diff options
Diffstat (limited to 'spec/features/help_dropdown_spec.rb')
-rw-r--r-- | spec/features/help_dropdown_spec.rb | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/spec/features/help_dropdown_spec.rb b/spec/features/help_dropdown_spec.rb index 08d7dba4d79..3e4c0bc55fe 100644 --- a/spec/features/help_dropdown_spec.rb +++ b/spec/features/help_dropdown_spec.rb @@ -3,24 +3,19 @@ require 'spec_helper' RSpec.describe "Help Dropdown", :js, feature_category: :shared do - let_it_be(:user) { create(:user, :no_super_sidebar) } - let_it_be(:admin) { create(:admin, :no_super_sidebar) } + let_it_be(:user) { create(:user) } + let_it_be(:admin) { create(:admin) } before do stub_application_setting(version_check_enabled: true) end - context 'when logged in as non-admin' do - before do - sign_in(user) - visit root_path - end - - it 'does not render version data' do - page.within '.header-help' do - find('.header-help-dropdown-toggle').click + shared_examples 'no version check badge' do + it 'does not render version check badge' do + within_testid('super-sidebar') do + click_on 'Help' - expect(page).not_to have_text('Your GitLab Version') + expect(page).not_to have_text('Your GitLab version') expect(page).not_to have_text("#{Gitlab.version_info.major}.#{Gitlab.version_info.minor}") expect(page).not_to have_selector('.version-check-badge') expect(page).not_to have_text('Up to date') @@ -28,45 +23,53 @@ RSpec.describe "Help Dropdown", :js, feature_category: :shared do end end - context 'when logged in as admin' do - before do - sign_in(admin) - gitlab_enable_admin_mode_sign_in(admin) - end + shared_examples 'correct version check badge' do |ui_text, severity| + context "when severity is #{severity}" do + before do + sign_in(admin) + gitlab_enable_admin_mode_sign_in(admin) - describe 'does render version data' do - where(:response, :ui_text) do - [ - [{ "severity" => "success" }, 'Up to date'], - [{ "severity" => "warning" }, 'Update available'], - [{ "severity" => "danger" }, 'Update ASAP'] - ] + allow_next_instance_of(VersionCheck) do |instance| + allow(instance).to receive(:response).and_return({ "severity" => severity }) + end + visit root_path end - with_them do - before do - allow_next_instance_of(VersionCheck) do |instance| - allow(instance).to receive(:response).and_return(response) - end - visit root_path - end + it 'renders correct version check badge variant' do + within_testid('super-sidebar') do + click_on 'Help' - it 'renders correct version badge variant', - quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/369850' do - page.within '.header-help' do - find('.header-help-dropdown-toggle').click + expect(page).to have_text('Your GitLab version') + expect(page).to have_text("#{Gitlab.version_info.major}.#{Gitlab.version_info.minor}") - expect(page).to have_text('Your GitLab Version') - expect(page).to have_text("#{Gitlab.version_info.major}.#{Gitlab.version_info.minor}") - expect(page).to have_selector('.version-check-badge') - expect(page).to have_selector( - 'a[data-testid="gitlab-version-container"][href="/help/update/index"]' - ) - expect(page).to have_selector('.version-check-badge[href="/help/update/index"]') - expect(page).to have_text(ui_text) + within page.find_link(href: help_page_path('update/index')) do + expect(page).to have_selector(".version-check-badge.badge-#{severity}", text: ui_text) end end end end end + + context 'when anonymous user' do + before do + visit user_path(user) + end + + include_examples 'no version check badge' + end + + context 'when logged in as non-admin' do + before do + sign_in(user) + visit root_path + end + + include_examples 'no version check badge' + end + + context 'when logged in as admin' do + include_examples 'correct version check badge', 'Up to date', 'success' + include_examples 'correct version check badge', 'Update available', 'warning' + include_examples 'correct version check badge', 'Update ASAP', 'danger' + end end |