diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/features/canonical_link_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/features/canonical_link_spec.rb')
-rw-r--r-- | spec/features/canonical_link_spec.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/features/canonical_link_spec.rb b/spec/features/canonical_link_spec.rb new file mode 100644 index 00000000000..8b64e9a5b9d --- /dev/null +++ b/spec/features/canonical_link_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Canonical link' do + include Spec::Support::Helpers::Features::CanonicalLinkHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :public, namespace: user.namespace) } + let_it_be(:issue) { create(:issue, project: project) } + + let_it_be(:issue_request) { issue_url(issue) } + let_it_be(:project_request) { project_url(project) } + + before do + sign_in(user) + end + + shared_examples 'shows canonical link' do + specify do + visit request_url + + expect(page).to have_canonical_link(expected_url) + end + end + + shared_examples 'does not show canonical link' do + specify do + visit request_url + + expect(page).not_to have_any_canonical_links + end + end + + it_behaves_like 'does not show canonical link' do + let(:request_url) { issue_request } + end + + it_behaves_like 'shows canonical link' do + let(:request_url) { issue_request + '/' } + let(:expected_url) { issue_request } + end + + it_behaves_like 'shows canonical link' do + let(:request_url) { project_issues_url(project) + "/?state=opened" } + let(:expected_url) { project_issues_url(project, state: 'opened') } + end + + it_behaves_like 'does not show canonical link' do + let(:request_url) { project_request } + end + + it_behaves_like 'shows canonical link' do + let(:request_url) { project_request + '/' } + let(:expected_url) { project_request } + end + + it_behaves_like 'shows canonical link' do + let(:query_params) { '?foo=bar' } + let(:request_url) { project_request + "/#{query_params}" } + let(:expected_url) { project_request + query_params } + end + + # Hard-coded canonical links + + it_behaves_like 'shows canonical link' do + let(:request_url) { explore_root_path } + let(:expected_url) { explore_projects_url } + end +end |