Skip to content

Commit

Permalink
Add integration test for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hilton committed Mar 31, 2017
1 parent 30856c5 commit a591533
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
8 changes: 6 additions & 2 deletions app/presenters/specialist_document_presenter.rb
Expand Up @@ -18,7 +18,7 @@ def title_and_context
def metadata
super.tap do |m|
facets_with_values.each do |facet|
m[:other][facet['name']] = facet['values'].join(', ')
m[:other][facet['name']] = join_facets(facet)
end
end
end
Expand All @@ -28,7 +28,7 @@ def document_footer
m[:other_dates] = {}
facets_with_values.each do |facet|
type = facet['type'] == 'date' ? :other_dates : :other
m[type][facet['name']] = facet['values'].join(', ')
m[type][facet['name']] = join_facets(facet)
end
end
end
Expand All @@ -50,6 +50,10 @@ def breadcrumbs

private

def join_facets(facet)
facet['values'].join(', ')
end

def finder
first_finder = content_item.dig("links", "finder", 0)
Airbrake.notify("Finder not found",
Expand Down
31 changes: 27 additions & 4 deletions test/integration/specialist_document_test.rb
Expand Up @@ -49,11 +49,24 @@ class SpecialistDocumentTest < ActionDispatch::IntegrationTest
test "renders text facets correctly" do
setup_and_visit_content_item('countryside-stewardship-grants')

within shared_component_selector("document_footer") do
component_args = JSON.parse(page.text)
assert_equal component_args["other"]["Grant type"], "<a href=\"/countryside-stewardship-grants?grant_type%5B%5D=option\">Option</a>"
assert_equal component_args["other"]["Tiers or standalone items"], "<a href=\"/countryside-stewardship-grants?tiers_or_standalone_items%5B%5D=higher-tier\">Higher Tier</a>, <a href=\"/countryside-stewardship-grants?tiers_or_standalone_items%5B%5D=mid-tier\">Mid Tier</a>"
def test_meta(component)
within shared_component_selector(component) do
component_args = JSON.parse(page.text)
assert_equal component_args["other"]["Grant type"], "<a href=\"/countryside-stewardship-grants?grant_type%5B%5D=option\">Option</a>"
assert_equal component_args["other"]["Tiers or standalone items"],
["<a href=\"/countryside-stewardship-grants?tiers_or_standalone_items%5B%5D=higher-tier\">Higher Tier</a>",
"<a href=\"/countryside-stewardship-grants?tiers_or_standalone_items%5B%5D=mid-tier\">Mid Tier</a>"].join(", ")
assert_equal component_args["other"]["Land use"],
["<a href=\"/countryside-stewardship-grants?land_use%5B%5D=arable-land\">Arable land</a>",
"<a href=\"/countryside-stewardship-grants?land_use%5B%5D=wildlife-package\">Wildlife package</a>",
"<a href=\"/countryside-stewardship-grants?land_use%5B%5D=water-quality\">Water quality</a>",
"<a href=\"/countryside-stewardship-grants?land_use%5B%5D=wildlife-package\">Wildlife package</a>"].join(", ")
assert_equal component_args["other"]["Funding (per unit per year)"],
"<a href=\"/countryside-stewardship-grants?funding_amount%5B%5D=more-than-500\">More than £500</a>"
end
end
test_meta("document_footer")
test_meta("metadata")
end

test "renders date facets correctly" do
Expand All @@ -63,6 +76,11 @@ class SpecialistDocumentTest < ActionDispatch::IntegrationTest
component_args = JSON.parse(page.text)
assert_equal component_args["other_dates"]["Issued"], "6 July 2015"
end

within shared_component_selector("metadata") do
component_args = JSON.parse(page.text)
assert_equal component_args["other"]["Issued"], "6 July 2015"
end
end


Expand All @@ -74,6 +92,11 @@ class SpecialistDocumentTest < ActionDispatch::IntegrationTest
component_args = JSON.parse(page.text)
assert_equal component_args["other_dates"], {}
end

within shared_component_selector("metadata") do
component_args = JSON.parse(page.text)
assert_equal component_args["other"], {}
end
end

test "renders a contents list" do
Expand Down

0 comments on commit a591533

Please sign in to comment.