Skip to content

Commit

Permalink
Merge pull request #2666 from alphagov/content_schema_test
Browse files Browse the repository at this point in the history
Re-enable content schema tests
  • Loading branch information
hannako authored Jan 17, 2023
2 parents e16cc29 + f4a41c3 commit 411c7ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions test/contracts/govuk_content_schemas_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
class GovukContentSchemasTest < ActionDispatch::IntegrationTest
include GovukContentSchemaExamples

all_examples_for_supported_schemas.each do |content_item|
test "can successfully render #{content_item['base_path']} schema example" do
all_examples_for_supported_schemas.each_with_index do |content_item, index|
test "can successfully render #{content_item['document_type']} #{index} example" do
stub_content_store_has_item(content_item["base_path"], content_item)
stub_parent_breadcrumbs(content_item, content_item["document_type"])

get content_item["base_path"]

Expand Down
10 changes: 8 additions & 2 deletions test/support/govuk_content_schema_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,23 @@ def govuk_content_schema_example(schema_name, example_name)
GovukSchemas::Example.find(schema_name, example_name:)
end

def stub_parent_breadcrumbs(document, schema)
parents = document.dig("links", "parent")
return if parents.nil?

stub_content_store_has_item(parents.first["base_path"], document) if schema == "html_publication"
end

module ClassMethods
def all_examples_for_supported_schemas
GovukSchemas::Example.find_all(supported_schemas)
supported_schemas.flat_map { |format| GovukSchemas::Example.find_all(format) }
end

def supported_schemas
%w[
case_study
coming_soon
html_publication
redirect
statistics_announcement
take_part
topical_event_about_page
Expand Down

0 comments on commit 411c7ef

Please sign in to comment.