Move admin header partial to a component

This way it's easier to refactor it.

Note we're using `with_request_url` in the tests because the component
renders the locale switcher, which needs a URL in order to work. This
doesn't affect whether we're in the management section or not.
This commit is contained in:
Javi Martín
2023-01-05 14:12:19 +01:00
parent d27bfb2afd
commit 86fd14f8f0
9 changed files with 153 additions and 142 deletions

View File

@@ -0,0 +1,38 @@
require "rails_helper"
describe Layout::AdminHeaderComponent do
let(:user) { create(:user) }
before { Setting["org_name"] = "CONSUL" }
around do |example|
with_request_url("/") { example.run }
end
context "management section", controller: Management::BaseController do
it "shows the menu for administrators" do
create(:administrator, user: user)
sign_in(user)
render_inline Layout::AdminHeaderComponent.new(user)
expect(page).to have_link "Go back to CONSUL"
expect(page).to have_link "You don't have new notifications"
expect(page).to have_link "My content"
expect(page).to have_link "My account"
expect(page).to have_link "Sign out"
end
it "does not show the menu managers" do
create(:manager, user: user)
sign_in(user)
render_inline Layout::AdminHeaderComponent.new(user)
expect(page).to have_link "Go back to CONSUL"
expect(page).not_to have_content "You don't have new notifications"
expect(page).not_to have_content "My content"
expect(page).not_to have_content "My account"
expect(page).not_to have_content "Sign out"
end
end
end