Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contribute back theme spec files #2217

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# frozen_string_literal: true

RSpec.describe 'themes/cultural_repository/_user_util_links.html.erb', type: :view do
let(:user) { create(:user) }
let!(:test_strategy) { Flipflop::FeatureSet.current.test! }
let(:admin_ability) { double(user_groups: ['admin']) }
let(:user_ability) { double(user_groups: []) }

context 'when feature flipper is on' do
before do
test_strategy.switch!(:show_login_link, true)
allow(view).to receive(:current_page?).and_return(false)
end

describe 'logged in user' do
before do
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_ability).and_return(user_ability)
render
end

it 'shows the links' do
expect(rendered).to have_link 'Change password', href: edit_user_registration_path
expect(rendered).to have_link 'Logout', href: destroy_user_session_path
expect(rendered).to have_link 'Dashboard', href: hyrax.dashboard_path
end
end

describe 'logged in admin user' do
before do
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_ability).and_return(admin_ability)
render
end

it 'shows the links' do
expect(rendered).to have_link 'Change password', href: edit_user_registration_path
expect(rendered).to have_link 'Logout', href: destroy_user_session_path
expect(rendered).to have_link 'Dashboard', href: hyrax.dashboard_path
end
end

describe 'logged out user' do
before do
allow(view).to receive(:user_signed_in?).and_return(false)
allow(view).to receive(:current_user).and_return(nil)
allow(view).to receive(:current_ability).and_return(nil)
render
end

it 'links to login path' do
expect(rendered).to have_link 'Login', href: single_signon_index_path
end
end
end

context 'When feature flipper is off' do
before do
test_strategy.switch!(:show_login_link, false)
allow(view).to receive(:current_page?).and_return(false)
end

describe 'logged in user' do
before do
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_ability).and_return(user_ability)
render
end

it 'hides the links' do
expect(rendered).not_to have_link 'Change password', href: edit_user_registration_path
expect(rendered).not_to have_link 'Logout', href: destroy_user_session_path
expect(rendered).to have_link 'Dashboard', href: hyrax.dashboard_path
end
end

describe 'logged in admin user' do
before do
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_ability).and_return(admin_ability)
render
end

it 'shows the links' do
expect(rendered).to have_link 'Change password', href: edit_user_registration_path
expect(rendered).to have_link 'Logout', href: destroy_user_session_path
expect(rendered).to have_link 'Dashboard', href: hyrax.dashboard_path
end
end

describe 'logged out user' do
before do
allow(view).to receive(:user_signed_in?).and_return(false)
allow(view).to receive(:current_user).and_return(nil)
allow(view).to receive(:current_ability).and_return(nil)
render
end

it 'hides the login path' do
expect(rendered).not_to have_link 'Login', href: single_signon_index_path
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# frozen_string_literal: true

RSpec.describe 'themes/institutional_repository/_user_util_links.html.erb', type: :view do
let(:user) { create(:user) }
let!(:test_strategy) { Flipflop::FeatureSet.current.test! }
let(:admin_ability) { double(user_groups: ['admin']) }
let(:user_ability) { double(user_groups: []) }

context 'when feature flipper is on' do
before { test_strategy.switch!(:show_login_link, true) }

describe 'logged in user' do
before do
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_ability).and_return(user_ability)
render
end

it 'shows the links' do
expect(rendered).to have_link 'Change password', href: edit_user_registration_path
expect(rendered).to have_link 'Logout', href: destroy_user_session_path
expect(rendered).to have_link 'Dashboard', href: hyrax.dashboard_path
end
end

describe 'logged in admin user' do
before do
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_ability).and_return(admin_ability)
render
end

it 'shows the links' do
expect(rendered).to have_link 'Change password', href: edit_user_registration_path
expect(rendered).to have_link 'Logout', href: destroy_user_session_path
expect(rendered).to have_link 'Dashboard', href: hyrax.dashboard_path
end
end

describe 'logged out user' do
before do
allow(view).to receive(:user_signed_in?).and_return(false)
allow(view).to receive(:current_user).and_return(nil)
allow(view).to receive(:current_ability).and_return(nil)
render
end

it 'links to login path' do
expect(rendered).to have_link 'Login', href: single_signon_index_path
end
end
end

context 'When feature flipper is off' do
before { test_strategy.switch!(:show_login_link, false) }

describe 'logged in user' do
before do
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_ability).and_return(user_ability)
render
end

it 'hides the links' do
expect(rendered).not_to have_link 'Change password', href: edit_user_registration_path
expect(rendered).not_to have_link 'Logout', href: destroy_user_session_path
expect(rendered).to have_link 'Dashboard', href: hyrax.dashboard_path
end
end

describe 'logged in admin user' do
before do
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_ability).and_return(admin_ability)
render
end

it 'shows the links' do
expect(rendered).to have_link 'Change password', href: edit_user_registration_path
expect(rendered).to have_link 'Logout', href: destroy_user_session_path
expect(rendered).to have_link 'Dashboard', href: hyrax.dashboard_path
end
end

describe 'logged out user' do
before do
allow(view).to receive(:user_signed_in?).and_return(false)
allow(view).to receive(:current_user).and_return(nil)
allow(view).to receive(:current_ability).and_return(nil)
render
end

it 'hides the login path' do
expect(rendered).not_to have_link 'Login', href: single_signon_index_path
end
end
end
end
Loading