Files
grecia/spec/components/layout/admin_login_items_component_spec.rb
taitus a5911f5c6a Modify admin layout to only manage tenants and admins
We only want to render the account link and login items in the header.
And we want only render the Multitenancy and Administrators sections in
the admin sidebar.

We include the administrators management so it's possible to give
permissions to other users to manage tenants.

In order to restrict access to other sections by typing the URL or
following a link, we're only enabling the rest of the routes when we
aren't in the multitenancy management mode.
2024-11-06 11:17:53 +01:00

142 lines
3.7 KiB
Ruby

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 "is not rendered when multitenancy_management_mode is enabled" do
allow(Rails.application.config).to receive(:multitenancy_management_mode).and_return(true)
user = create(:administrator).user
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).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