diff options
Diffstat (limited to 'spec/support/shared_examples/features')
10 files changed, 122 insertions, 127 deletions
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 6bfb60c3f34..d0b2d0c9cae 100644 --- a/spec/support/shared_examples/features/content_editor_shared_examples.rb +++ b/spec/support/shared_examples/features/content_editor_shared_examples.rb @@ -449,6 +449,9 @@ RSpec.shared_examples 'edits content using the content editor' do |params = { before do switch_to_content_editor + type_in_content_editor [modifier_key, 'a'] + type_in_content_editor :delete + type_in_content_editor "Some **rich** _text_ ~~content~~ [link](https://gitlab.com)" type_in_content_editor [modifier_key, 'a'] @@ -488,6 +491,26 @@ RSpec.shared_examples 'edits content using the content editor' do |params = { end end + it 'pastes raw markdown with formatting when pasting inside a markdown code block' do + type_in_content_editor '```md' + type_in_content_editor :enter + type_in_content_editor [modifier_key, 'v'] + + page.within content_editor_testid do + expect(page).to have_selector('pre', text: 'Some **rich** _text_ ~~content~~ [link](https://gitlab.com)') + end + end + + it 'pastes raw markdown without formatting when pasting inside a plaintext code block' do + type_in_content_editor '```' + type_in_content_editor :enter + type_in_content_editor [modifier_key, 'v'] + + page.within content_editor_testid do + expect(page).to have_selector('pre', text: 'Some rich text content link') + end + end + it 'pastes raw text without formatting, stripping whitespaces, if shift + ctrl + v is pressed' do type_in_content_editor " Some **rich**" type_in_content_editor :enter @@ -570,7 +593,7 @@ RSpec.shared_examples 'edits content using the content editor' do |params = { type_in_content_editor '/assign' expect(find(suggestions_dropdown)).to have_text('/assign') - send_keys [:arrow_down, :enter] + send_keys :enter expect(page).to have_text('/assign @') end @@ -579,7 +602,7 @@ RSpec.shared_examples 'edits content using the content editor' do |params = { type_in_content_editor '/label' expect(find(suggestions_dropdown)).to have_text('/label') - send_keys [:arrow_down, :enter] + send_keys :enter expect(page).to have_text('/label ~') end @@ -588,10 +611,23 @@ RSpec.shared_examples 'edits content using the content editor' do |params = { type_in_content_editor '/milestone' expect(find(suggestions_dropdown)).to have_text('/milestone') - send_keys [:arrow_down, :enter] + send_keys :enter expect(page).to have_text('/milestone %') end + + it 'scrolls selected item into view when navigating with keyboard' do + type_in_content_editor '/' + + expect(find(suggestions_dropdown)).to have_text('label') + + expect(dropdown_scroll_top).to be 0 + + send_keys :arrow_up + + expect(dropdown_scroll_top).to be > 100 + end + end it 'shows suggestions for members with descriptions' do @@ -603,7 +639,18 @@ RSpec.shared_examples 'edits content using the content editor' do |params = { type_in_content_editor 'bc' - send_keys [:arrow_down, :enter] + send_keys :enter + + expect(page).not_to have_css(suggestions_dropdown) + expect(page).to have_text('@abc123') + end + + it 'allows selecting element with tab key' do + type_in_content_editor '@abc' + + expect(find(suggestions_dropdown)).to have_text('abc123') + + send_keys :tab expect(page).not_to have_css(suggestions_dropdown) expect(page).to have_text('@abc123') @@ -701,11 +748,11 @@ RSpec.shared_examples 'edits content using the content editor' do |params = { expect(find(suggestions_dropdown)).to have_text('😃 smiley') expect(find(suggestions_dropdown)).to have_text('😸 smile_cat') - send_keys [:arrow_down, :enter] + send_keys :enter expect(page).not_to have_css(suggestions_dropdown) - expect(page).to have_text('😃') + expect(page).to have_text('😄') end it 'doesn\'t show suggestions dropdown if there are no suggestions to show' do @@ -718,18 +765,6 @@ RSpec.shared_examples 'edits content using the content editor' do |params = { expect(page).not_to have_css(suggestions_dropdown) end - it 'scrolls selected item into view when navigating with keyboard' do - type_in_content_editor ':' - - expect(find(suggestions_dropdown)).to have_text('grinning') - - expect(dropdown_scroll_top).to be 0 - - send_keys :arrow_up - - expect(dropdown_scroll_top).to be > 100 - end - def dropdown_scroll_top evaluate_script("document.querySelector('#{suggestions_dropdown}').scrollTop") end diff --git a/spec/support/shared_examples/features/editable_merge_request_shared_examples.rb b/spec/support/shared_examples/features/editable_merge_request_shared_examples.rb index 9f884683f47..1bee8184e61 100644 --- a/spec/support/shared_examples/features/editable_merge_request_shared_examples.rb +++ b/spec/support/shared_examples/features/editable_merge_request_shared_examples.rb @@ -54,6 +54,8 @@ RSpec.shared_examples 'an editable merge request' do page.within '.labels' do expect(page).to have_content label.title expect(page).to have_content label2.title + + expect(page).to have_selector("[data-testid='close-icon']", count: 1) end end end diff --git a/spec/support/shared_examples/features/integrations/user_activates_mattermost_slash_command_integration_shared_examples.rb b/spec/support/shared_examples/features/integrations/user_activates_mattermost_slash_command_integration_shared_examples.rb index 148ff2cfb54..5fdd91ebd2d 100644 --- a/spec/support/shared_examples/features/integrations/user_activates_mattermost_slash_command_integration_shared_examples.rb +++ b/spec/support/shared_examples/features/integrations/user_activates_mattermost_slash_command_integration_shared_examples.rb @@ -6,7 +6,7 @@ RSpec.shared_examples 'user activates the Mattermost Slash Command integration' end it 'shows a token placeholder' do - token_placeholder = find_field('service_token')['placeholder'] + token_placeholder = find_field('service-token')['placeholder'] expect(token_placeholder).to eq('') end @@ -14,7 +14,7 @@ RSpec.shared_examples 'user activates the Mattermost Slash Command integration' it 'redirects to the integrations page after saving but not activating' do token = ('a'..'z').to_a.join - fill_in 'service_token', with: token + fill_in 'service-token', with: token click_active_checkbox click_save_integration @@ -25,7 +25,7 @@ RSpec.shared_examples 'user activates the Mattermost Slash Command integration' it 'redirects to the integrations page after activating' do token = ('a'..'z').to_a.join - fill_in 'service_token', with: token + fill_in 'service-token', with: token click_save_integration expect(page).to have_current_path(edit_path, ignore_query: true) 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 178f85cb85b..b479d71b274 100644 --- a/spec/support/shared_examples/features/inviting_members_shared_examples.rb +++ b/spec/support/shared_examples/features/inviting_members_shared_examples.rb @@ -181,6 +181,7 @@ RSpec.shared_examples 'inviting members' do |snowplow_invite_label| visit subentity_members_page_path click_on _('Invite members') + wait_for_requests page.within invite_modal_selector do choose_options(role, nil) diff --git a/spec/support/shared_examples/features/runners_shared_examples.rb b/spec/support/shared_examples/features/runners_shared_examples.rb index 861c205337a..8e1e2b10bef 100644 --- a/spec/support/shared_examples/features/runners_shared_examples.rb +++ b/spec/support/shared_examples/features/runners_shared_examples.rb @@ -4,67 +4,41 @@ RSpec.shared_examples 'shows and resets runner registration token' do include Features::RunnersHelpers include Spec::Support::Helpers::ModalHelpers - before do + it 'shows registration instructions' do click_on dropdown_text - end - - describe 'shows registration instructions' do - before do - click_on 'Show runner installation and registration instructions' - - wait_for_requests - end - - it 'opens runner installation modal', :aggregate_failures do - within_modal do - expect(page).to have_text "Install a runner" - expect(page).to have_text "Environment" - expect(page).to have_text "Architecture" - expect(page).to have_text "Download and install binary" - end - end - - it 'dismisses runner installation modal' do - within_modal do - click_button('Close', match: :first) - end + click_on 'Show runner installation and registration instructions' - expect(page).not_to have_text "Install a runner" + within_modal do + expect(page).to have_text "Install a runner" + expect(page).to have_text "Environment" + expect(page).to have_text "Architecture" + expect(page).to have_text "Download and install binary" end end - it 'has a registration token' do + it 'resets current registration token' do + click_on dropdown_text click_on 'Click to reveal' - expect(page.find_field('token-value').value).to have_content(registration_token) - end - describe 'reset registration token' do - let!(:old_registration_token) { find_field('token-value').value } + # current registration token + expect(page.find_field('token-value').value).to eq(registration_token) - before do - click_on 'Reset registration token' - - within_modal do - click_button('Reset token', match: :first) - end - - wait_for_requests + # reset registration token + click_on 'Reset registration token' + within_modal do + click_button('Reset token', match: :first) end - it 'changes registration token' do - expect(find('.gl-toast')).to have_content('New registration token generated!') - - click_on dropdown_text - click_on 'Click to reveal' - - expect(find_field('token-value').value).not_to eq old_registration_token - end + # new registration token + click_on dropdown_text + expect(find_field('token-value').value).not_to eq(registration_token) + expect(find('.gl-toast')).to have_content('New registration token generated!') end end RSpec.shared_examples 'shows no runners registered' do it 'shows 0 count and the empty state' do - expect(find('[data-testid="runner-type-tabs"]')).to have_text "#{s_('Runners|All')} 0" + expect(find('[data-testid="runner-type-tabs"]')).to have_text "All 0" # No stats are shown expect(page).not_to have_text s_('Runners|Online') @@ -82,22 +56,19 @@ RSpec.shared_examples 'shows no runners found' do end end -RSpec.shared_examples 'shows runner in list' do - it 'shows runner row and no empty state' do +RSpec.shared_examples 'shows runner summary and navigates to details' do + it 'shows runner summary and details' do + expect(page).not_to have_content s_('Runners|Get started with runners') + + # see runner summary in list within_runner_row(runner.id) do expect(page).to have_text "##{runner.id}" expect(page).to have_text runner.short_sha expect(page).to have_text runner.description end - expect(page).not_to have_content s_('Runners|Get started with runners') - end -end - -RSpec.shared_examples 'shows runner details from list' do - it 'shows runner details page' do + # navigate to see runner details click_link("##{runner.id} (#{runner.short_sha})") - expect(current_url).to include(runner_page_path) expect(page).to have_selector 'h1', text: "##{runner.id} (#{runner.short_sha})" @@ -131,12 +102,10 @@ RSpec.shared_examples 'pauses, resumes and deletes a runner' do end end - it 'shows a confirmation modal' do + it 'confirms runner deletion' do expect(page).to have_text "Delete runner ##{runner.id} (#{runner.short_sha})?" expect(page).to have_text "Are you sure you want to continue?" - end - it 'deletes a runner' do within_modal do click_on 'Permanently delete runner' end @@ -150,8 +119,6 @@ RSpec.shared_examples 'pauses, resumes and deletes a runner' do click_on 'Cancel' end - wait_for_requests - expect(page).to have_content runner.description end end @@ -166,8 +133,6 @@ RSpec.shared_examples 'deletes runners in bulk' do within_modal do click_on "Permanently delete #{runner_count} runners" end - - wait_for_requests end it_behaves_like 'shows no runners registered' @@ -187,17 +152,11 @@ RSpec.shared_examples 'filters by tag' do end RSpec.shared_examples 'shows runner jobs tab' do - context 'when clicking on jobs tab' do - before do - click_on("#{s_('Runners|Jobs')} #{job_count}") + it 'show jobs in tab' do + click_on("#{s_('Runners|Jobs')} #{job_count}") - wait_for_requests - end - - it 'shows job in list' do - within "[data-testid='job-row-#{job.id}']" do - expect(page).to have_link("##{job.id}") - end + within "[data-testid='job-row-#{job.id}']" do + expect(page).to have_link("##{job.id}") end end end @@ -217,29 +176,17 @@ RSpec.shared_examples 'submits edit runner form' do end end - describe 'runner header', :js do - it 'contains the runner id' do - expect(page).to have_content("##{runner.id} (#{runner.short_sha})") - end - end - context 'when a runner is updated', :js do before do - fill_in s_('Runners|Runner description'), with: 'new-runner-description' + fill_in s_('Runners|Runner description'), with: 'new-runner-description', fill_options: { clear: :backspace } click_on _('Save changes') - wait_for_requests end - it 'redirects to runner page' do + it 'redirects to runner page and shows succesful update' do expect(current_url).to match(runner_page_path) - end - it 'show success alert' do expect(page.find('[data-testid="alert-success"]')).to have_content('saved') - end - - it 'shows updated information' do expect(page).to have_content("#{s_('Runners|Description')} new-runner-description") end end @@ -251,7 +198,6 @@ RSpec.shared_examples 'creates runner and shows register page' do fill_in s_('Runners|Runner description'), with: 'runner-foo' fill_in s_('Runners|Tags'), with: 'tag1' click_on s_('Runners|Create runner') - wait_for_requests end it 'navigates to registration page and opens install instructions drawer' do diff --git a/spec/support/shared_examples/features/variable_list_drawer_shared_examples.rb b/spec/support/shared_examples/features/variable_list_drawer_shared_examples.rb index b438a23aafd..04e73cfeee7 100644 --- a/spec/support/shared_examples/features/variable_list_drawer_shared_examples.rb +++ b/spec/support/shared_examples/features/variable_list_drawer_shared_examples.rb @@ -140,7 +140,10 @@ RSpec.shared_examples 'variable list drawer' do toggle_masked fill_variable('EMPTY_MASK_KEY', '???') - expect(page).to have_content('This variable value does not meet the masking requirements.') + # rubocop:disable Layout/LineLength -- error message is too long + expect(page).to have_content('This value cannot be masked because it contains the following characters: ?. The value must have at least 8 characters.') + # rubocop:enable Layout/LineLength + page.within('[data-testid="ci-variable-drawer"]') do expect(find_button('Add variable', disabled: true)).to be_present end diff --git a/spec/support/shared_examples/features/wiki/user_deletes_wiki_page_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_deletes_wiki_page_shared_examples.rb index 55c89977a99..9e6002f2958 100644 --- a/spec/support/shared_examples/features/wiki/user_deletes_wiki_page_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_deletes_wiki_page_shared_examples.rb @@ -22,7 +22,7 @@ RSpec.shared_examples 'User deletes wiki page' do specify 'deletes a page', :js do click_on('Edit') click_on('Delete') - find('[data-testid="confirm_deletion_button"]').click + find('[data-testid="confirm-deletion-button"]').click expect(page).to have_content('Wiki page was successfully deleted.') 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 a48ff8a5f77..09444084eb9 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 @@ -25,7 +25,7 @@ RSpec.shared_examples 'User updates wiki page' do end it 'redirects back to the home edit page' do - page.within(:css, '.wiki-form .form-actions') do + page.within(:css, '[data-testid="wiki-form-actions"]') do click_on('Cancel') end @@ -128,7 +128,7 @@ RSpec.shared_examples 'User updates wiki page' do end it 'cancels editing of a page' do - page.within(:css, '.wiki-form .form-actions') do + page.within(:css, '[data-testid="wiki-form-actions"]') do click_on('Cancel') end diff --git a/spec/support/shared_examples/features/wiki/user_views_wiki_page_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_views_wiki_page_shared_examples.rb index 3fac7e7093c..c6454f62f34 100644 --- a/spec/support/shared_examples/features/wiki/user_views_wiki_page_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_views_wiki_page_shared_examples.rb @@ -16,6 +16,10 @@ RSpec.shared_examples 'User views a wiki page' do ) end + let(:more_actions_dropdown) do + find('[data-testid="wiki-more-dropdown"] button') + end + before do sign_in(user) end @@ -38,10 +42,12 @@ RSpec.shared_examples 'User views a wiki page' do expect(page).to have_content('Wiki page was successfully created.') end - it 'shows the history of a page that has a path' do + it 'shows the history of a page that has a path', :js do expect(page).to have_current_path(%r{one/two/three-test}) first(:link, text: 'three').click + + more_actions_dropdown.click click_on('Page history') expect(page).to have_current_path(%r{one/two/three-test}) @@ -69,6 +75,7 @@ RSpec.shared_examples 'User views a wiki page' do expect(page).to have_content('Wiki page was successfully updated.') + more_actions_dropdown.click click_on('Page history') within('.wiki-page-header') do @@ -119,11 +126,12 @@ RSpec.shared_examples 'User views a wiki page' do wiki_page.update(message: 'updated home', content: 'updated [some link](other-page)') # rubocop:disable Rails/SaveBang end - it 'shows the page history' do + it 'shows the page history', :js do visit(wiki_page_path(wiki, wiki_page)) expect(page).to have_selector('[data-testid="wiki-edit-button"]') + more_actions_dropdown.click click_on('Page history') expect(page).to have_content(user.name) diff --git a/spec/support/shared_examples/features/work_items_shared_examples.rb b/spec/support/shared_examples/features/work_items_shared_examples.rb index 30605c81312..3dfd7604914 100644 --- a/spec/support/shared_examples/features/work_items_shared_examples.rb +++ b/spec/support/shared_examples/features/work_items_shared_examples.rb @@ -495,30 +495,30 @@ end RSpec.shared_examples 'work items parent' do |type| let(:work_item_parent) { create(:work_item, type, project: project) } - def set_parent(parent_dropdown, parent_text) - parent_dropdown.click - + def set_parent(parent_text) find('[data-testid="listbox-search-input"] .gl-listbox-search-input', visible: true).send_keys "\"#{parent_text}\"" wait_for_requests - find('.gl-new-dropdown-item').click - wait_for_requests + find('.gl-new-dropdown-item', text: parent_text).click + wait_for_all_requests end - let(:parent_dropdown_selector) { 'work-item-parent-listbox' } - it 'searches and sets or removes parent for the work item' do + find_by_testid('edit-parent').click within_testid('work-item-parent-form') do - set_parent(find_by_testid(parent_dropdown_selector), work_item_parent.title) + set_parent(work_item_parent.title) + end - expect(find_by_testid(parent_dropdown_selector)).to have_text(work_item_parent.title) + expect(find_by_testid('work-item-parent-link')).to have_text(work_item_parent.title) + wait_for_requests - find_by_testid(parent_dropdown_selector).click + page.refresh + find_by_testid('edit-parent').click - click_button('Unassign') + click_button('Unassign') + wait_for_requests - expect(find_by_testid(parent_dropdown_selector)).to have_text('None') - end + expect(find_by_testid('work-item-parent-none')).to have_text('None') end end |