diff options
Diffstat (limited to 'spec/support/shared_examples/features')
14 files changed, 302 insertions, 46 deletions
diff --git a/spec/support/shared_examples/features/cascading_settings_shared_examples.rb b/spec/support/shared_examples/features/cascading_settings_shared_examples.rb new file mode 100644 index 00000000000..29ef3da9a85 --- /dev/null +++ b/spec/support/shared_examples/features/cascading_settings_shared_examples.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'a cascading setting' do + context 'when setting is enforced by an ancestor group' do + before do + visit group_path + + page.within form_group_selector do + find(setting_field_selector).check + find('[data-testid="enforce-for-all-subgroups-checkbox"]').check + end + + click_save_button + end + + it 'disables setting in subgroups' do + visit subgroup_path + + expect(find("#{setting_field_selector}[disabled]")).to be_checked + end + + it 'does not show enforcement checkbox in subgroups' do + visit subgroup_path + + expect(page).not_to have_selector '[data-testid="enforce-for-all-subgroups-checkbox"]' + end + + it 'displays lock icon with popover', :js do + visit subgroup_path + + page.within form_group_selector do + find('[data-testid="cascading-settings-lock-icon"]').click + end + + page.within '[data-testid="cascading-settings-lock-popover"]' do + expect(page).to have_text 'This setting has been enforced by an owner of Foo bar.' + expect(page).to have_link 'Foo bar', href: setting_path + end + end + end +end diff --git a/spec/support/shared_examples/features/creatable_merge_request_shared_examples.rb b/spec/support/shared_examples/features/creatable_merge_request_shared_examples.rb index da966fd2200..1c816ee4b0a 100644 --- a/spec/support/shared_examples/features/creatable_merge_request_shared_examples.rb +++ b/spec/support/shared_examples/features/creatable_merge_request_shared_examples.rb @@ -43,7 +43,7 @@ RSpec.shared_examples 'a creatable merge request' do expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[1].value).to match(label.id.to_s) expect(page.all('input[name="merge_request[label_ids][]"]', visible: false)[2].value).to match(label2.id.to_s) - click_button 'Submit merge request' + click_button 'Create merge request' page.within '.issuable-sidebar' do page.within '.assignee' do diff --git a/spec/support/shared_examples/features/discussion_comments_shared_example.rb b/spec/support/shared_examples/features/discussion_comments_shared_example.rb index 86ba2821c78..808e0be6be2 100644 --- a/spec/support/shared_examples/features/discussion_comments_shared_example.rb +++ b/spec/support/shared_examples/features/discussion_comments_shared_example.rb @@ -304,7 +304,7 @@ RSpec.shared_examples 'thread comments for issue, epic and merge request' do |re let(:reply_id) { find("#{comments_selector} .note:last-of-type", match: :first)['data-note-id'] } it 'can be replied to after resolving' do - click_button "Resolve thread" + find('button[data-qa-selector="resolve_discussion_button"]').click wait_for_requests refresh @@ -316,7 +316,7 @@ RSpec.shared_examples 'thread comments for issue, epic and merge request' do |re it 'shows resolved thread when toggled' do submit_reply('a') - click_button "Resolve thread" + find('button[data-qa-selector="resolve_discussion_button"]').click wait_for_requests expect(page).to have_selector(".note-row-#{note_id}", visible: true) diff --git a/spec/support/shared_examples/features/error_tracking_shared_example.rb b/spec/support/shared_examples/features/error_tracking_shared_example.rb index 92fc54ce0b0..1bdc5355408 100644 --- a/spec/support/shared_examples/features/error_tracking_shared_example.rb +++ b/spec/support/shared_examples/features/error_tracking_shared_example.rb @@ -2,7 +2,7 @@ RSpec.shared_examples 'error tracking index page' do it 'renders the error index page', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/217810' } do - within('div.js-title-container') do + within('[data-testid="breadcrumb-links"]') do expect(page).to have_content(project.namespace.name) expect(page).to have_content(project.name) end diff --git a/spec/support/shared_examples/features/issuable_invite_members_shared_examples.rb b/spec/support/shared_examples/features/issuable_invite_members_shared_examples.rb index 7a32f61d4fa..49c3674277d 100644 --- a/spec/support/shared_examples/features/issuable_invite_members_shared_examples.rb +++ b/spec/support/shared_examples/features/issuable_invite_members_shared_examples.rb @@ -2,7 +2,7 @@ RSpec.shared_examples 'issuable invite members experiments' do context 'when a privileged user can invite' do - it 'shows a link for inviting members and follows through to the members page' do + it 'shows a link for inviting members and launches invite modal' do project.add_maintainer(user) visit issuable_path @@ -11,14 +11,14 @@ RSpec.shared_examples 'issuable invite members experiments' do wait_for_requests page.within '.dropdown-menu-user' do - expect(page).to have_link('Invite Members', href: project_project_members_path(project)) + expect(page).to have_link('Invite Members') expect(page).to have_selector('[data-track-event="click_invite_members"]') expect(page).to have_selector('[data-track-label="edit_assignee"]') end click_link 'Invite Members' - expect(current_path).to eq project_project_members_path(project) + expect(page).to have_content("You're inviting members to the") end end diff --git a/spec/support/shared_examples/features/project_upload_files_shared_examples.rb b/spec/support/shared_examples/features/project_upload_files_shared_examples.rb index 00d3bd08218..7adf303bde4 100644 --- a/spec/support/shared_examples/features/project_upload_files_shared_examples.rb +++ b/spec/support/shared_examples/features/project_upload_files_shared_examples.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -RSpec.shared_examples 'it uploads and commit a new text file' do - it 'uploads and commit a new text file', :js do +RSpec.shared_examples 'it uploads and commits a new text file' do + it 'uploads and commits a new text file', :js do find('.add-to-tree').click page.within('.dropdown-menu') do @@ -10,7 +10,7 @@ RSpec.shared_examples 'it uploads and commit a new text file' do wait_for_requests end - drop_in_dropzone(File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt')) + attach_file('upload_file', File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt'), make_visible: true) page.within('#modal-upload-blob') do fill_in(:commit_message, with: 'New commit message') @@ -32,8 +32,8 @@ RSpec.shared_examples 'it uploads and commit a new text file' do end end -RSpec.shared_examples 'it uploads and commit a new image file' do - it 'uploads and commit a new image file', :js do +RSpec.shared_examples 'it uploads and commits a new image file' do + it 'uploads and commits a new image file', :js do find('.add-to-tree').click page.within('.dropdown-menu') do @@ -42,7 +42,7 @@ RSpec.shared_examples 'it uploads and commit a new image file' do wait_for_requests end - drop_in_dropzone(File.join(Rails.root, 'spec', 'fixtures', 'logo_sample.svg')) + attach_file('upload_file', File.join(Rails.root, 'spec', 'fixtures', 'logo_sample.svg'), make_visible: true) page.within('#modal-upload-blob') do fill_in(:commit_message, with: 'New commit message') @@ -58,21 +58,49 @@ RSpec.shared_examples 'it uploads and commit a new image file' do end end -RSpec.shared_examples 'it uploads and commit a new file to a forked project' do +RSpec.shared_examples 'it uploads and commits a new pdf file' do + it 'uploads and commits a new pdf file', :js do + find('.add-to-tree').click + + page.within('.dropdown-menu') do + click_link('Upload file') + + wait_for_requests + end + + attach_file('upload_file', File.join(Rails.root, 'spec', 'fixtures', 'git-cheat-sheet.pdf'), make_visible: true) + + page.within('#modal-upload-blob') do + fill_in(:commit_message, with: 'New commit message') + fill_in(:branch_name, with: 'upload_image', visible: true) + click_button('Upload file') + end + + wait_for_all_requests + + visit(project_blob_path(project, 'upload_image/git-cheat-sheet.pdf')) + + expect(page).to have_css('.js-pdf-viewer') + end +end + +RSpec.shared_examples 'it uploads and commits a new file to a forked project' do let(:fork_message) do "You're not allowed to make changes to this project directly. "\ "A fork of this project has been created that you can make changes in, so you can submit a merge request." end - it 'uploads and commit a new file to a forked project', :js, :sidekiq_might_not_need_inline do + it 'uploads and commits a new file to a forked project', :js, :sidekiq_might_not_need_inline do find('.add-to-tree').click click_link('Upload file') expect(page).to have_content(fork_message) + wait_for_all_requests + find('.add-to-tree').click click_link('Upload file') - drop_in_dropzone(File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt')) + attach_file('upload_file', File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt'), make_visible: true) page.within('#modal-upload-blob') do fill_in(:commit_message, with: 'New commit message') @@ -95,6 +123,33 @@ RSpec.shared_examples 'it uploads and commit a new file to a forked project' do end end +RSpec.shared_examples 'it uploads a file to a sub-directory' do + it 'uploads a file to a sub-directory', :js do + click_link 'files' + + page.within('.repo-breadcrumb') do + expect(page).to have_content('files') + end + + find('.add-to-tree').click + click_link('Upload file') + attach_file('upload_file', File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt'), make_visible: true) + + page.within('#modal-upload-blob') do + fill_in(:commit_message, with: 'New commit message') + end + + click_button('Upload file') + + expect(page).to have_content('New commit message') + + page.within('.repo-breadcrumb') do + expect(page).to have_content('files') + expect(page).to have_content('doc_sample.txt') + end + end +end + RSpec.shared_examples 'uploads and commits a new text file via "upload file" button' do it 'uploads and commits a new text file via "upload file" button', :js do find('[data-testid="upload-file-button"]').click diff --git a/spec/support/shared_examples/features/resolving_discussions_in_issues_shared_examples.rb b/spec/support/shared_examples/features/resolving_discussions_in_issues_shared_examples.rb index 06127f2ed8c..6d44a6fde85 100644 --- a/spec/support/shared_examples/features/resolving_discussions_in_issues_shared_examples.rb +++ b/spec/support/shared_examples/features/resolving_discussions_in_issues_shared_examples.rb @@ -14,11 +14,11 @@ RSpec.shared_examples 'creating an issue for a thread' do end it 'can create a new issue for the project' do - expect { click_button 'Submit issue' }.to change { project.issues.reload.size }.by(1) + expect { click_button 'Create issue' }.to change { project.issues.reload.size }.by(1) end it 'resolves the discussion in the merge request' do - click_button 'Submit issue' + click_button 'Create issue' discussion.first_note.reload @@ -26,7 +26,7 @@ RSpec.shared_examples 'creating an issue for a thread' do end it 'shows a flash messaage after resolving a discussion' do - click_button 'Submit issue' + click_button 'Create issue' page.within '.flash-notice' do # Only check for the word 'Resolved' since the spec might have resolved diff --git a/spec/support/shared_examples/features/search_settings_shared_examples.rb b/spec/support/shared_examples/features/search_settings_shared_examples.rb index 6a507c4be56..dda780690b2 100644 --- a/spec/support/shared_examples/features/search_settings_shared_examples.rb +++ b/spec/support/shared_examples/features/search_settings_shared_examples.rb @@ -7,9 +7,7 @@ RSpec.shared_examples 'cannot search settings' do end RSpec.shared_examples 'can search settings' do |search_term, non_match_section| - it 'has search settings field' do - expect(page).to have_field(placeholder: SearchHelpers::INPUT_PLACEHOLDER) - end + it_behaves_like 'can highlight results', search_term it 'hides unmatching sections on search' do expect(page).to have_content(non_match_section) @@ -21,22 +19,19 @@ RSpec.shared_examples 'can search settings' do |search_term, non_match_section| end end -RSpec.shared_examples 'can search settings with feature flag check' do |search_term, non_match_section| - let(:flag) { true } - - before do - stub_feature_flags(search_settings_in_page: flag) - - visit(visit_path) +RSpec.shared_examples 'can highlight results' do |search_term| + it 'has search settings field' do + expect(page).to have_field(placeholder: SearchHelpers::INPUT_PLACEHOLDER) end - context 'with feature flag on' do - it_behaves_like 'can search settings', search_term, non_match_section - end + it 'highlights the search terms' do + selector = '.gl-bg-orange-100' + fill_in SearchHelpers::INPUT_PLACEHOLDER, with: search_term - context 'with feature flag off' do - let(:flag) { false } + expect(page).to have_css(selector) - it_behaves_like 'cannot search settings' + page.find_all(selector) do |element| + expect(element).to have_content(search_term) + end end end diff --git a/spec/support/shared_examples/features/sidebar_shared_examples.rb b/spec/support/shared_examples/features/sidebar_shared_examples.rb new file mode 100644 index 00000000000..429efbe6ba0 --- /dev/null +++ b/spec/support/shared_examples/features/sidebar_shared_examples.rb @@ -0,0 +1,165 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'issue boards sidebar' do + include MobileHelpers + + before do + first_card.click + end + + it 'shows sidebar when clicking issue' do + expect(page).to have_selector('[data-testid="issue-boards-sidebar"]') + end + + it 'closes sidebar when clicking issue' do + expect(page).to have_selector('[data-testid="issue-boards-sidebar"]') + + first_card.click + + expect(page).not_to have_selector('[data-testid="issue-boards-sidebar"]') + end + + it 'shows issue details when sidebar is open', :aggregate_failures do + page.within('[data-testid="issue-boards-sidebar"]') do + expect(page).to have_content(issue.title) + expect(page).to have_content(issue.to_reference) + end + end + + context 'when clicking close button' do + before do + find('[data-testid="issue-boards-sidebar"] .gl-drawer-close-button').click + end + + it 'unhighlights the active issue card' do + expect(first_card[:class]).not_to include('is-active') + expect(first_card[:class]).not_to include('multi-select') + end + + it 'closes sidebar when clicking close button' do + expect(page).not_to have_selector('[data-testid="issue-boards-sidebar"]') + end + end + + context 'in notifications subscription' do + it 'displays notifications toggle', :aggregate_failures do + page.within('[data-testid="sidebar-notifications"]') do + expect(page).to have_selector('[data-testid="notification-subscribe-toggle"]') + expect(page).to have_content('Notifications') + expect(page).not_to have_content('Notifications have been disabled by the project or group owner') + end + end + + it 'shows toggle as on then as off as user toggles to subscribe and unsubscribe', :aggregate_failures do + toggle = find('[data-testid="notification-subscribe-toggle"]') + + toggle.click + + expect(toggle).to have_css("button.is-checked") + + toggle.click + + expect(toggle).not_to have_css("button.is-checked") + end + + context 'when notifications have been disabled' do + before do + project.update_attribute(:emails_disabled, true) + + refresh_and_click_first_card + end + + it 'displays a message that notifications have been disabled' do + page.within('[data-testid="sidebar-notifications"]') do + expect(page).not_to have_selector('[data-testid="notification-subscribe-toggle"]') + expect(page).to have_content('Notifications have been disabled by the project or group owner') + end + end + end + end + + context 'in time tracking' do + it 'displays time tracking feature with default message' do + page.within('[data-testid="time-tracker"]') do + expect(page).to have_content('Time tracking') + expect(page).to have_content('No estimate or time spent') + end + end + + context 'when only spent time is recorded' do + before do + issue.timelogs.create!(time_spent: 3600, user: user) + + refresh_and_click_first_card + end + + it 'shows the total time spent only' do + page.within('[data-testid="time-tracker"]') do + expect(page).to have_content('Spent: 1h') + expect(page).not_to have_content('Estimated') + end + end + end + + context 'when only estimated time is recorded' do + before do + issue.update!(time_estimate: 3600) + + refresh_and_click_first_card + end + + it 'shows the estimated time only', :aggregate_failures do + page.within('[data-testid="time-tracker"]') do + expect(page).to have_content('Estimated: 1h') + expect(page).not_to have_content('Spent') + end + end + end + + context 'when estimated and spent times are available' do + before do + issue.timelogs.create!(time_spent: 1800, user: user) + issue.update!(time_estimate: 3600) + + refresh_and_click_first_card + end + + it 'shows time tracking progress bar' do + page.within('[data-testid="time-tracker"]') do + expect(page).to have_selector('[data-testid="timeTrackingComparisonPane"]') + end + end + + it 'shows both estimated and spent time text', :aggregate_failures do + page.within('[data-testid="time-tracker"]') do + expect(page).to have_content('Spent 30m') + expect(page).to have_content('Est 1h') + end + end + end + + context 'when limitedToHours instance option is turned on' do + before do + # 3600+3600*24 = 1d 1h or 25h + issue.timelogs.create!(time_spent: 3600 + 3600 * 24, user: user) + stub_application_setting(time_tracking_limit_to_hours: true) + + refresh_and_click_first_card + end + + it 'shows the total time spent only' do + page.within('[data-testid="time-tracker"]') do + expect(page).to have_content('Spent: 25h') + end + end + end + end + + def refresh_and_click_first_card + page.refresh + + wait_for_requests + + first_card.click + end +end diff --git a/spec/support/shared_examples/features/wiki/user_creates_wiki_page_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_creates_wiki_page_shared_examples.rb index 2f8ebd0d264..8a6d5d88ca6 100644 --- a/spec/support/shared_examples/features/wiki/user_creates_wiki_page_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_creates_wiki_page_shared_examples.rb @@ -240,7 +240,7 @@ RSpec.shared_examples 'User creates wiki page' do end end - it "shows the emoji autocompletion dropdown" do + it "shows the emoji autocompletion dropdown", :js do click_link("New page") page.within(".wiki-form") do diff --git a/spec/support/shared_examples/features/wiki/user_git_access_wiki_page_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_git_access_wiki_page_shared_examples.rb index d3d2a36147d..4fea450bd64 100644 --- a/spec/support/shared_examples/features/wiki/user_git_access_wiki_page_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_git_access_wiki_page_shared_examples.rb @@ -13,7 +13,7 @@ RSpec.shared_examples 'User views Git access wiki page' do expect(page).to have_text("Clone repository #{wiki.full_path}") - within('.git-clone-holder') do + within('.js-git-clone-holder') do expect(page).to have_css('#clone-dropdown', text: 'HTTP') expect(page).to have_field('clone_url', with: wiki.http_url_to_repo) diff --git a/spec/support/shared_examples/features/wiki/user_previews_wiki_changes_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_previews_wiki_changes_shared_examples.rb index a22d98f20c4..1a981f42086 100644 --- a/spec/support/shared_examples/features/wiki/user_previews_wiki_changes_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_previews_wiki_changes_shared_examples.rb @@ -38,19 +38,19 @@ RSpec.shared_examples 'User previews wiki changes' do end end - context "when there are no spaces or hyphens in the page name" do + context "when there are no spaces or hyphens in the page name", :js do let(:wiki_page) { build(:wiki_page, wiki: wiki, title: 'a/b/c/d', content: page_content) } it_behaves_like 'rewrites relative links' end - context "when there are spaces in the page name" do + context "when there are spaces in the page name", :js do let(:wiki_page) { build(:wiki_page, wiki: wiki, title: 'a page/b page/c page/d page', content: page_content) } it_behaves_like 'rewrites relative links' end - context "when there are hyphens in the page name" do + context "when there are hyphens in the page name", :js do let(:wiki_page) { build(:wiki_page, wiki: wiki, title: 'a-page/b-page/c-page/d-page', content: page_content) } it_behaves_like 'rewrites relative links' 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 1e325535e81..d185e9dd81c 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 @@ -11,7 +11,7 @@ RSpec.shared_examples 'User updates wiki page' do sign_in(user) end - context 'when wiki is empty' do + context 'when wiki is empty', :js do before do |example| visit(wiki_path(wiki)) @@ -57,7 +57,7 @@ RSpec.shared_examples 'User updates wiki page' do it_behaves_like 'wiki file attachments' end - context 'when wiki is not empty' do + context 'when wiki is not empty', :js do let!(:wiki_page) { create(:wiki_page, wiki: wiki, title: 'home', content: 'Home page') } before do @@ -147,7 +147,7 @@ RSpec.shared_examples 'User updates wiki page' do it_behaves_like 'wiki file attachments' end - context 'when the page is in a subdir' do + context 'when the page is in a subdir', :js do let(:page_name) { 'page_name' } let(:page_dir) { "foo/bar/#{page_name}" } let!(:wiki_page) { create(:wiki_page, wiki: wiki, title: page_dir, content: 'Home page') } diff --git a/spec/support/shared_examples/features/wiki/user_views_wiki_empty_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_views_wiki_empty_shared_examples.rb index 14180d503df..3514ce286d6 100644 --- a/spec/support/shared_examples/features/wiki/user_views_wiki_empty_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_views_wiki_empty_shared_examples.rb @@ -20,11 +20,11 @@ RSpec.shared_examples 'User views empty wiki' do end end - shared_examples 'empty wiki message' do |writable: false, issuable: false, confluence: false| + shared_examples 'empty wiki message' do |writable: false, issuable: false, confluence: false, expect_button: true| # This mirrors the logic in: # - app/views/shared/empty_states/_wikis.html.haml # - WikiHelper#wiki_empty_state_messages - it 'shows the empty state message with the expected elements' do + it 'shows the empty state message with the expected elements', :js do visit wiki_path(wiki) if writable @@ -37,7 +37,7 @@ RSpec.shared_examples 'User views empty wiki' do if issuable && !writable expect(element).to have_content("improve the wiki for this #{container_name}") expect(element).to have_link("issue tracker", href: project_issues_path(project)) - expect(element).to have_link("Suggest wiki improvement", href: new_project_issue_path(project)) + expect(element.has_link?("Suggest wiki improvement", href: new_project_issue_path(project))).to be(expect_button) else expect(element).not_to have_content("improve the wiki for this #{container_name}") expect(element).not_to have_link("issue tracker") |