Skip to content

Commit

Permalink
Shared tests for meta_tags with images
Browse files Browse the repository at this point in the history
- Needed for the tests added in the next commit.
- Separate from the no-image tags test already here,
  as the shared examples for images break if run on a
  non-image-bearing document type like help pages

Commit audit trail:
- https://github.com/alphagov/government-frontend/blob/6523741691ddfb9551967311a3f79775e9403ecf/test/integration/meta_tags_test.rb
  • Loading branch information
KludgeKML committed Nov 4, 2024
1 parent 90db91d commit b97cb37
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/support/meta_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,28 @@
expect(page).to have_css("meta[property='og:title'][content='Zhe title']", visible: false)
end
end

RSpec.shared_examples "it has meta tags for images" do |schema, base_path|
before do
example_doc = GovukSchemas::RandomExample.for_schema(frontend_schema: schema) do |random|
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("#{base_path}/some-page", example_doc.to_json)
end

it "renders image tags" do
visit "#{base_path}/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

0 comments on commit b97cb37

Please sign in to comment.