From 2e9c4de061e42d001233557c1653c8b3cdc07fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 3 Feb 2023 16:59:43 +0100 Subject: [PATCH] Unify specs testing access to admin menu items In most sections, we had two specs testing what happens after accessing one of the privileged areas. We're grouping the expectations and so we've only got one test per area, making these tests faster. --- spec/system/admin_spec.rb | 14 ++++---------- spec/system/moderation_spec.rb | 26 +++++--------------------- spec/system/officing_spec.rb | 24 ++++++------------------ spec/system/sdg_management_spec.rb | 19 ++++--------------- spec/system/valuation_spec.rb | 19 +++---------------- 5 files changed, 22 insertions(+), 80 deletions(-) diff --git a/spec/system/admin_spec.rb b/spec/system/admin_spec.rb index 1be11bb6e..a0f31c04d 100644 --- a/spec/system/admin_spec.rb +++ b/spec/system/admin_spec.rb @@ -62,22 +62,16 @@ describe "Admin" do end scenario "Access as administrator is authorized", :admin do - visit admin_root_path - - expect(page).to have_current_path(admin_root_path) - expect(page).not_to have_content "You do not have permission to access this page" - end - - scenario "Admin dashboard", :admin do visit root_path click_link "Menu" click_link "Administration" expect(page).to have_current_path(admin_root_path) - expect(page).to have_css("#admin_menu") - expect(page).not_to have_css("#moderation_menu") - expect(page).not_to have_css("#valuation_menu") + expect(page).to have_css "#admin_menu" + expect(page).not_to have_css "#moderation_menu" + expect(page).not_to have_css "#valuation_menu" + expect(page).not_to have_content "You do not have permission to access this page" end scenario "Admin menu does not hide active elements", :admin do diff --git a/spec/system/moderation_spec.rb b/spec/system/moderation_spec.rb index 2e4040cb6..99b4b0086 100644 --- a/spec/system/moderation_spec.rb +++ b/spec/system/moderation_spec.rb @@ -58,6 +58,7 @@ describe "Moderation" do end scenario "Access as a moderator is authorized" do + Setting["org_name"] = "OrgName" create(:moderator, user: user) login_as(user) @@ -66,6 +67,10 @@ describe "Moderation" do click_link "Moderation" expect(page).to have_current_path(moderation_root_path) + expect(page).to have_link "Go back to OrgName" + expect(page).to have_css "#moderation_menu" + expect(page).not_to have_css "#admin_menu" + expect(page).not_to have_css "#valuation_menu" expect(page).not_to have_content "You do not have permission to access this page" end @@ -80,25 +85,4 @@ describe "Moderation" do expect(page).to have_current_path(moderation_root_path) expect(page).not_to have_content "You do not have permission to access this page" end - - context "Moderation dashboard" do - before do - Setting["org_name"] = "OrgName" - end - - scenario "Contains correct elements" do - create(:moderator, user: user) - login_as(user) - - visit root_path - click_link "Menu" - click_link "Moderation" - - expect(page).to have_link("Go back to OrgName") - expect(page).to have_current_path(moderation_root_path) - expect(page).to have_css("#moderation_menu") - expect(page).not_to have_css("#admin_menu") - expect(page).not_to have_css("#valuation_menu") - end - end end diff --git a/spec/system/officing_spec.rb b/spec/system/officing_spec.rb index 3d92c2016..f3c791309 100644 --- a/spec/system/officing_spec.rb +++ b/spec/system/officing_spec.rb @@ -85,7 +85,7 @@ describe "Poll Officing" do expect(page).not_to have_content "You do not have permission to access this page" end - scenario "Access as an poll officer is authorized" do + scenario "Access as a poll officer is authorized" do create(:poll_officer, user: user) create(:poll) login_as(user) @@ -95,26 +95,14 @@ describe "Poll Officing" do click_link "Polling officers" expect(page).to have_current_path(officing_root_path) + expect(page).to have_css "#officing_menu" + expect(page).not_to have_link "Polling officers" + expect(page).not_to have_css "#valuation_menu" + expect(page).not_to have_css "#admin_menu" + expect(page).not_to have_css "#moderation_menu" expect(page).not_to have_content "You do not have permission to access this page" end - scenario "Officing dashboard" do - create(:poll_officer, user: user) - create(:poll) - login_as(user) - visit root_path - - click_link "Menu" - click_link "Polling officers" - - expect(page).to have_current_path(officing_root_path) - expect(page).to have_css("#officing_menu") - expect(page).not_to have_link("Polling officers") - expect(page).not_to have_css("#valuation_menu") - expect(page).not_to have_css("#admin_menu") - expect(page).not_to have_css("#moderation_menu") - end - scenario "Officing dashboard available for multiple sessions", :with_frozen_time do poll = create(:poll) booth = create(:poll_booth) diff --git a/spec/system/sdg_management_spec.rb b/spec/system/sdg_management_spec.rb index 41be8606b..7b7e6bfef 100644 --- a/spec/system/sdg_management_spec.rb +++ b/spec/system/sdg_management_spec.rb @@ -36,22 +36,11 @@ describe "SDGManagement" do click_on "SDG content" expect(page).to have_current_path(sdg_management_root_path) + expect(page).to have_css ".sdg-content-menu" + expect(page).not_to have_css "#valuation_menu" + expect(page).not_to have_css "#admin_menu" + expect(page).not_to have_css "#moderation_menu" expect(page).not_to have_content "You do not have permission to access this page" end end - - scenario "Valuation dashboard" do - create(:sdg_manager, user: user) - - login_as(user) - visit root_path - click_on "Menu" - click_on "SDG content" - - expect(page).to have_current_path(sdg_management_root_path) - expect(page).to have_css(".sdg-content-menu") - expect(page).not_to have_css("#valuation_menu") - expect(page).not_to have_css("#admin_menu") - expect(page).not_to have_css("#moderation_menu") - end end diff --git a/spec/system/valuation_spec.rb b/spec/system/valuation_spec.rb index 8fc6c7b29..53bf6c2bc 100644 --- a/spec/system/valuation_spec.rb +++ b/spec/system/valuation_spec.rb @@ -68,6 +68,9 @@ describe "Valuation" do click_link "Valuation" expect(page).to have_current_path(valuation_root_path) + expect(page).to have_css "#valuation_menu" + expect(page).not_to have_css "#admin_menu" + expect(page).not_to have_css "#moderation_menu" expect(page).not_to have_content "You do not have permission to access this page" end @@ -84,20 +87,4 @@ describe "Valuation" do expect(page).not_to have_content "You do not have permission to access this page" end end - - scenario "Valuation dashboard" do - create(:valuator, user: user) - create(:budget) - - login_as(user) - visit root_path - - click_link "Menu" - click_link "Valuation" - - expect(page).to have_current_path(valuation_root_path) - expect(page).to have_css("#valuation_menu") - expect(page).not_to have_css("#admin_menu") - expect(page).not_to have_css("#moderation_menu") - end end