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:
Javi Martín
2023-02-03 16:58:03 +01:00
parent 169b1b191a
commit 465d2d604d
8 changed files with 132 additions and 189 deletions

View 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