From 43a048b393fc35df98ac32dcef4c41189825696d Mon Sep 17 00:00:00 2001 From: George Schena Date: Thu, 10 Oct 2024 14:37:18 +0100 Subject: [PATCH] Add meta tags spec support and add to HelpPage spec - test/integration/meta_tags_test.rb https://github.com/alphagov/government-frontend/blob/5d6622e384dcde9c19fcefe88d94414e1d6fb457/test/integration/meta_tags_test.rb --- spec/support/meta_tags.rb | 20 ++++++++++++++++++++ spec/system/help_page_spec.rb | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 spec/support/meta_tags.rb diff --git a/spec/support/meta_tags.rb b/spec/support/meta_tags.rb new file mode 100644 index 0000000000..62c0d47ad9 --- /dev/null +++ b/spec/support/meta_tags.rb @@ -0,0 +1,20 @@ +RSpec.shared_examples "it has meta tags" do |schema, base_path| + before do + example_doc = GovukSchemas::RandomExample.for_schema(frontend_schema: schema) do |random| + random.merge!( + "title" => "Zhe title", + "withdrawn_notice" => {}, + ) + random["links"]["available_translations"] = [] + random + end + + stub_content_store_has_item("#{base_path}/some-page", example_doc.to_json) + end + + it "renders the correct meta tags for the title" do + visit "#{base_path}/some-page" + + expect(page).to have_css("meta[property='og:title'][content='Zhe title']", visible: false) + end +end diff --git a/spec/system/help_page_spec.rb b/spec/system/help_page_spec.rb index 9ce4663609..ca8bcd0e2d 100644 --- a/spec/system/help_page_spec.rb +++ b/spec/system/help_page_spec.rb @@ -1,7 +1,9 @@ RSpec.describe "HelpPage" do + it_behaves_like "it has meta tags", "help_page", "/help/about-govuk" + before do - content_store_has_example_item("/help/about-govuk", schema: "help_page", example: "about-govuk") - content_store_has_example_item("/help/cookie-details", schema: "help_page", example: "cookie-details") + content_store_has_example_item("/help/about-govuk", schema: :help_page, example: "about-govuk") + content_store_has_example_item("/help/cookie-details", schema: :help_page, example: "cookie-details") end context "when visiting 'help/:slug'" do