Skip to content

Commit c0a08d1

Browse files
committed
Replace database assertions with page-based checks in court report spec
Remove ActiveRecord precondition/postcondition checks and the wait_for_report_attachment polling helper from the court report generation test. Use Capybara's built-in wait/retry to assert button state, download icon, and spinner visibility instead. This eliminates race conditions on CI where the DB check could execute before the browser action completed.
1 parent 2645f39 commit c0a08d1

2 files changed

Lines changed: 6 additions & 23 deletions

File tree

spec/support/case_court_report_helpers.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,4 @@ def open_case_select2_dropdown
2121
# Wait for the dropdown to appear
2222
expect(page).to have_css(".select2-dropdown", visible: :visible)
2323
end
24-
25-
# Polls the database until the casa_case has an ActiveStorage court_report attached.
26-
# This is used after clicking 'Generate Report' to wait for the background job to complete.
27-
def wait_for_report_attachment(casa_case, timeout: 5)
28-
casa_case.reload # Ensure we have the latest record
29-
30-
Timeout.timeout(timeout) do
31-
until casa_case.court_reports.attached?
32-
sleep 0.2
33-
casa_case.reload
34-
end
35-
end
36-
end
3724
end

spec/system/case_court_reports/index_spec.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,10 @@
148148
end
149149

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

155-
# Precondition: no report attached
156-
expect(transition_case.court_reports.attached?).to be false
157-
158155
# Stub window.open so we can capture the download URL in the browser
159156
page.execute_script(<<~JS)
160157
window.__last_opened_url = null;
@@ -171,13 +168,12 @@
171168
# Button should be disabled while processing
172169
expect(page).to have_selector("#btnGenerateReport[disabled]")
173170

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

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

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

0 commit comments

Comments
 (0)