Skip to content

Commit

Permalink
Tests for meta_tags (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
KludgeKML committed Sep 23, 2024
1 parent 99d3d0b commit 352a8a3
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions spec/system/meta_tags_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
RSpec.describe "Meta Tags" do
before do
case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: "take_part") do |random|
random.merge!(
"title" => "Zhe title",
"withdrawn_notice" => {},
"locale" => "en",
)
end

stub_content_store_has_item("/government/get-involved/take-part/some-page", case_study.to_json)
end

it "renders the correct meta tags for pages" do
visit "/government/get-involved/take-part/some-page"

expect(page).to have_css("meta[property='og:title'][content='Zhe title']", visible: false)
end

context "for pages without images" do
before do
case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: "news_article") do |random|
random["details"].delete("image")
random["locale"] = "en"
random
end
stub_content_store_has_item("/government/get-involved/take-part/some-page", case_study.to_json)
end

it "does not render image tags" do
visit "/government/get-involved/take-part/some-page"

expect(page).to have_css("meta[name='twitter:card'][content='summary']", visible: false)
expect(page).not_to have_css("meta[name='twitter:image']")
expect(page).not_to have_css("meta[name='og:image']")
end
end

context "for pages with images" do
before do
case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: "news_article") do |random|
random["details"] = random["details"].merge(
"image" => {
"url" => "https://example.org/image.jpg",
"alt_text" => "An accessible alt text",
},
)
random["locale"] = "en"
random
end
stub_content_store_has_item("/government/get-involved/take-part/some-page", case_study.to_json)
end

it "renders image tags" do
visit "/government/get-involved/take-part/some-page"

expect(page).to have_css("meta[name='twitter:card'][content='summary_large_image']", visible: false)
expect(page).to have_css("meta[name='twitter:image'][content='https://example.org/image.jpg']", visible: false)
expect(page).to have_css("meta[property='og:image'][content='https://example.org/image.jpg']", visible: false)
end
end
end

0 comments on commit 352a8a3

Please sign in to comment.