diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/support/shared_examples/features | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/support/shared_examples/features')
5 files changed, 354 insertions, 16 deletions
diff --git a/spec/support/shared_examples/features/master_manages_access_requests_shared_example.rb b/spec/support/shared_examples/features/master_manages_access_requests_shared_example.rb index 00ce690d2e3..ffe4fb83283 100644 --- a/spec/support/shared_examples/features/master_manages_access_requests_shared_example.rb +++ b/spec/support/shared_examples/features/master_manages_access_requests_shared_example.rb @@ -8,17 +8,18 @@ RSpec.shared_examples 'Maintainer manages access requests' do entity.request_access(user) entity.respond_to?(:add_owner) ? entity.add_owner(maintainer) : entity.add_maintainer(maintainer) sign_in(maintainer) - end - - it 'maintainer can see access requests' do visit members_page_path + if has_tabs + click_on 'Access requests' + end + end + + it 'maintainer can see access requests', :js do expect_visible_access_request(entity, user) end it 'maintainer can grant access', :js do - visit members_page_path - expect_visible_access_request(entity, user) click_on 'Grant access' @@ -31,8 +32,6 @@ RSpec.shared_examples 'Maintainer manages access requests' do end it 'maintainer can deny access', :js do - visit members_page_path - expect_visible_access_request(entity, user) # Open modal @@ -47,7 +46,13 @@ RSpec.shared_examples 'Maintainer manages access requests' do end def expect_visible_access_request(entity, user) - expect(page).to have_content "Users requesting access to #{entity.name} 1" + if has_tabs + expect(page).to have_content "Access requests 1" + expect(page).to have_content "Users requesting access to #{entity.name}" + else + expect(page).to have_content "Users requesting access to #{entity.name} 1" + end + expect(page).to have_content user.name end diff --git a/spec/support/shared_examples/features/packages_shared_examples.rb b/spec/support/shared_examples/features/packages_shared_examples.rb new file mode 100644 index 00000000000..6debbf81fc0 --- /dev/null +++ b/spec/support/shared_examples/features/packages_shared_examples.rb @@ -0,0 +1,113 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'packages list' do |check_project_name: false| + it 'shows a list of packages' do + wait_for_requests + + packages.each_with_index do |pkg, index| + package_row = package_table_row(index) + + expect(package_row).to have_content(pkg.name) + expect(package_row).to have_content(pkg.version) + expect(package_row).to have_content(pkg.project.name) if check_project_name + end + end + + def package_table_row(index) + page.all("#{packages_table_selector} > [data-qa-selector=\"packages-row\"]")[index].text + end +end + +RSpec.shared_examples 'package details link' do |property| + let(:package) { packages.first } + + before do + stub_feature_flags(packages_details_one_column: false) + end + + it 'navigates to the correct url' do + page.within(packages_table_selector) do + click_link package.name + end + + expect(page).to have_current_path(project_package_path(package.project, package)) + + page.within('.detail-page-header') do + expect(page).to have_content(package.name) + end + + page.within('[data-qa-selector="package_information_content"]') do + expect(page).to have_content('Installation') + expect(page).to have_content('Registry setup') + end + end +end + +RSpec.shared_examples 'when there are no packages' do + it 'displays the empty message' do + expect(page).to have_content('There are no packages yet') + end +end + +RSpec.shared_examples 'correctly sorted packages list' do |order_by, ascending: false| + context "ordered by #{order_by} and ascending #{ascending}" do + before do + click_sort_option(order_by, ascending) + end + + it_behaves_like 'packages list' + end +end + +RSpec.shared_examples 'shared package sorting' do + it_behaves_like 'correctly sorted packages list', 'Type' do + let(:packages) { [package_two, package_one] } + end + + it_behaves_like 'correctly sorted packages list', 'Type', ascending: true do + let(:packages) { [package_one, package_two] } + end + + it_behaves_like 'correctly sorted packages list', 'Name' do + let(:packages) { [package_two, package_one] } + end + + it_behaves_like 'correctly sorted packages list', 'Name', ascending: true do + let(:packages) { [package_one, package_two] } + end + + it_behaves_like 'correctly sorted packages list', 'Version' do + let(:packages) { [package_one, package_two] } + end + + it_behaves_like 'correctly sorted packages list', 'Version', ascending: true do + let(:packages) { [package_two, package_one] } + end + + it_behaves_like 'correctly sorted packages list', 'Created' do + let(:packages) { [package_two, package_one] } + end + + it_behaves_like 'correctly sorted packages list', 'Created', ascending: true do + let(:packages) { [package_one, package_two] } + end +end + +def packages_table_selector + '[data-qa-selector="packages-table"]' +end + +def click_sort_option(option, ascending) + page.within('.gl-sorting') do + # Reset the sort direction + click_button 'Sort direction' if page.has_selector?('svg[aria-label="Sorting Direction: Ascending"]', wait: 0) + + find('button.dropdown-menu-toggle').click + + page.within('.dropdown-menu') do + click_button option + end + + click_button 'Sort direction' if ascending + end +end diff --git a/spec/support/shared_examples/features/protected_branches_access_control_ce_shared_examples.rb b/spec/support/shared_examples/features/protected_branches_access_control_ce_shared_examples.rb index 65db082505a..a46382bc292 100644 --- a/spec/support/shared_examples/features/protected_branches_access_control_ce_shared_examples.rb +++ b/spec/support/shared_examples/features/protected_branches_access_control_ce_shared_examples.rb @@ -22,7 +22,7 @@ RSpec.shared_examples "protected branches > access control > CE" do end end - click_on "Protect" + click_on_protect expect(ProtectedBranch.count).to eq(1) expect(ProtectedBranch.last.push_access_levels.map(&:access_level)).to eq([access_type_id]) @@ -45,7 +45,7 @@ RSpec.shared_examples "protected branches > access control > CE" do find(:link, 'No one').click end - click_on "Protect" + click_on_protect expect(ProtectedBranch.count).to eq(1) @@ -85,7 +85,7 @@ RSpec.shared_examples "protected branches > access control > CE" do find(:link, 'No one').click end - click_on "Protect" + click_on_protect expect(ProtectedBranch.count).to eq(1) expect(ProtectedBranch.last.merge_access_levels.map(&:access_level)).to eq([access_type_id]) @@ -108,7 +108,7 @@ RSpec.shared_examples "protected branches > access control > CE" do find(:link, 'No one').click end - click_on "Protect" + click_on_protect expect(ProtectedBranch.count).to eq(1) diff --git a/spec/support/shared_examples/features/rss_shared_examples.rb b/spec/support/shared_examples/features/rss_shared_examples.rb index 42df88ec08e..1b0d3f9605a 100644 --- a/spec/support/shared_examples/features/rss_shared_examples.rb +++ b/spec/support/shared_examples/features/rss_shared_examples.rb @@ -9,8 +9,7 @@ end RSpec.shared_examples "it has an RSS button with current_user's feed token" do it "shows the RSS button with current_user's feed token" do expect(page) - .to have_css("a:has(.fa-rss)[href*='feed_token=#{user.feed_token}']") - .or have_css("a.js-rss-button[href*='feed_token=#{user.feed_token}']") + .to have_css("a:has(.qa-rss-icon)[href*='feed_token=#{user.feed_token}']") end end @@ -23,7 +22,6 @@ end RSpec.shared_examples "it has an RSS button without a feed token" do it "shows the RSS button without a feed token" do expect(page) - .to have_css("a:has(.fa-rss):not([href*='feed_token'])") - .or have_css("a.js-rss-button:not([href*='feed_token'])") + .to have_css("a:has(.qa-rss-icon):not([href*='feed_token'])") end end diff --git a/spec/support/shared_examples/features/snippets_shared_examples.rb b/spec/support/shared_examples/features/snippets_shared_examples.rb index 1c8a9714bdf..8d68b1e4c0a 100644 --- a/spec/support/shared_examples/features/snippets_shared_examples.rb +++ b/spec/support/shared_examples/features/snippets_shared_examples.rb @@ -50,3 +50,225 @@ RSpec.shared_examples 'tabs with counts' do expect(tab.find('.badge').text).to eq(counts[:public]) end end + +RSpec.shared_examples 'does not show New Snippet button' do + let(:user) { create(:user, :external) } + + specify do + sign_in(user) + + subject + + wait_for_requests + + expect(page).not_to have_link('New snippet') + end +end + +RSpec.shared_examples 'show and render proper snippet blob' do + before do + allow_any_instance_of(Snippet).to receive(:blobs).and_return([snippet.repository.blob_at('master', file_path)]) + end + + context 'Ruby file' do + let(:file_path) { 'files/ruby/popen.rb' } + + it 'displays the blob' do + subject + + aggregate_failures do + # shows highlighted Ruby code + expect(page).to have_content("require 'fileutils'") + + # does not show a viewer switcher + expect(page).not_to have_selector('.js-blob-viewer-switcher') + + # shows an enabled copy button + expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') + + # shows a raw button + expect(page).to have_link('Open raw') + + # shows a download button + expect(page).to have_link('Download') + end + end + end + + context 'Markdown file' do + let(:file_path) { 'files/markdown/ruby-style-guide.md' } + + context 'visiting directly' do + before do + subject + end + + it 'displays the blob using the rich viewer' do + aggregate_failures do + # hides the simple viewer + expect(page).to have_selector('.blob-viewer[data-type="simple"]', visible: false) + expect(page).to have_selector('.blob-viewer[data-type="rich"]') + + # shows rendered Markdown + expect(page).to have_link("PEP-8") + + # shows a viewer switcher + expect(page).to have_selector('.js-blob-viewer-switcher') + + # shows a disabled copy button + expect(page).to have_selector('.js-copy-blob-source-btn.disabled') + + # shows a raw button + expect(page).to have_link('Open raw') + + # shows a download button + expect(page).to have_link('Download') + end + end + + context 'switching to the simple viewer' do + before do + find('.js-blob-viewer-switch-btn[data-viewer=simple]').click + + wait_for_requests + end + + it 'displays the blob using the simple viewer' do + aggregate_failures do + # hides the rich viewer + expect(page).to have_selector('.blob-viewer[data-type="simple"]') + expect(page).to have_selector('.blob-viewer[data-type="rich"]', visible: false) + + # shows highlighted Markdown code + expect(page).to have_content("[PEP-8](http://www.python.org/dev/peps/pep-0008/)") + + # shows an enabled copy button + expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') + end + end + + context 'switching to the rich viewer again' do + before do + find('.js-blob-viewer-switch-btn[data-viewer=rich]').click + + wait_for_requests + end + + it 'displays the blob using the rich viewer' do + aggregate_failures do + # hides the simple viewer + expect(page).to have_selector('.blob-viewer[data-type="simple"]', visible: false) + expect(page).to have_selector('.blob-viewer[data-type="rich"]') + + # shows an enabled copy button + expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') + end + end + end + end + end + + context 'visiting with a line number anchor' do + let(:anchor) { 'L1' } + + it 'displays the blob using the simple viewer' do + subject + + aggregate_failures do + # hides the rich viewer + expect(page).to have_selector('.blob-viewer[data-type="simple"]') + expect(page).to have_selector('.blob-viewer[data-type="rich"]', visible: false) + + # highlights the line in question + expect(page).to have_selector('#LC1.hll') + + # shows highlighted Markdown code + expect(page).to have_content("[PEP-8](http://www.python.org/dev/peps/pep-0008/)") + + # shows an enabled copy button + expect(page).to have_selector('.js-copy-blob-source-btn:not(.disabled)') + end + end + end + end +end + +RSpec.shared_examples 'personal snippet with references' do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:merge_request) { create(:merge_request, source_project: project) } + let_it_be(:project_snippet) { create(:project_snippet, :repository, project: project)} + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:commit) { project.commit } + + let(:mr_reference) { merge_request.to_reference(full: true) } + let(:issue_reference) { issue.to_reference(full: true) } + let(:snippet_reference) { project_snippet.to_reference(full: true) } + let(:commit_reference) { commit.reference_link_text(full: true) } + + RSpec.shared_examples 'handles resource links' do + context 'with access to the resource' do + before do + project.add_developer(user) + end + + it 'converts the reference to a link' do + subject + + page.within(container) do + aggregate_failures do + expect(page).to have_link(mr_reference) + expect(page).to have_link(issue_reference) + expect(page).to have_link(snippet_reference) + expect(page).to have_link(commit_reference) + end + end + end + end + + context 'without access to the resource' do + it 'does not convert the reference to a link' do + subject + + page.within(container) do + expect(page).not_to have_link(mr_reference) + expect(page).not_to have_link(issue_reference) + expect(page).not_to have_link(snippet_reference) + expect(page).not_to have_link(commit_reference) + end + end + end + end + + context 'when using references to resources' do + let(:references) do + <<~REFERENCES + MR: #{mr_reference} + + Commit: #{commit_reference} + + Issue: #{issue_reference} + + ProjectSnippet: #{snippet_reference} + REFERENCES + end + + it_behaves_like 'handles resource links' + end + + context 'when using links to resources' do + let(:args) { { host: Gitlab.config.gitlab.url, port: nil } } + let(:references) do + <<~REFERENCES + MR: #{merge_request_url(merge_request, args)} + + Commit: #{project_commit_url(project, commit, args)} + + Issue: #{issue_url(issue, args)} + + ProjectSnippet: #{project_snippet_url(project, project_snippet, args)} + REFERENCES + end + + it_behaves_like 'handles resource links' + end +end |