Move login items tests to the component
This way we reduce the number of system tests or, in some cases, requests during system tests, making the tests faster. We're still testing the interaction with the menu when users have the right permissions.
This commit is contained in:
132
spec/components/layout/admin_login_items_component_spec.rb
Normal file
132
spec/components/layout/admin_login_items_component_spec.rb
Normal file
@@ -0,0 +1,132 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Layout::AdminLoginItemsComponent do
|
||||
it "is not rendered for anonymous users" do
|
||||
render_inline Layout::AdminLoginItemsComponent.new(nil)
|
||||
|
||||
expect(page).not_to be_rendered
|
||||
end
|
||||
|
||||
it "is not rendered for regular users" do
|
||||
user = create(:user, :level_two)
|
||||
|
||||
render_inline Layout::AdminLoginItemsComponent.new(user)
|
||||
|
||||
expect(page).not_to be_rendered
|
||||
end
|
||||
|
||||
it "shows access to all places except officing to administrators" do
|
||||
user = create(:administrator).user
|
||||
|
||||
render_inline Layout::AdminLoginItemsComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Menu"
|
||||
|
||||
page.find("ul") do |menu|
|
||||
expect(menu).to have_link "Administration"
|
||||
expect(menu).to have_link "Moderation"
|
||||
expect(menu).to have_link "Valuation"
|
||||
expect(menu).to have_link "Management"
|
||||
expect(menu).to have_link "SDG content"
|
||||
expect(menu).to have_link count: 5
|
||||
end
|
||||
end
|
||||
|
||||
it "shows the moderation link to moderators" do
|
||||
user = create(:moderator).user
|
||||
|
||||
render_inline Layout::AdminLoginItemsComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Menu"
|
||||
|
||||
page.find("ul") do |menu|
|
||||
expect(menu).to have_link "Moderation"
|
||||
expect(menu).to have_link count: 1
|
||||
end
|
||||
end
|
||||
|
||||
it "shows the valuation link to valuators" do
|
||||
user = create(:valuator).user
|
||||
|
||||
render_inline Layout::AdminLoginItemsComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Menu"
|
||||
|
||||
page.find("ul") do |menu|
|
||||
expect(menu).to have_link "Valuation"
|
||||
expect(menu).to have_link count: 1
|
||||
end
|
||||
end
|
||||
|
||||
it "shows the management link to managers" do
|
||||
user = create(:manager).user
|
||||
|
||||
render_inline Layout::AdminLoginItemsComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Menu"
|
||||
|
||||
page.find("ul") do |menu|
|
||||
expect(menu).to have_link "Management"
|
||||
expect(menu).to have_link count: 1
|
||||
end
|
||||
end
|
||||
|
||||
it "shows the SDG content link to SDG managers" do
|
||||
user = create(:sdg_manager).user
|
||||
|
||||
render_inline Layout::AdminLoginItemsComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Menu"
|
||||
|
||||
page.find("ul") do |menu|
|
||||
expect(menu).to have_link "SDG content"
|
||||
expect(menu).to have_link count: 1
|
||||
end
|
||||
end
|
||||
|
||||
it "does not show the SDG content link when the SDG feature is disabled" do
|
||||
Setting["feature.sdg"] = false
|
||||
user = create(:administrator).user
|
||||
|
||||
render_inline Layout::AdminLoginItemsComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Menu"
|
||||
|
||||
page.find("ul") do |menu|
|
||||
expect(menu).to have_link "Administration"
|
||||
expect(menu).to have_link "Moderation"
|
||||
expect(menu).to have_link "Valuation"
|
||||
expect(menu).to have_link "Management"
|
||||
expect(menu).to have_link count: 4
|
||||
end
|
||||
end
|
||||
|
||||
it "shows the officing link to poll officers" do
|
||||
user = create(:poll_officer, polls: [create(:poll)]).user
|
||||
|
||||
render_inline Layout::AdminLoginItemsComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Menu"
|
||||
|
||||
page.find("ul") do |menu|
|
||||
expect(menu).to have_link "Polling officers"
|
||||
expect(menu).to have_link count: 1
|
||||
end
|
||||
end
|
||||
|
||||
it "shows several links to users with several roles" do
|
||||
user = create(:user)
|
||||
create(:moderator, user: user)
|
||||
create(:manager, user: user)
|
||||
|
||||
render_inline Layout::AdminLoginItemsComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Menu"
|
||||
|
||||
page.find("ul") do |menu|
|
||||
expect(menu).to have_link "Moderation"
|
||||
expect(menu).to have_link "Management"
|
||||
expect(menu).to have_link count: 2
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -68,19 +68,6 @@ describe "Admin" do
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Admin access links", :admin do
|
||||
Setting["feature.sdg"] = true
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link("Administration")
|
||||
expect(page).to have_link("Moderation")
|
||||
expect(page).to have_link("Valuation")
|
||||
expect(page).to have_link("Management")
|
||||
expect(page).to have_link("SDG content")
|
||||
end
|
||||
|
||||
scenario "Admin dashboard", :admin do
|
||||
visit root_path
|
||||
|
||||
|
||||
@@ -6,11 +6,6 @@ describe "Moderation" do
|
||||
scenario "Access as regular user is not authorized" do
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
|
||||
expect(page).not_to have_link("Menu")
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
@@ -22,11 +17,6 @@ describe "Moderation" do
|
||||
create(:valuator, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
@@ -38,11 +28,6 @@ describe "Moderation" do
|
||||
create(:manager, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
@@ -54,11 +39,6 @@ describe "Moderation" do
|
||||
create(:sdg_manager, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
@@ -70,11 +50,6 @@ describe "Moderation" do
|
||||
create(:poll_officer, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
@@ -106,18 +81,6 @@ describe "Moderation" do
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Moderation access links" do
|
||||
create(:moderator, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link("Moderation")
|
||||
expect(page).not_to have_link("Administration")
|
||||
expect(page).not_to have_link("Valuation")
|
||||
end
|
||||
|
||||
context "Moderation dashboard" do
|
||||
before do
|
||||
Setting["org_name"] = "OrgName"
|
||||
|
||||
@@ -6,10 +6,6 @@ describe "Poll Officing" do
|
||||
|
||||
scenario "Access as regular user is not authorized" do
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).not_to have_content "Menu"
|
||||
expect(page).not_to have_link "Polling officers"
|
||||
|
||||
visit officing_root_path
|
||||
|
||||
@@ -20,13 +16,7 @@ describe "Poll Officing" do
|
||||
|
||||
scenario "Access as moderator is not authorized" do
|
||||
create(:moderator, user: user)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link "Moderation"
|
||||
expect(page).not_to have_link "Polling officers"
|
||||
|
||||
visit officing_root_path
|
||||
|
||||
@@ -37,13 +27,7 @@ describe "Poll Officing" do
|
||||
|
||||
scenario "Access as manager is not authorized" do
|
||||
create(:manager, user: user)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link "Management"
|
||||
expect(page).not_to have_link "Polling officers"
|
||||
|
||||
visit officing_root_path
|
||||
|
||||
@@ -55,13 +39,7 @@ describe "Poll Officing" do
|
||||
scenario "Access as SDG manager is not authorized" do
|
||||
Setting["feature.sdg"] = true
|
||||
create(:sdg_manager, user: user)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link "SDG content"
|
||||
expect(page).not_to have_link "Polling officers"
|
||||
|
||||
visit officing_root_path
|
||||
|
||||
@@ -72,13 +50,7 @@ describe "Poll Officing" do
|
||||
|
||||
scenario "Access as a valuator is not authorized" do
|
||||
create(:valuator, user: user)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link "Valuation"
|
||||
expect(page).not_to have_link "Polling officers"
|
||||
|
||||
visit officing_root_path
|
||||
|
||||
@@ -90,14 +62,7 @@ describe "Poll Officing" do
|
||||
scenario "Access as an administrator is not authorized" do
|
||||
create(:administrator, user: user)
|
||||
create(:poll)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link "Administration"
|
||||
expect(page).not_to have_link "Polling officers"
|
||||
|
||||
visit officing_root_path
|
||||
|
||||
@@ -133,20 +98,6 @@ describe "Poll Officing" do
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Poll officer access links" do
|
||||
create(:poll)
|
||||
create(:poll_officer, user: user)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link("Polling officers")
|
||||
expect(page).not_to have_link("Valuation")
|
||||
expect(page).not_to have_link("Administration")
|
||||
expect(page).not_to have_link("Moderation")
|
||||
end
|
||||
|
||||
scenario "Officing dashboard" do
|
||||
create(:poll_officer, user: user)
|
||||
create(:poll)
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "SDG Management" do
|
||||
before { login_as(create(:administrator).user) }
|
||||
|
||||
context "SDG feature flag is enabled" do
|
||||
before { Setting["feature.sdg"] = true }
|
||||
|
||||
scenario "shows the SDG content link" do
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link "SDG content"
|
||||
end
|
||||
end
|
||||
|
||||
context "SDG feature is disabled" do
|
||||
before { Setting["feature.sdg"] = false }
|
||||
|
||||
scenario "does not show the SDG Content link" do
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link "SDG content"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,10 +8,7 @@ describe "SDGManagement" do
|
||||
context "Access" do
|
||||
scenario "Access as regular user is not authorized" do
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).not_to have_link("Menu")
|
||||
expect(page).not_to have_link("SDG content")
|
||||
visit sdg_management_root_path
|
||||
|
||||
expect(page).not_to have_current_path(sdg_management_root_path)
|
||||
@@ -22,10 +19,7 @@ describe "SDGManagement" do
|
||||
scenario "Access as manager is not authorized" do
|
||||
create(:manager, user: user)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
click_on "Menu"
|
||||
|
||||
expect(page).not_to have_link("SDG content")
|
||||
visit sdg_management_root_path
|
||||
|
||||
expect(page).not_to have_current_path(sdg_management_root_path)
|
||||
@@ -46,19 +40,6 @@ describe "SDGManagement" do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Valuation access links" do
|
||||
create(:sdg_manager, user: user)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
click_on "Menu"
|
||||
|
||||
expect(page).to have_link("SDG content")
|
||||
expect(page).not_to have_link("Administration")
|
||||
expect(page).not_to have_link("Moderation")
|
||||
expect(page).not_to have_link("Valuation")
|
||||
end
|
||||
|
||||
scenario "Valuation dashboard" do
|
||||
create(:sdg_manager, user: user)
|
||||
|
||||
|
||||
@@ -20,13 +20,6 @@ describe "Valuation budget investments" do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Display link to valuation section" do
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link "Valuation", href: valuation_root_path
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
scenario "Index shows budget investments assigned to current valuator" do
|
||||
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget, valuators: [valuator])
|
||||
|
||||
@@ -6,10 +6,6 @@ describe "Valuation" do
|
||||
context "Access" do
|
||||
scenario "Access as regular user is not authorized" do
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).not_to have_link("Menu")
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
@@ -22,11 +18,6 @@ describe "Valuation" do
|
||||
create(:moderator, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
@@ -38,11 +29,6 @@ describe "Valuation" do
|
||||
create(:manager, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
@@ -54,11 +40,6 @@ describe "Valuation" do
|
||||
create(:sdg_manager, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
@@ -70,11 +51,6 @@ describe "Valuation" do
|
||||
create(:poll_officer, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
@@ -109,19 +85,6 @@ describe "Valuation" do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Valuation access links" do
|
||||
create(:valuator, user: user)
|
||||
create(:budget)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link("Valuation")
|
||||
expect(page).not_to have_link("Administration")
|
||||
expect(page).not_to have_link("Moderation")
|
||||
end
|
||||
|
||||
scenario "Valuation dashboard" do
|
||||
create(:valuator, user: user)
|
||||
create(:budget)
|
||||
|
||||
Reference in New Issue
Block a user