Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions spec/support/case_court_report_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,4 @@ def open_case_select2_dropdown
# Wait for the dropdown to appear
expect(page).to have_css(".select2-dropdown", visible: :visible)
end

# Polls the database until the casa_case has an ActiveStorage court_report attached.
# This is used after clicking 'Generate Report' to wait for the background job to complete.
def wait_for_report_attachment(casa_case, timeout: 5)
casa_case.reload # Ensure we have the latest record

Timeout.timeout(timeout) do
until casa_case.court_reports.attached?
sleep 0.2
casa_case.reload
end
end
end
end
18 changes: 7 additions & 11 deletions spec/system/case_court_reports/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,10 @@
end

# NOTE: select by option VALUE (stable), stub `window.open` to capture the download URL,
# wait for the ActiveStorage attachment, and assert button state + opened URL.
it "generates and attaches a report on success", :aggregate_failures, :js do # rubocop:disable RSpec/ExampleLength
# wait for the button to re-enable (page-level signal), and assert UI state + opened URL.
it "generates a report and opens the download link on success", :aggregate_failures, :js do # rubocop:disable RSpec/ExampleLength
transition_case = casa_cases.detect(&:in_transition_age?)

# Precondition: no report attached
expect(transition_case.court_reports.attached?).to be false

# Stub window.open so we can capture the download URL in the browser
page.execute_script(<<~JS)
window.__last_opened_url = null;
Expand All @@ -171,13 +168,12 @@
# Button should be disabled while processing
expect(page).to have_selector("#btnGenerateReport[disabled]")

# Wait for the controller to attach the file (allow longer timeout on CI)
wait_for_report_attachment(transition_case, timeout: 10)
transition_case.reload
# Wait for the button to re-enable (report generated successfully)
expect(page).not_to have_selector("#btnGenerateReport[disabled]", wait: 10)

# Postcondition: report attached and button re-enabled
expect(transition_case.court_reports.attached?).to be true
expect(page).not_to have_selector("#btnGenerateReport[disabled]", visible: :all)
# Verify the UI reflects a successful generation
expect(page).to have_selector("#btnGenerateReport .lni-download", visible: :visible)
expect(page).to have_selector("#spinner", visible: :hidden)

# Verify the browser attempted to open the generated .docx link
opened_url = page.evaluate_script("window.__last_opened_url")
Expand Down
Loading