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.
This commit is contained in:
Javi Martín
2023-02-03 16:59:43 +01:00
parent 465d2d604d
commit 2e9c4de061
5 changed files with 22 additions and 80 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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