Commit fbecfe82 authored by Paul Slaughter's avatar Paul Slaughter Committed by Chad Woolley

Combined menu flag feature specs

- Wrapped existing specs which fail with flag on
  in a shared example.
- Introduced two contexts for flag on and
  flag off which use these examples.
parent 8dbe191b
...@@ -6,22 +6,50 @@ RSpec.describe 'Operations dropdown navbar EE' do ...@@ -6,22 +6,50 @@ RSpec.describe 'Operations dropdown navbar EE' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
before do shared_examples 'combined_menu: feature flag examples' do
stub_feature_flags(combined_menu: false) before do
project.add_maintainer(user)
sign_in(user)
project.add_maintainer(user) stub_licensed_features(operations_dashboard: true)
sign_in(user)
stub_licensed_features(operations_dashboard: true) visit project_issues_path(project)
end
visit project_issues_path(project) it 'has an `Operations` link' do
pending_on_combined_menu_flag
expect(page).to have_link('Operations', href: operations_path)
end
it 'has an `Environments` link' do
pending_on_combined_menu_flag
expect(page).to have_link('Environments', href: operations_environments_path)
end
end end
it 'has an `Operations` link' do context 'with combined_menu: feature flag on' do
expect(page).to have_link('Operations', href: operations_path) let(:needs_rewrite_for_combined_menu_flag_on) { true }
before do
stub_feature_flags(combined_menu: true)
end
it_behaves_like 'combined_menu: feature flag examples'
end
context 'with combined_menu feature flag off' do
let(:needs_rewrite_for_combined_menu_flag_on) { false }
before do
stub_feature_flags(combined_menu: false)
end
it_behaves_like 'combined_menu: feature flag examples'
end end
it 'has an `Environments` link' do def pending_on_combined_menu_flag
expect(page).to have_link('Environments', href: operations_environments_path) pending 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56587' if needs_rewrite_for_combined_menu_flag_on
end end
end end
...@@ -8,37 +8,67 @@ RSpec.describe 'Admin Mode Logout', :js do ...@@ -8,37 +8,67 @@ RSpec.describe 'Admin Mode Logout', :js do
let(:user) { create(:admin) } let(:user) { create(:admin) }
before do shared_examples 'combined_menu: feature flag examples' do
stub_feature_flags(combined_menu: false) before do
gitlab_sign_in(user)
gitlab_enable_admin_mode_sign_in(user)
visit admin_root_path
end
gitlab_sign_in(user) it 'disable removes admin mode and redirects to root page' do
gitlab_enable_admin_mode_sign_in(user) pending_on_combined_menu_flag
visit admin_root_path
end
it 'disable removes admin mode and redirects to root page' do gitlab_disable_admin_mode
gitlab_disable_admin_mode
expect(current_path).to eq root_path expect(current_path).to eq root_path
expect(page).to have_link(href: new_admin_session_path) expect(page).to have_link(href: new_admin_session_path)
end end
it 'disable shows flash notice' do
pending_on_combined_menu_flag
gitlab_disable_admin_mode
expect(page).to have_selector('.flash-notice')
end
it 'disable shows flash notice' do context 'on a read-only instance' do
gitlab_disable_admin_mode before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
expect(page).to have_selector('.flash-notice') it 'disable removes admin mode and redirects to root page' do
pending_on_combined_menu_flag
gitlab_disable_admin_mode
expect(current_path).to eq root_path
expect(page).to have_link(href: new_admin_session_path)
end
end
end end
context 'on a read-only instance' do context 'with combined_menu: feature flag on' do
let(:needs_rewrite_for_combined_menu_flag_on) { true }
before do before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) stub_feature_flags(combined_menu: true)
end end
it 'disable removes admin mode and redirects to root page' do it_behaves_like 'combined_menu: feature flag examples'
gitlab_disable_admin_mode end
expect(current_path).to eq root_path context 'with combined_menu feature flag off' do
expect(page).to have_link(href: new_admin_session_path) let(:needs_rewrite_for_combined_menu_flag_on) { false }
before do
stub_feature_flags(combined_menu: false)
end end
it_behaves_like 'combined_menu: feature flag examples'
end
def pending_on_combined_menu_flag
pending 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56587' if needs_rewrite_for_combined_menu_flag_on
end end
end end
...@@ -8,55 +8,43 @@ RSpec.describe 'Admin mode' do ...@@ -8,55 +8,43 @@ RSpec.describe 'Admin mode' do
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
before do shared_examples 'combined_menu: feature flag examples' do
stub_feature_flags(combined_menu: false)
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
end
context 'application setting :admin_mode is enabled', :request_store do
before do before do
sign_in(admin) stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
end end
context 'when not in admin mode' do context 'application setting :admin_mode is enabled', :request_store do
it 'has no leave admin mode button' do before do
visit new_admin_session_path sign_in(admin)
page.within('.navbar-sub-nav') do
expect(page).not_to have_link(href: destroy_admin_session_path)
end
end end
it 'can open pages not in admin scope' do context 'when not in admin mode' do
visit new_admin_session_path it 'has no leave admin mode button' do
pending_on_combined_menu_flag
page.within('.navbar-sub-nav') do
find_all('a', text: 'Projects').first.click
end
expect(page).to have_current_path(dashboard_projects_path) visit new_admin_session_path
end
it 'is necessary to provide credentials again before opening pages in admin scope' do page.within('.navbar-sub-nav') do
visit general_admin_application_settings_path # admin logged out because not in admin_mode expect(page).not_to have_link(href: destroy_admin_session_path)
end
end
expect(page).to have_current_path(new_admin_session_path) it 'can open pages not in admin scope' do
end pending_on_combined_menu_flag
it 'can enter admin mode' do visit new_admin_session_path
visit new_admin_session_path
fill_in 'user_password', with: admin.password page.within('.navbar-sub-nav') do
find_all('a', text: 'Projects').first.click
end
click_button 'Enter Admin Mode' expect(page).to have_current_path(dashboard_projects_path)
end
expect(page).to have_current_path(admin_root_path) it 'is necessary to provide credentials again before opening pages in admin scope' do
end visit general_admin_application_settings_path # admin logged out because not in admin_mode
context 'on a read-only instance' do expect(page).to have_current_path(new_admin_session_path)
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end end
it 'can enter admin mode' do it 'can enter admin mode' do
...@@ -68,108 +56,163 @@ RSpec.describe 'Admin mode' do ...@@ -68,108 +56,163 @@ RSpec.describe 'Admin mode' do
expect(page).to have_current_path(admin_root_path) expect(page).to have_current_path(admin_root_path)
end end
end
end
context 'when in admin_mode' do context 'on a read-only instance' do
before do before do
gitlab_enable_admin_mode_sign_in(admin) allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end end
it 'contains link to leave admin mode' do it 'can enter admin mode' do
page.within('.navbar-sub-nav') do visit new_admin_session_path
expect(page).to have_link(href: destroy_admin_session_path)
fill_in 'user_password', with: admin.password
click_button 'Enter Admin Mode'
expect(page).to have_current_path(admin_root_path)
end
end end
end end
it 'can leave admin mode using main dashboard link', :js do context 'when in admin_mode' do
page.within('.navbar-sub-nav') do before do
click_on 'Leave Admin Mode' gitlab_enable_admin_mode_sign_in(admin)
end
it 'contains link to leave admin mode' do
pending_on_combined_menu_flag
expect(page).to have_link(href: new_admin_session_path) page.within('.navbar-sub-nav') do
expect(page).to have_link(href: destroy_admin_session_path)
end
end end
end
it 'can leave admin mode using dropdown menu on smaller screens', :js do it 'can leave admin mode using main dashboard link', :js do
resize_screen_xs pending_on_combined_menu_flag
visit root_dashboard_path
page.within('.navbar-sub-nav') do
click_on 'Leave Admin Mode'
find('.header-more').click expect(page).to have_link(href: new_admin_session_path)
end
end
page.within '.navbar-sub-nav' do it 'can leave admin mode using dropdown menu on smaller screens', :js do
click_on 'Leave Admin Mode' pending_on_combined_menu_flag
resize_screen_xs
visit root_dashboard_path
find('.header-more').click find('.header-more').click
expect(page).to have_link(href: new_admin_session_path) page.within '.navbar-sub-nav' do
end click_on 'Leave Admin Mode'
end
it 'can open pages not in admin scope' do find('.header-more').click
page.within('.navbar-sub-nav') do
find_all('a', text: 'Projects').first.click
expect(page).to have_current_path(dashboard_projects_path) expect(page).to have_link(href: new_admin_session_path)
end
end end
end
context 'nav bar' do it 'can open pages not in admin scope' do
it 'shows admin dashboard links on bigger screen' do pending_on_combined_menu_flag
visit root_dashboard_path
page.within('.navbar-sub-nav') do
find_all('a', text: 'Projects').first.click
page.within '.navbar' do expect(page).to have_current_path(dashboard_projects_path)
expect(page).to have_link(text: 'Admin Area', href: admin_root_path, visible: true)
expect(page).to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true)
end end
end end
it 'relocates admin dashboard links to dropdown list on smaller screen', :js do context 'nav bar' do
resize_screen_xs it 'shows admin dashboard links on bigger screen' do
visit root_dashboard_path pending_on_combined_menu_flag
page.within '.navbar' do visit root_dashboard_path
expect(page).not_to have_link(text: 'Admin Area', href: admin_root_path, visible: true)
expect(page).not_to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true) page.within '.navbar' do
expect(page).to have_link(text: 'Admin Area', href: admin_root_path, visible: true)
expect(page).to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true)
end
end end
find('.header-more').click it 'relocates admin dashboard links to dropdown list on smaller screen', :js do
pending_on_combined_menu_flag
resize_screen_xs
visit root_dashboard_path
page.within '.navbar' do page.within '.navbar' do
expect(page).to have_link(text: 'Admin Area', href: admin_root_path, visible: true) expect(page).not_to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true)
expect(page).to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true) end
find('.header-more').click
page.within '.navbar' do
expect(page).to have_link(text: 'Admin Area', href: admin_root_path, visible: true)
expect(page).to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true)
end
end end
end end
end
context 'on a read-only instance' do context 'on a read-only instance' do
before do before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true) allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end end
it 'can leave admin mode', :js do it 'can leave admin mode', :js do
page.within('.navbar-sub-nav') do pending_on_combined_menu_flag
click_on 'Leave Admin Mode'
expect(page).to have_link(href: new_admin_session_path) page.within('.navbar-sub-nav') do
click_on 'Leave Admin Mode'
expect(page).to have_link(href: new_admin_session_path)
end
end end
end end
end end
end end
context 'application setting :admin_mode is disabled' do
before do
stub_application_setting(admin_mode: false)
sign_in(admin)
end
it 'shows no admin mode buttons in navbar' do
pending_on_combined_menu_flag
visit admin_root_path
page.within('.navbar-sub-nav') do
expect(page).not_to have_link(href: new_admin_session_path)
expect(page).not_to have_link(href: destroy_admin_session_path)
end
end
end
end end
context 'application setting :admin_mode is disabled' do context 'with combined_menu: feature flag on' do
let(:needs_rewrite_for_combined_menu_flag_on) { true }
before do before do
stub_application_setting(admin_mode: false) stub_feature_flags(combined_menu: true)
sign_in(admin)
end end
it 'shows no admin mode buttons in navbar' do it_behaves_like 'combined_menu: feature flag examples'
visit admin_root_path end
page.within('.navbar-sub-nav') do context 'with combined_menu feature flag off' do
expect(page).not_to have_link(href: new_admin_session_path) let(:needs_rewrite_for_combined_menu_flag_on) { false }
expect(page).not_to have_link(href: destroy_admin_session_path)
end before do
stub_feature_flags(combined_menu: false)
end end
it_behaves_like 'combined_menu: feature flag examples'
end
def pending_on_combined_menu_flag
pending 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56587' if needs_rewrite_for_combined_menu_flag_on
end end
end end
...@@ -3,30 +3,56 @@ ...@@ -3,30 +3,56 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Dashboard Active Tab', :js do RSpec.describe 'Dashboard Active Tab', :js do
before do shared_examples 'combined_menu: feature flag examples' do
stub_feature_flags(combined_menu: false) before do
sign_in(create(:user))
end
sign_in(create(:user)) shared_examples 'page has active tab' do |title|
end it "#{title} tab" do
pending_on_combined_menu_flag
subject
shared_examples 'page has active tab' do |title| expect(page).to have_selector('.navbar-sub-nav li.active', count: 1)
it "#{title} tab" do expect(find('.navbar-sub-nav li.active')).to have_content(title)
subject end
end
context 'on dashboard projects' do
it_behaves_like 'page has active tab', 'Projects' do
subject { visit dashboard_projects_path }
end
end
expect(page).to have_selector('.navbar-sub-nav li.active', count: 1) context 'on dashboard groups' do
expect(find('.navbar-sub-nav li.active')).to have_content(title) it_behaves_like 'page has active tab', 'Groups' do
subject { visit dashboard_groups_path }
end
end end
end end
context 'on dashboard projects' do context 'with combined_menu: feature flag on' do
it_behaves_like 'page has active tab', 'Projects' do let(:needs_rewrite_for_combined_menu_flag_on) { true }
subject { visit dashboard_projects_path }
before do
stub_feature_flags(combined_menu: true)
end end
it_behaves_like 'combined_menu: feature flag examples'
end end
context 'on dashboard groups' do context 'with combined_menu feature flag off' do
it_behaves_like 'page has active tab', 'Groups' do let(:needs_rewrite_for_combined_menu_flag_on) { false }
subject { visit dashboard_groups_path }
before do
stub_feature_flags(combined_menu: false)
end end
it_behaves_like 'combined_menu: feature flag examples'
end
def pending_on_combined_menu_flag
pending 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56587' if needs_rewrite_for_combined_menu_flag_on
end end
end end
...@@ -7,36 +7,64 @@ RSpec.describe 'The group dashboard' do ...@@ -7,36 +7,64 @@ RSpec.describe 'The group dashboard' do
let(:user) { create(:user) } let(:user) { create(:user) }
before do shared_examples 'combined_menu: feature flag examples' do
stub_feature_flags(combined_menu: false) before do
sign_in user
end
sign_in user describe 'The top navigation' do
end it 'has all the expected links' do
pending_on_combined_menu_flag
describe 'The top navigation' do visit dashboard_groups_path
it 'has all the expected links' do
visit dashboard_groups_path
within('.navbar') do within('.navbar') do
expect(page).to have_button('Projects') expect(page).to have_button('Projects')
expect(page).to have_button('Groups') expect(page).to have_button('Groups')
expect(page).to have_link('Activity') expect(page).to have_link('Activity')
expect(page).to have_link('Milestones') expect(page).to have_link('Milestones')
expect(page).to have_link('Snippets') expect(page).to have_link('Snippets')
end
end end
end
it 'hides some links when an external authorization service is enabled' do it 'hides some links when an external authorization service is enabled' do
enable_external_authorization_service_check pending_on_combined_menu_flag
visit dashboard_groups_path
enable_external_authorization_service_check
visit dashboard_groups_path
within('.navbar') do within('.navbar') do
expect(page).to have_button('Projects') expect(page).to have_button('Projects')
expect(page).to have_button('Groups') expect(page).to have_button('Groups')
expect(page).not_to have_link('Activity') expect(page).not_to have_link('Activity')
expect(page).not_to have_link('Milestones') expect(page).not_to have_link('Milestones')
expect(page).to have_link('Snippets') expect(page).to have_link('Snippets')
end
end end
end end
end end
context 'with combined_menu: feature flag on' do
let(:needs_rewrite_for_combined_menu_flag_on) { true }
before do
stub_feature_flags(combined_menu: true)
end
it_behaves_like 'combined_menu: feature flag examples'
end
context 'with combined_menu feature flag off' do
let(:needs_rewrite_for_combined_menu_flag_on) { false }
before do
stub_feature_flags(combined_menu: false)
end
it_behaves_like 'combined_menu: feature flag examples'
end
def pending_on_combined_menu_flag
pending 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56587' if needs_rewrite_for_combined_menu_flag_on
end
end end
...@@ -3,71 +3,97 @@ ...@@ -3,71 +3,97 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Dashboard shortcuts', :js do RSpec.describe 'Dashboard shortcuts', :js do
before do shared_examples 'combined_menu: feature flag examples' do
stub_feature_flags(combined_menu: false) context 'logged in' do
end let(:user) { create(:user) }
let(:project) { create(:project) }
context 'logged in' do before do
let(:user) { create(:user) } project.add_developer(user)
let(:project) { create(:project) } sign_in(user)
visit root_dashboard_path
end
before do it 'navigate to tabs' do
project.add_developer(user) pending_on_combined_menu_flag
sign_in(user)
visit root_dashboard_path
end
it 'navigate to tabs' do find('body').send_keys([:shift, 'I'])
find('body').send_keys([:shift, 'I'])
check_page_title('Issues') check_page_title('Issues')
find('body').send_keys([:shift, 'M']) find('body').send_keys([:shift, 'M'])
check_page_title('Merge requests') check_page_title('Merge requests')
find('body').send_keys([:shift, 'T']) find('body').send_keys([:shift, 'T'])
check_page_title('To-Do List') check_page_title('To-Do List')
find('body').send_keys([:shift, 'G']) find('body').send_keys([:shift, 'G'])
check_page_title('Groups') check_page_title('Groups')
find('body').send_keys([:shift, 'P']) find('body').send_keys([:shift, 'P'])
check_page_title('Projects') check_page_title('Projects')
find('body').send_keys([:shift, 'A']) find('body').send_keys([:shift, 'A'])
check_page_title('Activity') check_page_title('Activity')
end
end end
end
context 'logged out' do context 'logged out' do
before do before do
visit explore_root_path visit explore_root_path
end
it 'navigate to tabs' do
pending_on_combined_menu_flag
find('body').send_keys([:shift, 'G'])
find('.nothing-here-block')
expect(page).to have_content('No public groups')
find('body').send_keys([:shift, 'S'])
find('.nothing-here-block')
expect(page).to have_content('No snippets found')
find('body').send_keys([:shift, 'P'])
find('.nothing-here-block')
expect(page).to have_content('Explore public groups to find projects to contribute to.')
end
end end
it 'navigate to tabs' do def check_page_title(title)
find('body').send_keys([:shift, 'G']) expect(find('.page-title')).to have_content(title)
end
end
find('.nothing-here-block') context 'with combined_menu: feature flag on' do
expect(page).to have_content('No public groups') let(:needs_rewrite_for_combined_menu_flag_on) { true }
find('body').send_keys([:shift, 'S']) before do
stub_feature_flags(combined_menu: true)
end
find('.nothing-here-block') it_behaves_like 'combined_menu: feature flag examples'
expect(page).to have_content('No snippets found') end
find('body').send_keys([:shift, 'P']) context 'with combined_menu feature flag off' do
let(:needs_rewrite_for_combined_menu_flag_on) { false }
find('.nothing-here-block') before do
expect(page).to have_content('Explore public groups to find projects to contribute to.') stub_feature_flags(combined_menu: false)
end end
it_behaves_like 'combined_menu: feature flag examples'
end end
def check_page_title(title) def pending_on_combined_menu_flag
expect(find('.page-title')).to have_content(title) pending 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56587' if needs_rewrite_for_combined_menu_flag_on
end end
end end
...@@ -5,45 +5,73 @@ require 'spec_helper' ...@@ -5,45 +5,73 @@ require 'spec_helper'
RSpec.describe 'Frequently visited items', :js do RSpec.describe 'Frequently visited items', :js do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
before do shared_examples 'combined_menu: feature flag examples' do
stub_feature_flags(combined_menu: false) before do
sign_in(user)
end
sign_in(user) context 'for projects' do
end let_it_be(:project) { create(:project, :public) }
context 'for projects' do it 'increments localStorage counter when visiting the project' do
let_it_be(:project) { create(:project, :public) } pending_on_combined_menu_flag
it 'increments localStorage counter when visiting the project' do visit project_path(project)
visit project_path(project)
frequent_projects = nil frequent_projects = nil
wait_for('localStorage frequent-projects') do wait_for('localStorage frequent-projects') do
frequent_projects = page.evaluate_script("localStorage['#{user.username}/frequent-projects']") frequent_projects = page.evaluate_script("localStorage['#{user.username}/frequent-projects']")
frequent_projects.present? frequent_projects.present?
end end
expect(Gitlab::Json.parse(frequent_projects)).to contain_exactly(a_hash_including('id' => project.id, 'frequency' => 1)) expect(Gitlab::Json.parse(frequent_projects)).to contain_exactly(a_hash_including('id' => project.id, 'frequency' => 1))
end
end end
end
context 'for groups' do context 'for groups' do
let_it_be(:group) { create(:group, :public) } let_it_be(:group) { create(:group, :public) }
it 'increments localStorage counter when visiting the group' do it 'increments localStorage counter when visiting the group' do
visit group_path(group) pending_on_combined_menu_flag
frequent_groups = nil visit group_path(group)
wait_for('localStorage frequent-groups') do frequent_groups = nil
frequent_groups = page.evaluate_script("localStorage['#{user.username}/frequent-groups']")
frequent_groups.present? wait_for('localStorage frequent-groups') do
frequent_groups = page.evaluate_script("localStorage['#{user.username}/frequent-groups']")
frequent_groups.present?
end
expect(Gitlab::Json.parse(frequent_groups)).to contain_exactly(a_hash_including('id' => group.id, 'frequency' => 1))
end end
end
end
expect(Gitlab::Json.parse(frequent_groups)).to contain_exactly(a_hash_including('id' => group.id, 'frequency' => 1)) context 'with combined_menu: feature flag on' do
let(:needs_rewrite_for_combined_menu_flag_on) { true }
before do
stub_feature_flags(combined_menu: true)
end end
it_behaves_like 'combined_menu: feature flag examples'
end
context 'with combined_menu feature flag off' do
let(:needs_rewrite_for_combined_menu_flag_on) { false }
before do
stub_feature_flags(combined_menu: false)
end
it_behaves_like 'combined_menu: feature flag examples'
end
def pending_on_combined_menu_flag
pending 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56587' if needs_rewrite_for_combined_menu_flag_on
end end
end end
...@@ -5,50 +5,48 @@ require 'spec_helper' ...@@ -5,50 +5,48 @@ require 'spec_helper'
RSpec.describe 'New project', :js do RSpec.describe 'New project', :js do
include Select2Helper include Select2Helper
context 'as a user' do shared_examples 'combined_menu: feature flag examples' do
let(:user) { create(:user) } context 'as a user' do
let(:user) { create(:user) }
before do before do
sign_in(user) sign_in(user)
end end
context 'new repo experiment', :experiment do
it 'when in control renders "project"' do
stub_experiments(new_repo: :control)
visit new_project_path context 'new repo experiment', :experiment do
it 'when in control renders "project"' do
stub_experiments(new_repo: :control)
find('li.header-new.dropdown').click visit new_project_path
page.within('li.header-new.dropdown') do find('li.header-new.dropdown').click
expect(page).to have_selector('a', text: 'New project')
expect(page).to have_no_selector('a', text: 'New project/repository')
end
expect(page).to have_selector('h3', text: 'Create blank project') page.within('li.header-new.dropdown') do
expect(page).to have_no_selector('h3', text: 'Create blank project/repository') expect(page).to have_selector('a', text: 'New project')
end expect(page).to have_no_selector('a', text: 'New project/repository')
end
it 'when in candidate renders "project/repository"' do expect(page).to have_selector('h3', text: 'Create blank project')
stub_experiments(new_repo: :candidate) expect(page).to have_no_selector('h3', text: 'Create blank project/repository')
end
visit new_project_path it 'when in candidate renders "project/repository"' do
stub_experiments(new_repo: :candidate)
find('li.header-new.dropdown').click visit new_project_path
page.within('li.header-new.dropdown') do find('li.header-new.dropdown').click
expect(page).to have_selector('a', text: 'New project/repository')
end
expect(page).to have_selector('h3', text: 'Create blank project/repository') page.within('li.header-new.dropdown') do
end expect(page).to have_selector('a', text: 'New project/repository')
end
context 'with combined_menu feature disabled' do expect(page).to have_selector('h3', text: 'Create blank project/repository')
before do
stub_feature_flags(combined_menu: false)
end end
it 'when in control it renders "project" in the new projects dropdown' do it 'when in control it renders "project" in the new projects dropdown' do
pending_on_combined_menu_flag
stub_experiments(new_repo: :control) stub_experiments(new_repo: :control)
visit new_project_path visit new_project_path
...@@ -64,6 +62,8 @@ RSpec.describe 'New project', :js do ...@@ -64,6 +62,8 @@ RSpec.describe 'New project', :js do
end end
it 'when in candidate it renders "project/repository" in the new projects dropdown' do it 'when in candidate it renders "project/repository" in the new projects dropdown' do
pending_on_combined_menu_flag
stub_experiments(new_repo: :candidate) stub_experiments(new_repo: :candidate)
visit new_project_path visit new_project_path
...@@ -76,347 +76,373 @@ RSpec.describe 'New project', :js do ...@@ -76,347 +76,373 @@ RSpec.describe 'New project', :js do
end end
end end
end end
end
it 'shows a message if multiple levels are restricted' do it 'shows a message if multiple levels are restricted' do
Gitlab::CurrentSettings.update!( Gitlab::CurrentSettings.update!(
restricted_visibility_levels: [Gitlab::VisibilityLevel::PRIVATE, Gitlab::VisibilityLevel::INTERNAL] restricted_visibility_levels: [Gitlab::VisibilityLevel::PRIVATE, Gitlab::VisibilityLevel::INTERNAL]
) )
visit new_project_path visit new_project_path
find('[data-qa-selector="blank_project_link"]').click find('[data-qa-selector="blank_project_link"]').click
expect(page).to have_content 'Other visibility settings have been disabled by the administrator.'
end
it 'shows a message if all levels are restricted' do expect(page).to have_content 'Other visibility settings have been disabled by the administrator.'
Gitlab::CurrentSettings.update!( end
restricted_visibility_levels: Gitlab::VisibilityLevel.values
)
visit new_project_path it 'shows a message if all levels are restricted' do
find('[data-qa-selector="blank_project_link"]').click Gitlab::CurrentSettings.update!(
restricted_visibility_levels: Gitlab::VisibilityLevel.values
)
expect(page).to have_content 'Visibility settings have been disabled by the administrator.' visit new_project_path
end find('[data-qa-selector="blank_project_link"]').click
end
context 'as an admin' do
let(:user) { create(:admin) }
before do expect(page).to have_content 'Visibility settings have been disabled by the administrator.'
sign_in(user) end
end end
it 'shows "New project" page', :js do context 'as an admin' do
visit new_project_path let(:user) { create(:admin) }
find('[data-qa-selector="blank_project_link"]').click
expect(page).to have_content('Project name')
expect(page).to have_content('Project URL')
expect(page).to have_content('Project slug')
click_link('New project')
find('[data-qa-selector="import_project_link"]').click
expect(page).to have_link('GitHub')
expect(page).to have_link('Bitbucket')
expect(page).to have_link('GitLab.com')
expect(page).to have_button('Repo by URL')
expect(page).to have_link('GitLab export')
end
describe 'manifest import option' do
before do before do
sign_in(user)
end
it 'shows "New project" page', :js do
visit new_project_path visit new_project_path
find('[data-qa-selector="blank_project_link"]').click
find('[data-qa-selector="import_project_link"]').click expect(page).to have_content('Project name')
end expect(page).to have_content('Project URL')
expect(page).to have_content('Project slug')
it { expect(page).to have_link('Manifest file') } click_link('New project')
end find('[data-qa-selector="import_project_link"]').click
context 'Visibility level selector', :js do expect(page).to have_link('GitHub')
Gitlab::VisibilityLevel.options.each do |key, level| expect(page).to have_link('Bitbucket')
it "sets selector to #{key}" do expect(page).to have_link('GitLab.com')
stub_application_setting(default_project_visibility: level) expect(page).to have_button('Repo by URL')
expect(page).to have_link('GitLab export')
end
describe 'manifest import option' do
before do
visit new_project_path visit new_project_path
find('[data-qa-selector="blank_project_link"]').click
page.within('#blank-project-pane') do
expect(find_field("project_visibility_level_#{level}")).to be_checked
end
end
it "saves visibility level #{level} on validation error" do find('[data-qa-selector="import_project_link"]').click
visit new_project_path end
find('[data-qa-selector="blank_project_link"]').click
choose(key) it 'has Manifest file' do
click_button('Create project') expect(page).to have_link('Manifest file')
page.within('#blank-project-pane') do
expect(find_field("project_visibility_level_#{level}")).to be_checked
end
end end
end end
context 'when group visibility is private but default is internal' do context 'Visibility level selector', :js do
let_it_be(:group) { create(:group, visibility_level: Gitlab::VisibilityLevel::PRIVATE) } Gitlab::VisibilityLevel.options.each do |key, level|
it "sets selector to #{key}" do
stub_application_setting(default_project_visibility: level)
before do visit new_project_path
stub_application_setting(default_project_visibility: Gitlab::VisibilityLevel::INTERNAL) find('[data-qa-selector="blank_project_link"]').click
end page.within('#blank-project-pane') do
expect(find_field("project_visibility_level_#{level}")).to be_checked
end
end
context 'when admin mode is enabled', :enable_admin_mode do it "saves visibility level #{level} on validation error" do
it 'has private selected' do visit new_project_path
visit new_project_path(namespace_id: group.id)
find('[data-qa-selector="blank_project_link"]').click find('[data-qa-selector="blank_project_link"]').click
choose(key)
click_button('Create project')
page.within('#blank-project-pane') do page.within('#blank-project-pane') do
expect(find_field("project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).to be_checked expect(find_field("project_visibility_level_#{level}")).to be_checked
end end
end end
end end
context 'when admin mode is disabled' do context 'when group visibility is private but default is internal' do
it 'is not allowed' do let_it_be(:group) { create(:group, visibility_level: Gitlab::VisibilityLevel::PRIVATE) }
visit new_project_path(namespace_id: group.id)
expect(page).to have_content('Not Found') before do
stub_application_setting(default_project_visibility: Gitlab::VisibilityLevel::INTERNAL)
end end
end
end
context 'when group visibility is public but user requests private' do context 'when admin mode is enabled', :enable_admin_mode do
let_it_be(:group) { create(:group, visibility_level: Gitlab::VisibilityLevel::PUBLIC) } it 'has private selected' do
visit new_project_path(namespace_id: group.id)
find('[data-qa-selector="blank_project_link"]').click
before do page.within('#blank-project-pane') do
stub_application_setting(default_project_visibility: Gitlab::VisibilityLevel::INTERNAL) expect(find_field("project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).to be_checked
end end
end
end
context 'when admin mode is enabled', :enable_admin_mode do context 'when admin mode is disabled' do
it 'has private selected' do it 'is not allowed' do
visit new_project_path(namespace_id: group.id, project: { visibility_level: Gitlab::VisibilityLevel::PRIVATE }) visit new_project_path(namespace_id: group.id)
find('[data-qa-selector="blank_project_link"]').click
page.within('#blank-project-pane') do expect(page).to have_content('Not Found')
expect(find_field("project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).to be_checked
end end
end end
end end
context 'when admin mode is disabled' do context 'when group visibility is public but user requests private' do
it 'is not allowed' do let_it_be(:group) { create(:group, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
visit new_project_path(namespace_id: group.id, project: { visibility_level: Gitlab::VisibilityLevel::PRIVATE })
expect(page).to have_content('Not Found') before do
stub_application_setting(default_project_visibility: Gitlab::VisibilityLevel::INTERNAL)
end end
end
end
end
context 'Readme selector' do context 'when admin mode is enabled', :enable_admin_mode do
it 'shows the initialize with Readme checkbox on "Blank project" tab' do it 'has private selected' do
visit new_project_path visit new_project_path(namespace_id: group.id, project: { visibility_level: Gitlab::VisibilityLevel::PRIVATE })
find('[data-qa-selector="blank_project_link"]').click find('[data-qa-selector="blank_project_link"]').click
expect(page).to have_css('input#project_initialize_with_readme') page.within('#blank-project-pane') do
expect(page).to have_content('Initialize repository with a README') expect(find_field("project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).to be_checked
end end
end
end
it 'does not show the initialize with Readme checkbox on "Create from template" tab' do context 'when admin mode is disabled' do
visit new_project_path it 'is not allowed' do
find('[data-qa-selector="create_from_template_link"]').click visit new_project_path(namespace_id: group.id, project: { visibility_level: Gitlab::VisibilityLevel::PRIVATE })
first('.choose-template').click
page.within '.project-fields-form' do expect(page).to have_content('Not Found')
expect(page).not_to have_css('input#project_initialize_with_readme') end
expect(page).not_to have_content('Initialize repository with a README') end
end end
end end
it 'does not show the initialize with Readme checkbox on "Import project" tab' do context 'Readme selector' do
visit new_project_path it 'shows the initialize with Readme checkbox on "Blank project" tab' do
find('[data-qa-selector="import_project_link"]').click visit new_project_path
first('.js-import-git-toggle-button').click find('[data-qa-selector="blank_project_link"]').click
page.within '#import-project-pane' do expect(page).to have_css('input#project_initialize_with_readme')
expect(page).not_to have_css('input#project_initialize_with_readme') expect(page).to have_content('Initialize repository with a README')
expect(page).not_to have_content('Initialize repository with a README')
end end
end
end
context 'Namespace selector' do it 'does not show the initialize with Readme checkbox on "Create from template" tab' do
context 'with user namespace' do
before do
visit new_project_path visit new_project_path
find('[data-qa-selector="blank_project_link"]').click find('[data-qa-selector="create_from_template_link"]').click
first('.choose-template').click
page.within '.project-fields-form' do
expect(page).not_to have_css('input#project_initialize_with_readme')
expect(page).not_to have_content('Initialize repository with a README')
end
end end
it 'selects the user namespace' do it 'does not show the initialize with Readme checkbox on "Import project" tab' do
page.within('#blank-project-pane') do visit new_project_path
expect(page).to have_select('project[namespace_id]', visible: false, selected: user.username) find('[data-qa-selector="import_project_link"]').click
first('.js-import-git-toggle-button').click
page.within '#import-project-pane' do
expect(page).not_to have_css('input#project_initialize_with_readme')
expect(page).not_to have_content('Initialize repository with a README')
end end
end end
end end
context 'with group namespace' do context 'Namespace selector' do
let(:group) { create(:group, :private) } context 'with user namespace' do
before do
visit new_project_path
find('[data-qa-selector="blank_project_link"]').click
end
before do it 'selects the user namespace' do
group.add_owner(user) page.within('#blank-project-pane') do
visit new_project_path(namespace_id: group.id) expect(page).to have_select('project[namespace_id]', visible: false, selected: user.username)
find('[data-qa-selector="blank_project_link"]').click end
end
end end
it 'selects the group namespace' do context 'with group namespace' do
page.within('#blank-project-pane') do let(:group) { create(:group, :private) }
expect(page).to have_select('project[namespace_id]', visible: false, selected: group.name)
before do
group.add_owner(user)
visit new_project_path(namespace_id: group.id)
find('[data-qa-selector="blank_project_link"]').click
end
it 'selects the group namespace' do
page.within('#blank-project-pane') do
expect(page).to have_select('project[namespace_id]', visible: false, selected: group.name)
end
end end
end end
end
context 'with subgroup namespace' do context 'with subgroup namespace' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:subgroup) { create(:group, parent: group) } let(:subgroup) { create(:group, parent: group) }
before do before do
group.add_maintainer(user) group.add_maintainer(user)
visit new_project_path(namespace_id: subgroup.id) visit new_project_path(namespace_id: subgroup.id)
find('[data-qa-selector="blank_project_link"]').click find('[data-qa-selector="blank_project_link"]').click
end end
it 'selects the group namespace' do it 'selects the group namespace' do
page.within('#blank-project-pane') do page.within('#blank-project-pane') do
expect(page).to have_select('project[namespace_id]', visible: false, selected: subgroup.full_path) expect(page).to have_select('project[namespace_id]', visible: false, selected: subgroup.full_path)
end
end end
end end
end
context 'when changing namespaces dynamically', :js do context 'when changing namespaces dynamically', :js do
let(:public_group) { create(:group, :public) } let(:public_group) { create(:group, :public) }
let(:internal_group) { create(:group, :internal) } let(:internal_group) { create(:group, :internal) }
let(:private_group) { create(:group, :private) } let(:private_group) { create(:group, :private) }
before do before do
public_group.add_owner(user) public_group.add_owner(user)
internal_group.add_owner(user) internal_group.add_owner(user)
private_group.add_owner(user) private_group.add_owner(user)
visit new_project_path(namespace_id: public_group.id) visit new_project_path(namespace_id: public_group.id)
find('[data-qa-selector="blank_project_link"]').click find('[data-qa-selector="blank_project_link"]').click
end end
it 'enables the correct visibility options' do it 'enables the correct visibility options' do
select2(user.namespace_id, from: '#project_namespace_id') select2(user.namespace_id, from: '#project_namespace_id')
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).not_to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).not_to be_disabled
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::INTERNAL}")).not_to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::INTERNAL}")).not_to be_disabled
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PUBLIC}")).not_to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PUBLIC}")).not_to be_disabled
select2(public_group.id, from: '#project_namespace_id') select2(public_group.id, from: '#project_namespace_id')
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).not_to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).not_to be_disabled
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::INTERNAL}")).not_to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::INTERNAL}")).not_to be_disabled
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PUBLIC}")).not_to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PUBLIC}")).not_to be_disabled
select2(internal_group.id, from: '#project_namespace_id') select2(internal_group.id, from: '#project_namespace_id')
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).not_to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).not_to be_disabled
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::INTERNAL}")).not_to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::INTERNAL}")).not_to be_disabled
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PUBLIC}")).to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PUBLIC}")).to be_disabled
select2(private_group.id, from: '#project_namespace_id') select2(private_group.id, from: '#project_namespace_id')
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).not_to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PRIVATE}")).not_to be_disabled
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::INTERNAL}")).to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::INTERNAL}")).to be_disabled
expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PUBLIC}")).to be_disabled expect(find("#project_visibility_level_#{Gitlab::VisibilityLevel::PUBLIC}")).to be_disabled
end
end end
end end
end
context 'Import project options', :js do
before do
visit new_project_path
find('[data-qa-selector="import_project_link"]').click
end
context 'from git repository url, "Repo by URL"' do context 'Import project options', :js do
before do before do
first('.js-import-git-toggle-button').click visit new_project_path
find('[data-qa-selector="import_project_link"]').click
end end
it 'does not autocomplete sensitive git repo URL' do context 'from git repository url, "Repo by URL"' do
autocomplete = find('#project_import_url')['autocomplete'] before do
first('.js-import-git-toggle-button').click
end
expect(autocomplete).to eq('off') it 'does not autocomplete sensitive git repo URL' do
end autocomplete = find('#project_import_url')['autocomplete']
it 'shows import instructions' do expect(autocomplete).to eq('off')
git_import_instructions = first('.js-toggle-content') end
expect(git_import_instructions).to be_visible it 'shows import instructions' do
expect(git_import_instructions).to have_content 'Git repository URL' git_import_instructions = first('.js-toggle-content')
end
it 'reports error if repo URL does not end with .git' do expect(git_import_instructions).to be_visible
fill_in 'project_import_url', with: 'http://foo/bar' expect(git_import_instructions).to have_content 'Git repository URL'
fill_in 'project_name', with: 'import-project-without-git-suffix' end
fill_in 'project_path', with: 'import-project-without-git-suffix'
click_button 'Create project' it 'reports error if repo URL does not end with .git' do
fill_in 'project_import_url', with: 'http://foo/bar'
fill_in 'project_name', with: 'import-project-without-git-suffix'
fill_in 'project_path', with: 'import-project-without-git-suffix'
expect(page).to have_text('Please provide a valid URL ending with .git') click_button 'Create project'
end
it 'keeps "Import project" tab open after form validation error' do expect(page).to have_text('Please provide a valid URL ending with .git')
collision_project = create(:project, name: 'test-name-collision', namespace: user.namespace) end
fill_in 'project_import_url', with: collision_project.http_url_to_repo it 'keeps "Import project" tab open after form validation error' do
fill_in 'project_name', with: collision_project.name collision_project = create(:project, name: 'test-name-collision', namespace: user.namespace)
click_on 'Create project' fill_in 'project_import_url', with: collision_project.http_url_to_repo
fill_in 'project_name', with: collision_project.name
expect(page).to have_css('#import-project-pane.active') click_on 'Create project'
expect(page).not_to have_css('.toggle-import-form.hide')
end
end
context 'from GitHub' do expect(page).to have_css('#import-project-pane.active')
before do expect(page).not_to have_css('.toggle-import-form.hide')
first('.js-import-github').click end
end end
it 'shows import instructions' do context 'from GitHub' do
expect(page).to have_content('Authenticate with GitHub') before do
expect(current_path).to eq new_import_github_path first('.js-import-github').click
end end
end
context 'from manifest file' do it 'shows import instructions' do
before do expect(page).to have_content('Authenticate with GitHub')
first('.import_manifest').click expect(current_path).to eq new_import_github_path
end
end end
it 'shows import instructions' do context 'from manifest file' do
expect(page).to have_content('Manifest file import') before do
expect(current_path).to eq new_import_manifest_path first('.import_manifest').click
end
it 'shows import instructions' do
expect(page).to have_content('Manifest file import')
expect(current_path).to eq new_import_manifest_path
end
end end
end end
end
context 'Namespace selector' do context 'Namespace selector' do
context 'with group with DEVELOPER_MAINTAINER_PROJECT_ACCESS project_creation_level' do context 'with group with DEVELOPER_MAINTAINER_PROJECT_ACCESS project_creation_level' do
let(:group) { create(:group, project_creation_level: ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS) } let(:group) { create(:group, project_creation_level: ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS) }
before do before do
group.add_developer(user) group.add_developer(user)
visit new_project_path(namespace_id: group.id) visit new_project_path(namespace_id: group.id)
find('[data-qa-selector="blank_project_link"]').click find('[data-qa-selector="blank_project_link"]').click
end end
it 'selects the group namespace' do it 'selects the group namespace' do
page.within('#blank-project-pane') do page.within('#blank-project-pane') do
expect(page).to have_select('project[namespace_id]', visible: false, selected: group.full_path) expect(page).to have_select('project[namespace_id]', visible: false, selected: group.full_path)
end
end end
end end
end end
end end
end end
context 'with combined_menu: feature flag on' do
let(:needs_rewrite_for_combined_menu_flag_on) { true }
before do
stub_feature_flags(combined_menu: true)
end
it_behaves_like 'combined_menu: feature flag examples'
end
context 'with combined_menu feature flag off' do
let(:needs_rewrite_for_combined_menu_flag_on) { false }
before do
stub_feature_flags(combined_menu: false)
end
it_behaves_like 'combined_menu: feature flag examples'
end
def pending_on_combined_menu_flag
pending 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56587' if needs_rewrite_for_combined_menu_flag_on
end
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