Skip to content

Commit

Permalink
Grabbag of changes to mitigate possible flakiness
Browse files Browse the repository at this point in the history
Mostly converting find-then-check occurences to use capybara matchers
instead.
  • Loading branch information
solebared committed May 31, 2024
1 parent a2467d4 commit 3f993ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 43 deletions.
2 changes: 1 addition & 1 deletion app/views/volunteers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<thead>
<tr>
<th>
<input type="checkbox" class="form-check-input" data-select-all-target="checkboxAll" data-action="select-all#toggleAll">
<input id="checkbox-toggle-all" type="checkbox" class="form-check-input" data-select-all-target="checkboxAll" data-action="select-all#toggleAll">
</th>
<th>Name</th>
<th>Email</th>
Expand Down
70 changes: 28 additions & 42 deletions spec/system/volunteers/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

visit volunteers_path

expect(page.find("#casa-logo")["src"]).to match "default-logo"
expect(page.find("#casa-logo")["alt"]).to have_content "CASA Logo"
expect(page).to have_selector("#casa-logo[src*='default-logo']")
expect(page).to have_selector("#casa-logo[alt='CASA Logo']")
end
end

Expand Down Expand Up @@ -104,15 +104,15 @@
inactive_volunteers.each do |inactive_volunteer|
expect(page).to have_text inactive_volunteer.display_name
end
expect(page.all("table#volunteers tbody tr").count).to eq inactive_volunteers.count
expect(page).to have_selector("table#volunteers tbody tr", count: inactive_volunteers.count)

visit volunteers_path
click_on "Supervisor"
find(:css, "#unassigned-vol-filter").set(false)
assigned_volunteers.each do |assigned_volunteer|
expect(page).to have_text assigned_volunteer.display_name
end
expect(page.all("table#volunteers tbody tr").count).to eq assigned_volunteers.count
expect(page).to have_selector("table#volunteers tbody tr", count: assigned_volunteers.count)
end

it "can go to the volunteer edit page from the volunteer list", js: true do
Expand All @@ -136,7 +136,7 @@
click_on "New Volunteer"

expect(page).to have_text("New Volunteer")
expect(page).to have_css("form#new_volunteer")
expect(page).to have_selector("form#new_volunteer")
end

describe "supervisor column of volunteers table" do
Expand All @@ -147,9 +147,8 @@
visit volunteers_path
click_on "Supervisor"
find(:css, "#unassigned-vol-filter").set(true)
supervisor_cell = page.find("tbody .supervisor-column")

expect(supervisor_cell.text).to eq ""
expect(page).to have_selector("tbody .supervisor-column", text: "")
end

it "displays supervisor's name when volunteer has supervisor", js: true do
Expand All @@ -159,9 +158,7 @@
sign_in admin

visit volunteers_path
supervisor_cell = page.find("tbody .supervisor-column")

expect(supervisor_cell.text).to eq name
expect(page).to have_selector("tbody .supervisor-column", text: name)
end

it "is blank when volunteer's supervisor is inactive", js: true do
Expand All @@ -171,9 +168,8 @@
visit volunteers_path
click_on "Supervisor"
find(:css, "#unassigned-vol-filter").set(true)
supervisor_cell = page.find("tbody .supervisor-column")

expect(supervisor_cell.text).to eq ""
expect(page).to have_selector("tbody .supervisor-column", text: "")
end
end

Expand Down Expand Up @@ -209,8 +205,7 @@
visit volunteers_path
volunteers.each_with_index do |volunteer, index|
find("#supervisor_volunteer_volunteer_ids_#{volunteer.id}").click
button = find("[data-select-all-target='buttonLabel']")
expect(button).to have_text "(#{index + 1})"
expect(page).to have_selector("[data-select-all-target='buttonLabel']", text: "#{index + 1})")
end
end

Expand Down Expand Up @@ -250,10 +245,10 @@
it "selects all volunteers" do
visit volunteers_path
find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}") # Wait for data table to be loaded
find("[data-select-all-target='checkboxAll']").click
find("#checkbox-toggle-all").click

volunteers.each do |volunteer|
expect(find("#supervisor_volunteer_volunteer_ids_#{volunteer.id}").checked?).to be true
expect(page).to have_field("supervisor_volunteer_volunteer_ids_#{volunteer.id}", checked: true)
end
end

Expand All @@ -264,11 +259,11 @@
find("#supervisor_volunteer_volunteer_ids_#{volunteer.id}").click
end

find("[data-select-all-target='checkboxAll']").click
expect(find("[data-select-all-target='checkboxAll']").checked?).to be false
find("#checkbox-toggle-all").click
expect(page).to have_field("checkbox-toggle-all", checked: false)

volunteers.each do |volunteer|
expect(find("#supervisor_volunteer_volunteer_ids_#{volunteer.id}").checked?).to be false
expect(page).to have_field("supervisor_volunteer_volunteer_ids_#{volunteer.id}", checked: false)
end
end
end
Expand All @@ -278,17 +273,17 @@
visit volunteers_path
find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}").click

expect(find("[data-select-all-target='checkboxAll']").checked?).to be false
expect(find("[data-select-all-target='checkboxAll']")[:indeterminate]).to eq("true")
expect(page).to have_field("checkbox-toggle-all", checked: false)
expect(find("#checkbox-toggle-all")[:indeterminate]).to eq("true")
end

it "selects all volunteers" do
visit volunteers_path
find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}").click
find("[data-select-all-target='checkboxAll']").click
find("#checkbox-toggle-all").click

volunteers.each do |volunteer|
expect(find("#supervisor_volunteer_volunteer_ids_#{volunteer.id}").checked?).to be true
expect(page).to have_field("supervisor_volunteer_volunteer_ids_#{volunteer.id}", checked: true)
end
end
end
Expand All @@ -311,8 +306,7 @@
find("[data-select-all-target='button']").click
select "None", from: "supervisor_volunteer_supervisor_id"

expect(page).to have_button("Confirm", disabled: false)
expect(page).to have_button("Confirm", class: %w[!deactive-btn dark-btn btn-hover])
expect(page).to have_button("Confirm", disabled: false, class: %w[!deactive-btn dark-btn btn-hover])
end
end

Expand All @@ -323,11 +317,8 @@
find("[data-select-all-target='button']").click

select supervisor.display_name, from: "supervisor_volunteer_supervisor_id"
button = find("[data-disable-form-target='submitButton']")
expect(button.disabled?).to be false
expect(button[:class].include?("deactive-btn")).to be false
expect(button[:class].include?("dark-btn")).to be true
expect(button[:class].include?("btn-hover")).to be true

expect(page).to have_button("Confirm", disabled: false, class: %w[!deactive-btn dark-btn btn-hover])
end
end

Expand All @@ -339,19 +330,15 @@

select supervisor.display_name, from: "supervisor_volunteer_supervisor_id"
select "Choose a supervisor", from: "supervisor_volunteer_supervisor_id"
button = find("[data-disable-form-target='submitButton']")
expect(button.disabled?).to be true
expect(button[:class].include?("deactive-btn")).to be true
expect(button[:class].include?("dark-btn")).to be false
expect(button[:class].include?("btn-hover")).to be false

expect(page).to have_button("Confirm", disabled: true, class: %w[deactive-btn !dark-btn !btn-hover])
end
end
end
end

context "supervisor user" do
let(:supervisor) { create(:supervisor, casa_org: organization) }
let(:input_field) { "div#volunteers_filter input" }

it "can filter volunteers", js: true do
active_volunteers = create_list(:volunteer, 3, :with_assigned_supervisor, casa_org: organization)
Expand All @@ -365,8 +352,7 @@

visit volunteers_path
expect(page).to have_selector(".volunteer-filters")

expect(page.all("table#volunteers tbody tr").count).to eq 1
expect(page).to have_selector("table#volunteers tbody tr", count: 1)

click_on "Status"
find(:css, 'input[data-value="true"]').set(false)
Expand All @@ -376,7 +362,7 @@
inactive_volunteers.each do |inactive_volunteer|
expect(page).to have_text inactive_volunteer.display_name
end
expect(page.all("table#volunteers tbody tr").count).to eq inactive_volunteers.count
expect(page).to have_selector("table#volunteers tbody tr", count: inactive_volunteers.count)
end

it "can show/hide columns on volunteers table", js: true do
Expand Down Expand Up @@ -469,12 +455,12 @@
sign_in supervisor
visit volunteers_path

page.find(input_field).set("Test")
page.fill_in("Search:", with: "Test")

visit supervisors_path
visit volunteers_path
input_search = page.find(input_field)
expect(input_search.value).to eq("")

expect(page).to have_selector("#volunteers_filter input", text: "")
end
end
end
Expand Down

0 comments on commit 3f993ee

Please sign in to comment.