diff options
Diffstat (limited to 'spec/features/projects')
9 files changed, 680 insertions, 2 deletions
diff --git a/spec/features/projects/commit/builds_spec.rb b/spec/features/projects/commit/builds_spec.rb index f97abc5bd8b..00ec9d49a10 100644 --- a/spec/features/projects/commit/builds_spec.rb +++ b/spec/features/projects/commit/builds_spec.rb @@ -19,7 +19,7 @@ RSpec.describe 'project commit pipelines', :js do context 'when no builds triggered yet' do it 'shows the ID of the first pipeline' do - page.within('.table-holder') do + page.within('.pipelines .ci-table') do expect(page).to have_content project.ci_pipelines[0].id # pipeline ids end end diff --git a/spec/features/projects/feature_flag_user_lists/user_deletes_feature_flag_user_list_spec.rb b/spec/features/projects/feature_flag_user_lists/user_deletes_feature_flag_user_list_spec.rb new file mode 100644 index 00000000000..2a81c706525 --- /dev/null +++ b/spec/features/projects/feature_flag_user_lists/user_deletes_feature_flag_user_list_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User deletes feature flag user list', :js do + let_it_be(:project) { create(:project) } + let_it_be(:developer) { create(:user) } + + before do + project.add_developer(developer) + sign_in(developer) + end + + context 'with a list' do + before do + create(:operations_feature_flag_user_list, project: project, name: 'My List') + end + + it 'deletes the list' do + visit(project_feature_flags_path(project, scope: 'userLists')) + + delete_user_list_button.click + delete_user_list_modal_confirmation_button.click + + expect(page).to have_text('Lists 0') + end + end + + context 'with a list that is in use' do + before do + list = create(:operations_feature_flag_user_list, project: project, name: 'My List') + feature_flag = create(:operations_feature_flag, :new_version_flag, project: project) + create(:operations_strategy, feature_flag: feature_flag, name: 'gitlabUserList', user_list: list) + end + + it 'does not delete the list' do + visit(project_feature_flags_path(project, scope: 'userLists')) + + delete_user_list_button.click + delete_user_list_modal_confirmation_button.click + + expect(page).to have_text('User list is associated with a strategy') + expect(page).to have_text('Lists 1') + expect(page).to have_text('My List') + + alert_dismiss_button.click + + expect(page).not_to have_text('User list is associated with a strategy') + end + end + + def delete_user_list_button + find("button[data-testid='delete-user-list']") + end + + def delete_user_list_modal_confirmation_button + find("button[data-testid='modal-confirm']") + end + + def alert_dismiss_button + find("div[data-testid='serverErrors'] button") + end +end diff --git a/spec/features/projects/feature_flag_user_lists/user_edits_feature_flag_user_list_spec.rb b/spec/features/projects/feature_flag_user_lists/user_edits_feature_flag_user_list_spec.rb new file mode 100644 index 00000000000..b37c2780827 --- /dev/null +++ b/spec/features/projects/feature_flag_user_lists/user_edits_feature_flag_user_list_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User edits feature flag user list', :js do + let_it_be(:project) { create(:project) } + let_it_be(:developer) { create(:user) } + + before do + project.add_developer(developer) + sign_in(developer) + end + + it 'prefills the edit form with the list name' do + list = create(:operations_feature_flag_user_list, project: project, name: 'My List Name') + + visit(edit_project_feature_flags_user_list_path(project, list)) + + expect(page).to have_field 'Name', with: 'My List Name' + end +end diff --git a/spec/features/projects/feature_flag_user_lists/user_sees_feature_flag_user_list_details_spec.rb b/spec/features/projects/feature_flag_user_lists/user_sees_feature_flag_user_list_details_spec.rb new file mode 100644 index 00000000000..dfebe6408bd --- /dev/null +++ b/spec/features/projects/feature_flag_user_lists/user_sees_feature_flag_user_list_details_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User sees feature flag user list details', :js do + let_it_be(:project) { create(:project) } + let_it_be(:developer) { create(:user) } + + before do + project.add_developer(developer) + sign_in(developer) + end + + it 'displays the list name' do + list = create(:operations_feature_flag_user_list, project: project, name: 'My List') + + visit(project_feature_flags_user_list_path(project, list)) + + expect(page).to have_text('My List') + end +end diff --git a/spec/features/projects/feature_flags/user_creates_feature_flag_spec.rb b/spec/features/projects/feature_flags/user_creates_feature_flag_spec.rb new file mode 100644 index 00000000000..830dda737b0 --- /dev/null +++ b/spec/features/projects/feature_flags/user_creates_feature_flag_spec.rb @@ -0,0 +1,200 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User creates feature flag', :js do + include FeatureFlagHelpers + + let(:user) { create(:user) } + let(:project) { create(:project, namespace: user.namespace) } + + before do + project.add_developer(user) + stub_feature_flags(feature_flag_permissions: false) + sign_in(user) + end + + it 'user creates a flag enabled for user ids' do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('test_feature', 'Test feature') + within_strategy_row(1) do + select 'User IDs', from: 'Type' + fill_in 'User IDs', with: 'user1, user2' + environment_plus_button.click + environment_search_input.set('production') + environment_search_results.first.click + end + click_button 'Create feature flag' + + expect_user_to_see_feature_flags_index_page + expect(page).to have_text('test_feature') + end + + it 'user creates a flag with default environment scopes' do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('test_flag', 'Test flag') + within_strategy_row(1) do + select 'All users', from: 'Type' + end + click_button 'Create feature flag' + + expect_user_to_see_feature_flags_index_page + expect(page).to have_text('test_flag') + + edit_feature_flag_button.click + + within_strategy_row(1) do + expect(page).to have_text('All users') + expect(page).to have_text('All environments') + end + end + + it 'removes the correct strategy when a strategy is deleted' do + visit(new_project_feature_flag_path(project)) + click_button 'Add strategy' + within_strategy_row(1) do + select 'All users', from: 'Type' + end + within_strategy_row(2) do + select 'Percent of users', from: 'Type' + end + within_strategy_row(1) do + delete_strategy_button.click + end + + within_strategy_row(1) do + expect(page).to have_select('Type', selected: 'Percent of users') + end + end + + context 'with new version flags disabled' do + before do + stub_feature_flags(feature_flags_new_version: false) + end + + context 'when creates without changing scopes' do + before do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('ci_live_trace', 'For live trace') + click_button 'Create feature flag' + expect(page).to have_current_path(project_feature_flags_path(project)) + end + + it 'shows the created feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') + expect_status_toggle_button_to_be_checked + + within_feature_flag_scopes do + expect(page.find('[data-qa-selector="feature-flag-scope-info-badge"]:nth-child(1)')).to have_content('*') + end + end + end + end + + context 'when creates with disabling the default scope' do + before do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('ci_live_trace', 'For live trace') + + within_scope_row(1) do + within_status { find('.project-feature-toggle').click } + end + + click_button 'Create feature flag' + end + + it 'shows the created feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') + expect_status_toggle_button_to_be_checked + + within_feature_flag_scopes do + expect(page.find('[data-qa-selector="feature-flag-scope-muted-badge"]:nth-child(1)')).to have_content('*') + end + end + end + end + + context 'when creates with an additional scope' do + before do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('mr_train', '') + + within_scope_row(2) do + within_environment_spec do + find('.js-env-search > input').set("review/*") + find('.js-create-button').click + end + end + + within_scope_row(2) do + within_status { find('.project-feature-toggle').click } + end + + click_button 'Create feature flag' + end + + it 'shows the created feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('mr_train') + expect_status_toggle_button_to_be_checked + + within_feature_flag_scopes do + expect(page.find('[data-qa-selector="feature-flag-scope-info-badge"]:nth-child(1)')).to have_content('*') + expect(page.find('[data-qa-selector="feature-flag-scope-info-badge"]:nth-child(2)')).to have_content('review/*') + end + end + end + end + + context 'when searches an environment name for scope creation' do + let!(:environment) { create(:environment, name: 'production', project: project) } + + before do + visit(new_project_feature_flag_path(project)) + set_feature_flag_info('mr_train', '') + + within_scope_row(2) do + within_environment_spec do + find('.js-env-search > input').set('prod') + click_button 'production' + end + end + + click_button 'Create feature flag' + end + + it 'shows the created feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('mr_train') + expect_status_toggle_button_to_be_checked + + within_feature_flag_scopes do + expect(page.find('[data-qa-selector="feature-flag-scope-info-badge"]:nth-child(1)')).to have_content('*') + expect(page.find('[data-qa-selector="feature-flag-scope-muted-badge"]:nth-child(2)')).to have_content('production') + end + end + end + end + end + + private + + def set_feature_flag_info(name, description) + fill_in 'Name', with: name + fill_in 'Description', with: description + end + + def environment_plus_button + find('.js-new-environments-dropdown') + end + + def environment_search_input + find('.js-new-environments-dropdown input') + end + + def environment_search_results + all('.js-new-environments-dropdown button.dropdown-item') + end +end diff --git a/spec/features/projects/feature_flags/user_deletes_feature_flag_spec.rb b/spec/features/projects/feature_flags/user_deletes_feature_flag_spec.rb new file mode 100644 index 00000000000..581709aacee --- /dev/null +++ b/spec/features/projects/feature_flags/user_deletes_feature_flag_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User deletes feature flag', :js do + include FeatureFlagHelpers + + let(:user) { create(:user) } + let(:project) { create(:project, namespace: user.namespace) } + + let!(:feature_flag) do + create_flag(project, 'ci_live_trace', false, + description: 'For live trace feature') + end + + before do + project.add_developer(user) + stub_feature_flags(feature_flag_permissions: false) + sign_in(user) + + visit(project_feature_flags_path(project)) + + find('.js-feature-flag-delete-button').click + click_button('Delete feature flag') + expect(page).to have_current_path(project_feature_flags_path(project)) + end + + it 'user does not see feature flag' do + expect(page).to have_no_content('ci_live_trace') + end +end diff --git a/spec/features/projects/feature_flags/user_sees_feature_flag_list_spec.rb b/spec/features/projects/feature_flags/user_sees_feature_flag_list_spec.rb new file mode 100644 index 00000000000..750f4dc5ef4 --- /dev/null +++ b/spec/features/projects/feature_flags/user_sees_feature_flag_list_spec.rb @@ -0,0 +1,147 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User sees feature flag list', :js do + include FeatureFlagHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, namespace: user.namespace) } + + before_all do + project.add_developer(user) + end + + before do + sign_in(user) + end + + context 'with legacy feature flags' do + before do + create_flag(project, 'ci_live_trace', false).tap do |feature_flag| + create_scope(feature_flag, 'review/*', true) + end + create_flag(project, 'drop_legacy_artifacts', false) + create_flag(project, 'mr_train', true).tap do |feature_flag| + create_scope(feature_flag, 'production', false) + end + stub_feature_flags(feature_flags_legacy_read_only_override: false) + end + + it 'user sees the first flag' do + visit(project_feature_flags_path(project)) + + within_feature_flag_row(1) do + expect(page.find('.js-feature-flag-id')).to have_content('^1') + expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') + expect_status_toggle_button_not_to_be_checked + + within_feature_flag_scopes do + expect(page.find('[data-qa-selector="feature-flag-scope-muted-badge"]:nth-child(1)')).to have_content('*') + expect(page.find('[data-qa-selector="feature-flag-scope-info-badge"]:nth-child(2)')).to have_content('review/*') + end + end + end + + it 'user sees the second flag' do + visit(project_feature_flags_path(project)) + + within_feature_flag_row(2) do + expect(page.find('.js-feature-flag-id')).to have_content('^2') + expect(page.find('.feature-flag-name')).to have_content('drop_legacy_artifacts') + expect_status_toggle_button_not_to_be_checked + + within_feature_flag_scopes do + expect(page.find('[data-qa-selector="feature-flag-scope-muted-badge"]:nth-child(1)')).to have_content('*') + end + end + end + + it 'user sees the third flag' do + visit(project_feature_flags_path(project)) + + within_feature_flag_row(3) do + expect(page.find('.js-feature-flag-id')).to have_content('^3') + expect(page.find('.feature-flag-name')).to have_content('mr_train') + expect_status_toggle_button_to_be_checked + + within_feature_flag_scopes do + expect(page.find('[data-qa-selector="feature-flag-scope-info-badge"]:nth-child(1)')).to have_content('*') + expect(page.find('[data-qa-selector="feature-flag-scope-muted-badge"]:nth-child(2)')).to have_content('production') + end + end + end + + it 'user sees the status toggle disabled' do + visit(project_feature_flags_path(project)) + + within_feature_flag_row(1) do + expect_status_toggle_button_to_be_disabled + end + end + + context 'when legacy feature flags are not read-only' do + before do + stub_feature_flags(feature_flags_legacy_read_only: false) + end + + it 'user updates the status toggle' do + visit(project_feature_flags_path(project)) + + within_feature_flag_row(1) do + status_toggle_button.click + + expect_status_toggle_button_to_be_checked + end + end + end + + context 'when legacy feature flags are read-only but the override is active for a project' do + before do + stub_feature_flags( + feature_flags_legacy_read_only: true, + feature_flags_legacy_read_only_override: project + ) + end + + it 'user updates the status toggle' do + visit(project_feature_flags_path(project)) + + within_feature_flag_row(1) do + status_toggle_button.click + + expect_status_toggle_button_to_be_checked + end + end + end + end + + context 'with new version flags' do + before do + create(:operations_feature_flag, :new_version_flag, project: project, + name: 'my_flag', active: false) + end + + it 'user updates the status toggle' do + visit(project_feature_flags_path(project)) + + within_feature_flag_row(1) do + status_toggle_button.click + + expect_status_toggle_button_to_be_checked + end + end + end + + context 'when there are no feature flags' do + before do + visit(project_feature_flags_path(project)) + end + + it 'shows empty page' do + expect(page).to have_text 'Get started with feature flags' + expect(page).to have_selector('.btn-success', text: 'New feature flag') + expect(page).to have_selector('[data-qa-selector="configure_feature_flags_button"]', text: 'Configure') + end + end +end diff --git a/spec/features/projects/feature_flags/user_updates_feature_flag_spec.rb b/spec/features/projects/feature_flags/user_updates_feature_flag_spec.rb new file mode 100644 index 00000000000..bc2d63e1953 --- /dev/null +++ b/spec/features/projects/feature_flags/user_updates_feature_flag_spec.rb @@ -0,0 +1,195 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'User updates feature flag', :js do + include FeatureFlagHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, namespace: user.namespace) } + + before_all do + project.add_developer(user) + end + + before do + stub_feature_flags( + feature_flag_permissions: false, + feature_flags_legacy_read_only_override: false + ) + sign_in(user) + end + + context 'with a new version feature flag' do + let!(:feature_flag) do + create_flag(project, 'test_flag', false, version: Operations::FeatureFlag.versions['new_version_flag'], + description: 'For testing') + end + + let!(:strategy) do + create(:operations_strategy, feature_flag: feature_flag, + name: 'default', parameters: {}) + end + + let!(:scope) do + create(:operations_scope, strategy: strategy, environment_scope: '*') + end + + it 'user adds a second strategy' do + visit(edit_project_feature_flag_path(project, feature_flag)) + + wait_for_requests + + click_button 'Add strategy' + within_strategy_row(2) do + select 'Percent of users', from: 'Type' + fill_in 'Percentage', with: '15' + end + click_button 'Save changes' + + edit_feature_flag_button.click + + within_strategy_row(1) do + expect(page).to have_text 'All users' + expect(page).to have_text 'All environments' + end + within_strategy_row(2) do + expect(page).to have_text 'Percent of users' + expect(page).to have_field 'Percentage', with: '15' + expect(page).to have_text 'All environments' + end + end + + it 'user toggles the flag on' do + visit(edit_project_feature_flag_path(project, feature_flag)) + status_toggle_button.click + click_button 'Save changes' + + within_feature_flag_row(1) do + expect_status_toggle_button_to_be_checked + end + end + end + + context 'with a legacy feature flag' do + let!(:feature_flag) do + create_flag(project, 'ci_live_trace', true, + description: 'For live trace feature') + end + + let!(:scope) { create_scope(feature_flag, 'review/*', true) } + + context 'when legacy flags are editable' do + before do + stub_feature_flags(feature_flags_legacy_read_only: false) + + visit(edit_project_feature_flag_path(project, feature_flag)) + end + + it 'user sees persisted default scope' do + within_scope_row(1) do + within_environment_spec do + expect(page).to have_content('* (All Environments)') + end + + within_status do + expect(find('.project-feature-toggle')['aria-label']) + .to eq('Toggle Status: ON') + end + end + end + + context 'when user updates the status of a scope' do + before do + within_scope_row(2) do + within_status { find('.project-feature-toggle').click } + end + + click_button 'Save changes' + expect(page).to have_current_path(project_feature_flags_path(project)) + end + + it 'shows the updated feature flag' do + within_feature_flag_row(1) do + expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') + expect_status_toggle_button_to_be_checked + + within_feature_flag_scopes do + expect(page.find('.badge:nth-child(1)')).to have_content('*') + expect(page.find('.badge:nth-child(1)')['class']).to include('badge-info') + expect(page.find('.badge:nth-child(2)')).to have_content('review/*') + expect(page.find('.badge:nth-child(2)')['class']).to include('badge-muted') + end + end + end + end + + context 'when user adds a new scope' do + before do + within_scope_row(3) do + within_environment_spec do + find('.js-env-search > input').set('production') + find('.js-create-button').click + end + end + + click_button 'Save changes' + expect(page).to have_current_path(project_feature_flags_path(project)) + end + + it 'shows the newly created scope' do + within_feature_flag_row(1) do + within_feature_flag_scopes do + expect(page.find('.badge:nth-child(3)')).to have_content('production') + expect(page.find('.badge:nth-child(3)')['class']).to include('badge-muted') + end + end + end + end + + context 'when user deletes a scope' do + before do + within_scope_row(2) do + within_delete { find('.js-delete-scope').click } + end + + click_button 'Save changes' + expect(page).to have_current_path(project_feature_flags_path(project)) + end + + it 'shows the updated feature flag' do + within_feature_flag_row(1) do + within_feature_flag_scopes do + expect(page).to have_css('.badge:nth-child(1)') + expect(page).not_to have_css('.badge:nth-child(2)') + end + end + end + end + end + + context 'when legacy flags are read-only' do + it 'the user cannot edit the flag' do + visit(edit_project_feature_flag_path(project, feature_flag)) + + expect(page).to have_text 'This feature flag is read-only, and it will be removed in 14.0.' + expect(page).to have_css('button.js-ff-submit.disabled') + end + end + + context 'when legacy flags are read-only, but the override is active for one project' do + it 'the user can edit the flag' do + stub_feature_flags(feature_flags_legacy_read_only_override: project) + + visit(edit_project_feature_flag_path(project, feature_flag)) + status_toggle_button.click + click_button 'Save changes' + + expect(page).to have_current_path(project_feature_flags_path(project)) + within_feature_flag_row(1) do + expect_status_toggle_button_not_to_be_checked + end + end + end + end +end diff --git a/spec/features/projects/releases/user_views_edit_release_spec.rb b/spec/features/projects/releases/user_views_edit_release_spec.rb index 2028902f10f..9115a135aeb 100644 --- a/spec/features/projects/releases/user_views_edit_release_spec.rb +++ b/spec/features/projects/releases/user_views_edit_release_spec.rb @@ -39,7 +39,7 @@ RSpec.describe 'User edits Release', :js do it 'renders the edit Release form' do expect(page).to have_content('Releases are based on Git tags. We recommend tags that use semantic versioning, for example v1.0, v2.0-pre.') - expect(find_field('Tag name', { disabled: true }).value).to eq(release.tag) + expect(find_field('Tag name', disabled: true).value).to eq(release.tag) expect(find_field('Release title').value).to eq(release.name) expect(find_field('Release notes').value).to eq(release.description) |