Skip to content

Commit

Permalink
Fix system volunteers/edit flaky spec (#5064)
Browse files Browse the repository at this point in the history
* spec refactor

* Remove system spec that is already in view spec

* Try scrolling to the element so that it is in view
  • Loading branch information
littleforest committed Jul 30, 2023
1 parent 55578b4 commit 02ca98d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 41 deletions.
17 changes: 1 addition & 16 deletions spec/system/volunteers/edit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
require "rails_helper"

RSpec.describe "volunteers/edit", type: :system do
it "shows invite and login info" do
organization = create(:casa_org)
admin = create(:casa_admin, casa_org_id: organization.id)
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org_id: organization.id)

sign_in admin
visit edit_volunteer_path(volunteer)

expect(page).to have_text "Added to system "
expect(page).to have_text "Invitation email sent never"
expect(page).to have_text "Last logged in"
expect(page).to have_text "Invitation accepted never"
expect(page).to have_text "Password reset last sent never"
expect(page).to have_text "Learning Hours This Year 0h 0min"
end

describe "updating volunteer personal data" do
context "with valid data" do
it "updates successfully" do
Expand Down Expand Up @@ -184,6 +168,7 @@
visit edit_volunteer_path(volunteer)

dismiss_confirm do
scroll_to(".actions")
click_on "Deactivate volunteer"
end
expect(page).not_to have_text("Volunteer was deactivated on")
Expand Down
71 changes: 46 additions & 25 deletions spec/views/volunteers/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require "rails_helper"

RSpec.describe "volunteers/edit", type: :view do
let(:org) { create :casa_org }
let(:volunteer) { create :volunteer, casa_org: org }

it "allows an administrator to edit a volunteers email address" do
administrator = build_stubbed :casa_admin
enable_pundit(view, administrator)
org = create :casa_org
volunteer = create :volunteer, casa_org: org
allow(view).to receive(:current_user).and_return(administrator)
allow(view).to receive(:current_organization).and_return(administrator.casa_org)

assign :volunteer, volunteer
assign :supervisors, []

Expand All @@ -20,8 +20,11 @@
it "allows an administrator to edit a volunteers phone number" do
administrator = build_stubbed :casa_admin
enable_pundit(view, administrator)
org = create :casa_org
volunteer = create :volunteer, casa_org: org
allow(view).to receive(:current_user).and_return(administrator)
allow(view).to receive(:current_organization).and_return(administrator.casa_org)

assign :volunteer, volunteer
assign :supervisors, []

Expand All @@ -33,8 +36,11 @@
it "allows a supervisor to edit a volunteers email address" do
supervisor = build_stubbed :supervisor
enable_pundit(view, supervisor)
org = create :casa_org
volunteer = create :volunteer, casa_org: org
allow(view).to receive(:current_user).and_return(supervisor)
allow(view).to receive(:current_organization).and_return(supervisor.casa_org)

assign :volunteer, volunteer
assign :supervisors, []

Expand All @@ -44,10 +50,13 @@
end

it "allows a supervisor in the same org to edit a volunteers phone number" do
org = create :casa_org
supervisor = build_stubbed :supervisor, casa_org: org
enable_pundit(view, supervisor)
volunteer = create :volunteer, casa_org: org
allow(view).to receive(:current_user).and_return(supervisor)
allow(view).to receive(:current_organization).and_return(supervisor.casa_org)

assign :volunteer, volunteer
assign :supervisors, []

Expand All @@ -59,8 +68,11 @@
it "does not allow a supervisor from a different org to edit a volunteers phone number" do
different_supervisor = build_stubbed :supervisor
enable_pundit(view, different_supervisor)
org = create :casa_org
volunteer = create :volunteer, casa_org: org
allow(view).to receive(:current_user).and_return(different_supervisor)
allow(view).to receive(:current_organization).and_return(different_supervisor.casa_org)

assign :volunteer, volunteer
assign :supervisors, []

Expand All @@ -72,8 +84,11 @@
it "shows invite and login info" do
supervisor = build_stubbed :supervisor
enable_pundit(view, supervisor)
org = create :casa_org
volunteer = create :volunteer, casa_org: org
allow(view).to receive(:current_user).and_return(supervisor)
allow(view).to receive(:current_organization).and_return(supervisor.casa_org)

assign :volunteer, volunteer
assign :supervisors, []

Expand All @@ -87,34 +102,40 @@
expect(rendered).to have_text("Learning Hours This Year\n 0h 0min")
end

context " the user has requested to reset their password" do
describe "shows resend invitation "
let(:volunteer) { create :volunteer }
let(:supervisor) { build_stubbed :supervisor }
let(:admin) { build_stubbed :casa_admin }
context "the user has requested to reset their password" do
describe "shows resend invitation" do
it "allows an administrator resend invitation to a volunteer" do
volunteer = create :volunteer
supervisor = build_stubbed :supervisor
admin = build_stubbed :casa_admin

it "allows an administrator resend invitation to a volunteer" do
enable_pundit(view, supervisor)
allow(view).to receive(:current_user).and_return(admin)
allow(view).to receive(:current_organization).and_return(admin.casa_org)
assign :volunteer, volunteer
assign :supervisors, []
enable_pundit(view, supervisor)
allow(view).to receive(:current_user).and_return(admin)
allow(view).to receive(:current_organization).and_return(admin.casa_org)

render template: "volunteers/edit"
assign :volunteer, volunteer
assign :supervisors, []

expect(rendered).to have_content("Resend Invitation")
end
render template: "volunteers/edit"

expect(rendered).to have_content("Resend Invitation")
end

it "allows a supervisor to resend invitation to a volunteer" do
volunteer = create :volunteer
supervisor = build_stubbed :supervisor

enable_pundit(view, supervisor)
allow(view).to receive(:current_user).and_return(supervisor)
allow(view).to receive(:current_organization).and_return(supervisor.casa_org)

it "allows a supervisor to resend invitation to a volunteer" do
enable_pundit(view, supervisor)
allow(view).to receive(:current_user).and_return(supervisor)
allow(view).to receive(:current_organization).and_return(supervisor.casa_org)
assign :volunteer, volunteer
assign :supervisors, []
assign :volunteer, volunteer
assign :supervisors, []

render template: "volunteers/edit"
render template: "volunteers/edit"

expect(rendered).to have_content("Resend Invitation")
expect(rendered).to have_content("Resend Invitation")
end
end
end
end

0 comments on commit 02ca98d

Please sign in to comment.