Skip to content

Commit

Permalink
Update tets
Browse files Browse the repository at this point in the history
  • Loading branch information
gms-gs committed Nov 27, 2024
1 parent 0e145fd commit 118de9e
Showing 1 changed file with 82 additions and 12 deletions.
94 changes: 82 additions & 12 deletions spec/features/canonical_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 118de9e

Please sign in to comment.