From 118de9eddcf7e57509a8620f4532bae6f193aee4 Mon Sep 17 00:00:00 2001 From: gms-gs Date: Wed, 27 Nov 2024 11:59:57 +0000 Subject: [PATCH] Update tets --- spec/features/canonical_tags_spec.rb | 94 ++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/spec/features/canonical_tags_spec.rb b/spec/features/canonical_tags_spec.rb index 553091eaa4..1b5f538525 100644 --- a/spec/features/canonical_tags_spec.rb +++ b/spec/features/canonical_tags_spec.rb @@ -2,22 +2,92 @@ require 'rails_helper' -feature 'Canonical tags' do - context 'when visiting Find pages', :with_find_constraint do - scenario 'Find pages contain canonical tags' do - visit '/' +feature 'Canonical tags', :with_find_constraint do + before do + given_i_have_courses + and_i_visit_the_home_page + end - expect(page).to have_css("link[rel='canonical'][href='http://www.example.com/']", visible: :all) - expect(page).to have_css("meta[property='og:url'][content='http://www.example.com/']", visible: :all) + describe 'Canonical tags on Find pages' do + scenario 'without query params' do + then_the_page_contains_canonical_tags_with_no_query_params + end + + scenario 'with query parameters' do + and_i_select_the_across_england_radio_button + then_the_page_contains_canonical_tags_without_query_params end - end - context 'when visiting Publish pages', :with_publish_constraint do - scenario 'Publish pages contain canonical tags' do - visit '/' + scenario 'when visiting a course' do + when_i_visit_the_course_page + then_the_page_contains_canonical_tags_for_a_course + end + + scenario 'when visiting a course and selecting an anchor tag' do + when_i_visit_the_course_page + and_i_click_an_anchor_tag + then_the_page_contains_canonical_tags_for_a_course + end + end - expect(page).to have_css("link[rel='canonical'][href='http://www.example.com/sign-in/']", visible: :all) - expect(page).to have_css("meta[property='og:url'][content='http://www.example.com/sign-in/']", visible: :all) + describe 'Canonical tags on Publish pages', :with_publish_constraint do + scenario 'Publish page contains canonical tags' do + and_i_visit_the_publish_page + then_the_publish_page_contains_canonical_tags end end + + def when_i_visit_the_course_page + visit find_course_path( + provider_code: @mathematics_course.provider.provider_code, + course_code: @mathematics_course.course_code + ) + end + + def given_i_have_courses + provider = create(:provider) + @mathematics_course = create(:course, :published_postgraduate, :secondary, provider:, name: 'Mathematics', subjects: [find_or_create(:secondary_subject, :mathematics)]) + end + + def and_i_visit_the_home_page + visit '/' + end + + def and_i_visit_the_publish_page + visit '/sign-in/' + end + + def and_i_select_the_across_england_radio_button + choose 'Across England' + click_link_or_button 'Continue' + end + + def and_i_click_an_anchor_tag + click_link_or_button 'Where you will train' + end + + def then_the_page_contains_canonical_tags_for_a_course + canonical_url = "http://www.example.com/course/#{@mathematics_course.provider.provider_code}/#{@mathematics_course.course_code}/" + + link_tag = page.find("link[rel='canonical']", visible: :all) + expect(link_tag[:href]).to eq(canonical_url) + + og_url_tag = page.find("meta[property='og:url']", visible: :all) + expect(og_url_tag[:content]).to eq(canonical_url) + end + + def then_the_page_contains_canonical_tags_with_no_query_params + expect(page).to have_css("link[rel='canonical'][href='http://www.example.com/']", visible: :all) + expect(page).to have_css("meta[property='og:url'][content='http://www.example.com/']", visible: :all) + end + + def then_the_page_contains_canonical_tags_without_query_params + expect(page).to have_css("link[rel='canonical'][href='http://www.example.com/age-groups/']", visible: :all) + expect(page).to have_css("meta[property='og:url'][content='http://www.example.com/age-groups/']", visible: :all) + end + + def then_the_publish_page_contains_canonical_tags + expect(page).to have_css("link[rel='canonical'][href='http://www.example.com/sign-in/']", visible: :all) + expect(page).to have_css("meta[property='og:url'][content='http://www.example.com/sign-in/']", visible: :all) + end end