From 02ca98dee8b7a2281b007718792f77deb7a0befd Mon Sep 17 00:00:00 2001 From: Jeanine Soterwood Date: Sun, 30 Jul 2023 08:24:36 -0700 Subject: [PATCH] Fix system volunteers/edit flaky spec (#5064) * spec refactor * Remove system spec that is already in view spec * Try scrolling to the element so that it is in view --- spec/system/volunteers/edit_spec.rb | 17 +---- spec/views/volunteers/edit.html.erb_spec.rb | 71 +++++++++++++-------- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/spec/system/volunteers/edit_spec.rb b/spec/system/volunteers/edit_spec.rb index 0e30f8b99f..1b5588857c 100644 --- a/spec/system/volunteers/edit_spec.rb +++ b/spec/system/volunteers/edit_spec.rb @@ -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 @@ -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") diff --git a/spec/views/volunteers/edit.html.erb_spec.rb b/spec/views/volunteers/edit.html.erb_spec.rb index b7a4c0a664..dc75043205 100644 --- a/spec/views/volunteers/edit.html.erb_spec.rb +++ b/spec/views/volunteers/edit.html.erb_spec.rb @@ -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, [] @@ -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, [] @@ -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, [] @@ -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, [] @@ -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, [] @@ -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, [] @@ -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