diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /spec/support/shared_examples/features | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/support/shared_examples/features')
10 files changed, 197 insertions, 41 deletions
diff --git a/spec/support/shared_examples/features/access_tokens_shared_examples.rb b/spec/support/shared_examples/features/access_tokens_shared_examples.rb index c162ed36881..0fc45b154d8 100644 --- a/spec/support/shared_examples/features/access_tokens_shared_examples.rb +++ b/spec/support/shared_examples/features/access_tokens_shared_examples.rb @@ -38,7 +38,7 @@ RSpec.shared_examples 'resource access tokens creation' do |resource_type| expect(active_resource_access_tokens).to have_text('in') expect(active_resource_access_tokens).to have_text('read_api') expect(active_resource_access_tokens).to have_text('read_repository') - expect(active_resource_access_tokens).to have_text('Maintainer') + expect(active_resource_access_tokens).to have_text('Guest') expect(created_resource_access_token).not_to be_empty end end diff --git a/spec/support/shared_examples/features/content_editor_shared_examples.rb b/spec/support/shared_examples/features/content_editor_shared_examples.rb index 0ea82f37db0..3fa7beea97e 100644 --- a/spec/support/shared_examples/features/content_editor_shared_examples.rb +++ b/spec/support/shared_examples/features/content_editor_shared_examples.rb @@ -13,9 +13,8 @@ RSpec.shared_examples 'edits content using the content editor' do expect(page).to have_css('[data-testid="formatting-bubble-menu"]') end - it 'does not show a formatting bubble menu for code' do - find(content_editor_testid).send_keys 'This is a `code`' - find(content_editor_testid).send_keys [:shift, :left] + it 'does not show a formatting bubble menu for code blocks' do + find(content_editor_testid).send_keys '```js ' expect(page).not_to have_css('[data-testid="formatting-bubble-menu"]') end diff --git a/spec/support/shared_examples/features/inviting_members_shared_examples.rb b/spec/support/shared_examples/features/inviting_members_shared_examples.rb index bca0e02fcdd..277ec6a7fa7 100644 --- a/spec/support/shared_examples/features/inviting_members_shared_examples.rb +++ b/spec/support/shared_examples/features/inviting_members_shared_examples.rb @@ -147,9 +147,9 @@ RSpec.shared_examples 'inviting members' do |snowplow_invite_label| invite_member(user2.name, role: role, refresh: false) - expect(page).to have_selector(invite_modal_selector) - expect(page).to have_content "#{user2.name}: Access level should be greater than or equal to Developer " \ - "inherited membership from group #{group.name}" + invite_modal = page.find(invite_modal_selector) + expect(invite_modal).to have_content "#{user2.name}: Access level should be greater than or equal to " \ + "Developer inherited membership from group #{group.name}" page.refresh @@ -166,31 +166,85 @@ RSpec.shared_examples 'inviting members' do |snowplow_invite_label| group.add_maintainer(user3) end - it 'shows the user errors and then removes them from the form', :js do - visit subentity_members_page_path + it 'shows the partial user error and success and then removes them from the form', :js do + user4 = create(:user) + user5 = create(:user) + user6 = create(:user) + user7 = create(:user) + + group.add_maintainer(user6) + group.add_maintainer(user7) - invite_member([user2.name, user3.name], role: role, refresh: false) + visit subentity_members_page_path - expect(page).to have_selector(invite_modal_selector) - expect(page).to have_selector(member_token_error_selector(user2.id)) - expect(page).to have_selector(member_token_error_selector(user3.id)) - expect(page).to have_text("The following 2 members couldn't be invited") - expect(page).to have_text("#{user2.name}: Access level should be greater than or equal to") - expect(page).to have_text("#{user3.name}: Access level should be greater than or equal to") + invite_member([user2.name, user3.name, user4.name, user6.name, user7.name], role: role, refresh: false) + + # we have more than 2 errors, so one will be hidden + invite_modal = page.find(invite_modal_selector) + expect(invite_modal).to have_text("The following 4 members couldn't be invited") + expect(invite_modal).to have_selector(limited_invite_error_selector, count: 2, visible: :visible) + expect(invite_modal).to have_selector(expanded_invite_error_selector, count: 2, visible: :hidden) + # unpredictability of return order means we can't rely on message showing in any order here + # so we will not expect on the message + expect_to_have_invalid_invite_indicator(invite_modal, user2, message: false) + expect_to_have_invalid_invite_indicator(invite_modal, user3, message: false) + expect_to_have_invalid_invite_indicator(invite_modal, user6, message: false) + expect_to_have_invalid_invite_indicator(invite_modal, user7, message: false) + expect_to_have_successful_invite_indicator(invite_modal, user4) + expect(invite_modal).to have_button('Show more (2)') + + # now we want to test the show more errors count logic + remove_token(user7.id) + + # count decreases from 4 to 3 and 2 to 1 + expect(invite_modal).to have_text("The following 3 members couldn't be invited") + expect(invite_modal).to have_button('Show more (1)') + + # we want to show this error now for user6 + invite_modal.find(more_invite_errors_button_selector).click + + # now we should see the error for all users and our collapse button text + expect(invite_modal).to have_selector(limited_invite_error_selector, count: 2, visible: :visible) + expect(invite_modal).to have_selector(expanded_invite_error_selector, count: 1, visible: :visible) + expect_to_have_invalid_invite_indicator(invite_modal, user2, message: true) + expect_to_have_invalid_invite_indicator(invite_modal, user3, message: true) + expect_to_have_invalid_invite_indicator(invite_modal, user6, message: true) + expect(invite_modal).to have_button('Show less') + + # adds new token, but doesn't submit + select_members(user5.name) + + expect_to_have_normal_invite_indicator(invite_modal, user5) remove_token(user2.id) - expect(page).not_to have_selector(member_token_error_selector(user2.id)) - expect(page).to have_selector(member_token_error_selector(user3.id)) - expect(page).to have_text("The following member couldn't be invited") - expect(page).not_to have_text("#{user2.name}: Access level should be greater than or equal to") + expect(invite_modal).to have_text("The following 2 members couldn't be invited") + expect(invite_modal).not_to have_selector(more_invite_errors_button_selector) + expect_to_have_invite_removed(invite_modal, user2) + expect_to_have_invalid_invite_indicator(invite_modal, user3) + expect_to_have_invalid_invite_indicator(invite_modal, user6) + expect_to_have_successful_invite_indicator(invite_modal, user4) + expect_to_have_normal_invite_indicator(invite_modal, user5) + + remove_token(user6.id) + + expect(invite_modal).to have_text("The following member couldn't be invited") + expect_to_have_invite_removed(invite_modal, user6) + expect_to_have_invalid_invite_indicator(invite_modal, user3) + expect_to_have_successful_invite_indicator(invite_modal, user4) + expect_to_have_normal_invite_indicator(invite_modal, user5) remove_token(user3.id) - expect(page).not_to have_selector(member_token_error_selector(user3.id)) - expect(page).not_to have_text("The following member couldn't be invited") - expect(page).not_to have_text("Review the invite errors and try again") - expect(page).not_to have_text("#{user3.name}: Access level should be greater than or equal to") + expect(invite_modal).not_to have_text("The following member couldn't be invited") + expect(invite_modal).not_to have_text("Review the invite errors and try again") + expect_to_have_invite_removed(invite_modal, user3) + expect_to_have_successful_invite_indicator(invite_modal, user4) + expect_to_have_normal_invite_indicator(invite_modal, user5) + + submit_invites + + expect(page).not_to have_selector(invite_modal_selector) page.refresh @@ -203,6 +257,10 @@ RSpec.shared_examples 'inviting members' do |snowplow_invite_label| expect(page).to have_content('Maintainer') expect(page).not_to have_button('Maintainer') end + + page.within find_invited_member_row(user4.name) do + expect(page).to have_button(role) + end end it 'only shows the error for an invalid formatted email and does not display other member errors', :js do @@ -210,12 +268,12 @@ RSpec.shared_examples 'inviting members' do |snowplow_invite_label| invite_member([user2.name, user3.name, 'bad@email'], role: role, refresh: false) - expect(page).to have_selector(invite_modal_selector) - expect(page).to have_text('email contains an invalid email address') - expect(page).not_to have_text("The following 2 members couldn't be invited") - expect(page).not_to have_text("Review the invite errors and try again") - expect(page).not_to have_text("#{user2.name}: Access level should be greater than or equal to") - expect(page).not_to have_text("#{user3.name}: Access level should be greater than or equal to") + invite_modal = page.find(invite_modal_selector) + expect(invite_modal).to have_text('email contains an invalid email address') + expect(invite_modal).not_to have_text("The following 2 members couldn't be invited") + expect(invite_modal).not_to have_text("Review the invite errors and try again") + expect(invite_modal).not_to have_text("#{user2.name}: Access level should be greater than or equal to") + expect(invite_modal).not_to have_text("#{user3.name}: Access level should be greater than or equal to") end end end diff --git a/spec/support/shared_examples/features/multiple_assignees_widget_mr_shared_examples.rb b/spec/support/shared_examples/features/multiple_assignees_widget_mr_shared_examples.rb index bbde448a1a1..ef2683d6424 100644 --- a/spec/support/shared_examples/features/multiple_assignees_widget_mr_shared_examples.rb +++ b/spec/support/shared_examples/features/multiple_assignees_widget_mr_shared_examples.rb @@ -32,7 +32,7 @@ RSpec.shared_examples 'multiple assignees widget merge request' do |action, save end page.within '.dropdown-menu-user' do - click_link user.name + click_button user.name end page.within '.issuable-sidebar' do diff --git a/spec/support/shared_examples/features/sidebar/sidebar_due_date_shared_examples.rb b/spec/support/shared_examples/features/sidebar/sidebar_due_date_shared_examples.rb index 345dfbce423..95c0a76d726 100644 --- a/spec/support/shared_examples/features/sidebar/sidebar_due_date_shared_examples.rb +++ b/spec/support/shared_examples/features/sidebar/sidebar_due_date_shared_examples.rb @@ -16,7 +16,9 @@ RSpec.shared_examples 'date sidebar widget' do page.within('[data-testid="sidebar-due-date"]') do today = Date.today.day - click_button 'Edit' + button = find_button('Edit') + scroll_to(button) + button.click click_button today.to_s diff --git a/spec/support/shared_examples/features/trial_email_validation_shared_example.rb b/spec/support/shared_examples/features/trial_email_validation_shared_example.rb new file mode 100644 index 00000000000..8304a91af86 --- /dev/null +++ b/spec/support/shared_examples/features/trial_email_validation_shared_example.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'user email validation' do + let(:email_hint_message) { 'We recommend a work email address.' } + let(:email_error_message) { 'Please provide a valid email address.' } + + let(:email_warning_message) do + 'This email address does not look right, are you sure you typed it correctly?' + end + + context 'with trial_email_validation flag enabled' do + it 'shows an error message until a correct email is entered' do + visit path + expect(page).to have_content(email_hint_message) + expect(page).not_to have_content(email_error_message) + expect(page).not_to have_content(email_warning_message) + + fill_in 'new_user_email', with: 'foo@' + fill_in 'new_user_first_name', with: '' + + expect(page).not_to have_content(email_hint_message) + expect(page).to have_content(email_error_message) + expect(page).not_to have_content(email_warning_message) + + fill_in 'new_user_email', with: 'foo@bar' + fill_in 'new_user_first_name', with: '' + + expect(page).not_to have_content(email_hint_message) + expect(page).not_to have_content(email_error_message) + expect(page).to have_content(email_warning_message) + + fill_in 'new_user_email', with: 'foo@gitlab.com' + fill_in 'new_user_first_name', with: '' + + expect(page).not_to have_content(email_hint_message) + expect(page).not_to have_content(email_error_message) + expect(page).not_to have_content(email_warning_message) + end + end + + context 'when trial_email_validation flag disabled' do + before do + stub_feature_flags trial_email_validation: false + end + + it 'does not show an error message' do + visit path + expect(page).to have_content(email_hint_message) + expect(page).not_to have_content(email_error_message) + expect(page).not_to have_content(email_warning_message) + + fill_in 'new_user_email', with: 'foo@' + + expect(page).to have_content(email_hint_message) + expect(page).not_to have_content(email_error_message) + expect(page).not_to have_content(email_warning_message) + end + end +end diff --git a/spec/support/shared_examples/features/user_views_tag_shared_examples.rb b/spec/support/shared_examples/features/user_views_tag_shared_examples.rb new file mode 100644 index 00000000000..989de1dbfbb --- /dev/null +++ b/spec/support/shared_examples/features/user_views_tag_shared_examples.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'user views tag' do + context 'when user views with the tag' do + let(:project) { create(:project, :repository) } + let(:user) { create(:user) } + let(:tag_name) { "stable" } + let!(:release) { create(:release, project: project, tag: tag_name, name: "ReleaseName") } + + before do + project.add_developer(user) + project.repository.add_tag(user, tag_name, project.default_branch_or_main) + + sign_in(user) + end + + shared_examples 'shows tag' do + it do + visit tag_page + + expect(page).to have_content tag_name + expect(page).to have_link("ReleaseName", href: project_release_path(project, release)) + end + end + + it_behaves_like 'shows tag' + + context 'when tag name contains a slash' do + let(:tag_name) { "stable/v0.1" } + + it_behaves_like 'shows tag' + end + end +end diff --git a/spec/support/shared_examples/features/variable_list_shared_examples.rb b/spec/support/shared_examples/features/variable_list_shared_examples.rb index c63faace6b2..9d81c0e9a3e 100644 --- a/spec/support/shared_examples/features/variable_list_shared_examples.rb +++ b/spec/support/shared_examples/features/variable_list_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.shared_examples 'variable list' do +RSpec.shared_examples 'variable list' do |is_admin| it 'shows a list of variables' do page.within('[data-testid="ci-variable-table"]') do expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq(variable.key) @@ -166,7 +166,7 @@ RSpec.shared_examples 'variable list' do wait_for_requests expect(find('.flash-container')).to be_present - expect(find('[data-testid="alert-danger"]').text).to have_content('Variables key (key) has already been taken') + expect(find('[data-testid="alert-danger"]').text).to have_content('(key) has already been taken') end it 'prevents a variable to be added if no values are provided when a variable is set to masked' do @@ -257,7 +257,11 @@ RSpec.shared_examples 'variable list' do end it 'shows a message regarding the changed default' do - expect(page).to have_content 'Environment variables are configured by your administrator to be protected by default' + if is_admin + expect(page).to have_content 'Environment variables on this GitLab instance are configured to be protected by default' + else + expect(page).to have_content 'Environment variables are configured by your administrator to be protected by default' + end end end diff --git a/spec/support/shared_examples/features/wiki/file_attachments_shared_examples.rb b/spec/support/shared_examples/features/wiki/file_attachments_shared_examples.rb index 0ef1ccdfe57..8d1502bed84 100644 --- a/spec/support/shared_examples/features/wiki/file_attachments_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/file_attachments_shared_examples.rb @@ -12,8 +12,8 @@ RSpec.shared_examples 'wiki file attachments' do end context 'before uploading' do - it 'shows "Attach a file" button' do - expect(page).to have_button('Attach a file') + it 'shows "Attach a file or image" button' do + expect(page).to have_selector('[data-testid="button-attach-file"]') expect(page).not_to have_selector('.uploading-progress-container', visible: true) end end @@ -26,7 +26,7 @@ RSpec.shared_examples 'wiki file attachments' do click_button 'Cancel' end - expect(page).to have_button('Attach a file') + expect(page).to have_selector('[data-testid="button-attach-file"]') expect(page).not_to have_button('Cancel') expect(page).not_to have_selector('.uploading-progress-container', visible: true) end @@ -41,11 +41,11 @@ RSpec.shared_examples 'wiki file attachments' do end context 'uploading is complete' do - it 'shows "Attach a file" button on uploading complete' do + it 'shows "Attach a file or image" button on uploading complete' do attach_with_dropzone wait_for_requests - expect(page).to have_button('Attach a file') + expect(page).to have_selector('[data-testid="button-attach-file"]') expect(page).not_to have_selector('.uploading-progress-container', visible: true) end diff --git a/spec/support/shared_examples/features/wiki/user_updates_wiki_page_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_updates_wiki_page_shared_examples.rb index 79c7c1891ac..87067336a36 100644 --- a/spec/support/shared_examples/features/wiki/user_updates_wiki_page_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_updates_wiki_page_shared_examples.rb @@ -140,7 +140,7 @@ RSpec.shared_examples 'User updates wiki page' do context 'when using the content editor' do context 'with feature flag on' do before do - click_button 'Edit rich text' + find('[data-testid="toggle-editing-mode-button"] label', text: 'Rich text').click end it_behaves_like 'edits content using the content editor' |