Commit 9c6a6e1c authored by Paul Slaughter's avatar Paul Slaughter Committed by Mark Lapierre

Add feature specs for admin search settings

- Separates feature flag check from other
  shared examples so we can reduce
  redundant specs
parent 35a2f4c4
...@@ -2,6 +2,7 @@ import initSettingsPanels from '~/settings_panels'; ...@@ -2,6 +2,7 @@ import initSettingsPanels from '~/settings_panels';
import projectSelect from '~/project_select'; import projectSelect from '~/project_select';
import selfMonitor from '~/self_monitor'; import selfMonitor from '~/self_monitor';
import initVariableList from '~/ci_variable_list'; import initVariableList from '~/ci_variable_list';
import initSearchSettings from '~/search_settings';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
if (gon.features?.ciInstanceVariablesUi) { if (gon.features?.ciInstanceVariablesUi) {
...@@ -11,4 +12,5 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -11,4 +12,5 @@ document.addEventListener('DOMContentLoaded', () => {
// Initialize expandable settings panels // Initialize expandable settings panels
initSettingsPanels(); initSettingsPanels();
projectSelect(); projectSelect();
initSearchSettings();
}); });
...@@ -3,4 +3,9 @@ ...@@ -3,4 +3,9 @@
- nav "admin" - nav "admin"
- @left_sidebar = true - @left_sidebar = true
-# This active_nav_link check is also used in `app/views/layouts/nav/sidebar/_admin.html.haml`
- is_application_settings = active_nav_link?(controller: [:application_settings, :integrations])
- enable_search_settings if is_application_settings
= render template: "layouts/application" = render template: "layouts/application"
...@@ -247,6 +247,7 @@ ...@@ -247,6 +247,7 @@
= _('Settings') = _('Settings')
%ul.sidebar-sub-level-items{ data: { qa_selector: 'admin_sidebar_settings_submenu_content' } } %ul.sidebar-sub-level-items{ data: { qa_selector: 'admin_sidebar_settings_submenu_content' } }
-# This active_nav_link check is also used in `app/views/layouts/admin.html.haml`
= nav_link(controller: [:application_settings, :integrations], html_options: { class: "fly-out-top-item" } ) do = nav_link(controller: [:application_settings, :integrations], html_options: { class: "fly-out-top-item" } ) do
= link_to general_admin_application_settings_path do = link_to general_admin_application_settings_path do
%strong.fly-out-top-item-name %strong.fly-out-top-item-name
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Admin searches application settings', :js do
let_it_be(:admin) { create(:admin) }
let_it_be(:application_settings) { create(:application_setting) }
before do
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
end
context 'in appearances page' do
before do
visit(admin_appearances_path)
end
it_behaves_like 'cannot search settings'
end
context 'in ci/cd settings page' do
let(:visit_path) { ci_cd_admin_application_settings_path }
it_behaves_like 'can search settings with feature flag check', 'Variables', 'Package Registry'
end
end
...@@ -3,51 +3,23 @@ ...@@ -3,51 +3,23 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'User searches their settings', :js do RSpec.describe 'User searches their settings', :js do
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:search_input_placeholder) { 'Search settings' }
before do before do
sign_in(user) sign_in(user)
end end
context 'when search_settings_in_page feature flag is on' do context 'in profile page' do
it 'allows searching in the user profile page' do let(:visit_path) { profile_path }
search_term = 'Public Avatar'
hidden_section_name = 'Main settings'
visit profile_path it_behaves_like 'can search settings with feature flag check', 'Public Avatar', 'Main settings'
fill_in search_input_placeholder, with: search_term
expect(page).to have_content(search_term)
expect(page).not_to have_content(hidden_section_name)
end
it 'allows searching in the user applications page' do
visit applications_profile_path
expect(page.find_field(placeholder: search_input_placeholder)).not_to be_disabled
end
it 'allows searching in the user preferences page' do
search_term = 'Syntax highlighting theme'
hidden_section_name = 'Behavior'
visit profile_preferences_path
fill_in search_input_placeholder, with: search_term
expect(page).to have_content(search_term)
expect(page).not_to have_content(hidden_section_name)
end
end end
context 'when search_settings_in_page feature flag is off' do context 'in preferences page' do
before do before do
stub_feature_flags(search_settings_in_page: false) visit profile_preferences_path
visit(profile_path)
end end
it 'does not allow searching in the user settings pages' do it_behaves_like 'can search settings', 'Syntax highlighting theme', 'Behavior'
expect(page).not_to have_content(search_input_placeholder)
end
end end
end end
# frozen_string_literal: true
module SearchHelpers
self::INPUT_PLACEHOLDER = 'Search settings'
end
# frozen_string_literal: true
RSpec.shared_examples 'cannot search settings' do
it 'does note have search settings field' do
expect(page).not_to have_field(placeholder: SearchHelpers::INPUT_PLACEHOLDER)
end
end
RSpec.shared_examples 'can search settings' do |search_term, non_match_section|
it 'has search settings field' do
expect(page).to have_field(placeholder: SearchHelpers::INPUT_PLACEHOLDER)
end
it 'hides unmatching sections on search' do
expect(page).to have_content(non_match_section)
fill_in SearchHelpers::INPUT_PLACEHOLDER, with: search_term
expect(page).to have_content(search_term)
expect(page).not_to have_content(non_match_section)
end
end
RSpec.shared_examples 'can search settings with feature flag check' do |search_term, non_match_section|
let(:flag) { true }
before do
stub_feature_flags(search_settings_in_page: flag)
visit(visit_path)
end
context 'with feature flag on' do
it_behaves_like 'can search settings', search_term, non_match_section
end
context 'with feature flag off' do
let(:flag) { false }
it_behaves_like 'cannot search settings'
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment