-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a number of meta tags for use by third parties like Facebook, Slack and Twitter. It makes the most difference to pages that have images like news articles and case studies. - Opengraph (`og`) tag are used by most services. You can read the spec here http://ogp.me. - The `twitter` tags are service-specific but are also used by Slack and possibly others (https://medium.com/slack-developer-blog/everything-you-ever-wanted-to-k now-about-unfurling-but-were-afraid-to-ask-or-how-to-make-your-e64b4bb92
- Loading branch information
Showing
4 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'test_helper' | ||
|
||
class MetaTagsTest < ActionDispatch::IntegrationTest | ||
test "correct meta tags are displayed for pages" do | ||
case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: 'news_article') do |random| | ||
random.merge( | ||
"title" => "Zhe title", | ||
"withdrawn_notice" => {}, | ||
) | ||
end | ||
|
||
content_store_has_item("/some-page", case_study.to_json) | ||
|
||
visit "/some-page" | ||
|
||
assert page.has_css?("meta[property='og:title'][content='Zhe title']", visible: false) | ||
end | ||
|
||
test "correct meta tags are displayed for pages without images" do | ||
case_study = GovukSchemas::RandomExample.for_schema(frontend_schema: 'news_article') do |random| | ||
random["details"].delete("image") | ||
random | ||
end | ||
|
||
content_store_has_item("/some-page", case_study.to_json) | ||
|
||
visit "/some-page" | ||
|
||
assert page.has_css?("meta[name='twitter:card'][content='summary']", visible: false) | ||
end | ||
|
||
test "correct meta tags are displayed for pages with images" 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 | ||
end | ||
|
||
content_store_has_item("/some-page", case_study.to_json) | ||
|
||
visit "/some-page" | ||
|
||
assert page.has_css?("meta[name='twitter:card'][content='summary_large_image']", visible: false) | ||
assert page.has_css?("meta[name='twitter:image'][content='https://example.org/image.jpg']", visible: false) | ||
assert page.has_css?("meta[property='og:image'][content='https://example.org/image.jpg']", visible: false) | ||
end | ||
end |