Skip to content

Commit

Permalink
Tests for meta_tags
Browse files Browse the repository at this point in the history
commit audit trail:
alphagov/government-frontend@76e9bd2#diff-6048e9f535fbd535b1c38ab5e387e5c6e0a485d411e9edbbbce9b111b40c25b7
(We have not copied the no-image tags yet, as they are not relevant for the
take_part document type. We will bring in when a document type without images
is ported over)
  • Loading branch information
KludgeKML committed Sep 23, 2024
1 parent dc5c302 commit 590d264
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions spec/system/meta_tags_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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" => {},
)
random["links"]["available_translations"] = []
random
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 with images" do
before do
case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: "take_part") do |random|
random["details"] = random["details"].merge(
"image" => {
"url" => "https://example.org/image.jpg",
"alt_text" => "An accessible alt text",
},
)
random["links"]["available_translations"] = []
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 590d264

Please sign in to comment.