Skip to content

Commit

Permalink
Merge pull request #4897 from fchatterji/fix_flaky_court_dates_edit_test
Browse files Browse the repository at this point in the history
Fix flaky court dates edit test
  • Loading branch information
FireLemons authored Jun 24, 2023
2 parents f506dfd + 73564df commit 754791c
Showing 1 changed file with 71 additions and 65 deletions.
136 changes: 71 additions & 65 deletions spec/system/court_dates/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,87 +15,93 @@

before do
travel_to now
sign_in admin
visit casa_case_path(casa_case)
click_on court_date.date.strftime("%B %-d, %Y")
click_on "Edit"
end

it "shows court orders" do
court_order = court_date.case_court_orders.first
context "as an admin" do
before do
sign_in admin
visit casa_case_path(casa_case)
click_on court_date.date.strftime("%B %-d, %Y")
click_on "Edit"
end

expect(page).to have_text(court_order.text)
expect(page).to have_text(court_order.implementation_status.humanize)
end
it "shows court orders" do
court_order = court_date.case_court_orders.first

it "edits past court date", js: true do
expect(page).to have_text("Editing Court Date")
expect(page).to have_text("Case Number:")
expect(page).to have_text(casa_case.case_number)
expect(page).to have_text("Add Court Date")
expect(page).to have_field("court_date_date", with: "2020-12-25")
expect(page).to have_text("Add Court Report Due Date")
expect(page).to have_field("court_date_court_report_due_date")
expect(page).to have_select("Judge")
expect(page).to have_select("Hearing type")
expect(page).to have_text("Court Orders - Please check that you didn't enter any youth names")
expect(page).to have_text("Add a court order")

page.find("#add-court-order-button").click
find("#court-orders-list-container").first("textarea").send_keys("Court Order Text One")

within ".top-page-actions" do
click_on "Update"
expect(page).to have_text(court_order.text)
expect(page).to have_text(court_order.implementation_status.humanize)
end

it "edits past court date", js: true do
expect(page).to have_text("Editing Court Date")
expect(page).to have_text("Case Number:")
expect(page).to have_text(casa_case.case_number)
expect(page).to have_text("Add Court Date")
expect(page).to have_field("court_date_date", with: "2020-12-25")
expect(page).to have_text("Add Court Report Due Date")
expect(page).to have_field("court_date_court_report_due_date")
expect(page).to have_select("Judge")
expect(page).to have_select("Hearing type")
expect(page).to have_text("Court Orders - Please check that you didn't enter any youth names")
expect(page).to have_text("Add a court order")

page.find("#add-court-order-button").click
find("#court-orders-list-container").first("textarea").send_keys("Court Order Text One")

within ".top-page-actions" do
click_on "Update"
end
expect(page).to have_text("Court Order Text One")
end
expect(page).to have_text("Court Order Text One")
end

it "can delete a future court date as admin", js: true do
visit root_path
click_on "Cases"
click_on casa_case.case_number
it "can delete a future court date", js: true do
visit root_path
click_on "Cases"
click_on casa_case.case_number

expect(CourtDate.count).to eq 2
expect(page).to have_content future_court_date.date.strftime("%B %-d, %Y")
page.find("a", text: future_court_date.date.strftime("%B %-d, %Y")).click
page.find("a", text: "Delete Future Court Date").click
page.driver.browser.switch_to.alert.accept
expect(CourtDate.count).to eq 2
expect(page).to have_content future_court_date.date.strftime("%B %-d, %Y")
page.find("a", text: future_court_date.date.strftime("%B %-d, %Y")).click
page.find("a", text: "Delete Future Court Date").click
page.driver.browser.switch_to.alert.accept

expect(page).to have_content "Court date was successfully deleted."
expect(CourtDate.count).to eq 1
expect(page).to have_content "Court date was successfully deleted."
expect(CourtDate.count).to eq 1
end
end

it "can delete a future court date as supervisor", js: true do
sign_out admin
sign_in supervisor
context "as a supervisor" do
it "can delete a future court date", js: true do
sign_in supervisor

visit root_path
click_on "Cases"
click_on casa_case.case_number
visit root_path
click_on "Cases"
click_on casa_case.case_number

expect(CourtDate.count).to eq 2
expect(page).to have_content future_court_date.date.strftime("%B %-d, %Y")
page.find("a", text: future_court_date.date.strftime("%B %-d, %Y")).click
page.find("a", text: "Delete Future Court Date").click
page.driver.browser.switch_to.alert.accept
expect(CourtDate.count).to eq 2
expect(page).to have_content future_court_date.date.strftime("%B %-d, %Y")
page.find("a", text: future_court_date.date.strftime("%B %-d, %Y")).click
page.find("a", text: "Delete Future Court Date").click
page.driver.browser.switch_to.alert.accept

expect(page).to have_content "Court date was successfully deleted."
expect(CourtDate.count).to eq 1
expect(page).to have_content "Court date was successfully deleted."
expect(CourtDate.count).to eq 1
end
end

it "can't delete a future court date as volunteer", js: true do
sign_out admin
sleep(1) # flaky test??? sleep seems to be the only thing that makes this one pass :/
volunteer.casa_cases = [casa_case]
sign_in volunteer
context "as a volunteer" do
it "can't delete a future court date as volunteer", js: true do
volunteer.casa_cases = [casa_case]
sign_in volunteer

visit root_path
click_on "Cases"
click_on casa_case.case_number
visit root_path
click_on "Cases"
click_on casa_case.case_number

expect(CourtDate.count).to eq 2
expect(page).to have_content future_court_date.date.strftime("%B %-d, %Y")
page.find("a", text: future_court_date.date.strftime("%B %-d, %Y")).click
expect(page).not_to have_content "Delete Future Court Date"
expect(CourtDate.count).to eq 2
expect(page).to have_content future_court_date.date.strftime("%B %-d, %Y")
page.find("a", text: future_court_date.date.strftime("%B %-d, %Y")).click
expect(page).not_to have_content "Delete Future Court Date"
end
end
end

0 comments on commit 754791c

Please sign in to comment.