diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 5b053c563..aecc60843 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -61,6 +61,7 @@ def set_guide_draft_access_token def load_content_item content_item = Services.content_store.content_item(content_item_path) @content_item = PresenterBuilder.new(content_item, content_item_path).presenter + @content_item.include_collections_in_other_publisher_metadata = show_new_navigation? end def load_taxonomy_navigation diff --git a/app/presenters/content_item/metadata.rb b/app/presenters/content_item/metadata.rb index 3e4e6610c..6daa7d2e9 100644 --- a/app/presenters/content_item/metadata.rb +++ b/app/presenters/content_item/metadata.rb @@ -20,14 +20,18 @@ def important_metadata end def publisher_metadata - { - published: published, - last_updated: updated, - link_to_history: !!updated, - other: { - 'From': from + {}.tap do |publisher_metadata| + publisher_metadata[:published] = published + publisher_metadata[:last_updated] = updated + publisher_metadata[:link_to_history] = !!updated + publisher_metadata[:other] = { + from: from, } - } + + if include_collections_in_other_publisher_metadata + publisher_metadata[:other][:collections] = links('document_collections') + end + end end end end diff --git a/app/presenters/content_item_presenter.rb b/app/presenters/content_item_presenter.rb index c121346ab..876359e52 100644 --- a/app/presenters/content_item_presenter.rb +++ b/app/presenters/content_item_presenter.rb @@ -14,6 +14,8 @@ class ContentItemPresenter :document_type, :taxons + attr_accessor :include_collections_in_other_publisher_metadata + def initialize(content_item, requested_content_item_path = nil) @content_item = content_item @requested_content_item_path = requested_content_item_path diff --git a/app/views/components/_publisher-metadata.html.erb b/app/views/components/_publisher-metadata.html.erb index 9136eca64..a90742a64 100644 --- a/app/views/components/_publisher-metadata.html.erb +++ b/app/views/components/_publisher-metadata.html.erb @@ -16,10 +16,39 @@ <% values ||= [] values = Array(values) + toggle_id = "app-c-publisher-metadata__definition--#{title.to_s.parameterize(separator: '-')}" %> <% if values.any? %> -
<%= title %>:
-
<%= values.to_sentence.html_safe %>
+
+ <%= t(title.to_s.parameterize(separator: '_'), + scope: 'components.publisher_metadata', + default: title.to_s.humanize) %>: +
+
+ <% if title.to_sym == :collections %> + <% if values.size <= 2 %> + + <%= values.take(2).to_sentence.html_safe %> + + <% else %> + <% featured_value, *other_values = values %> + + <%= featured_value.html_safe %> and <%= pluralize(other_values.size, 'other') %> + + + + <%= t('components.publisher_metadata.show_all') %> + + <%= other_values.to_sentence.html_safe %> + <% end %> + <% else %> + + <%= values.to_sentence.html_safe %> + + <% end %> +
<% end %> <% end %> diff --git a/app/views/components/docs/publisher-metadata.yml b/app/views/components/docs/publisher-metadata.yml index 24bcd88f6..d1d45bd7b 100644 --- a/app/views/components/docs/publisher-metadata.yml +++ b/app/views/components/docs/publisher-metadata.yml @@ -14,7 +14,7 @@ examples: published: 31 July 2017 last_updated: 20 September 2017 other: - From: + from: - Ministry of Defence with_history_link: data: @@ -22,7 +22,7 @@ examples: last_updated: 20 September 2017 link_to_history: true other: - From: + from: - Ministry of Defence no_last_updated: data: @@ -37,7 +37,7 @@ examples: published: 31 July 2017 last_updated: 20 September 2017 other: - From: + from: - Department for Education - Education Funding Agency multiple_publishers_and_no_link_to_history: @@ -45,10 +45,28 @@ examples: published: 31 July 2017 last_updated: 20 September 2017 other: - From: + from: - Department for Education - Education Funding Agency - Department for Work and Pensions + one_collection: + data: + other: + collections: + - Tribunals statistics + two_collections: + data: + other: + collections: + - Tribunals statistics + - Civil justice statistics quarterly + more_than_two_collections: + data: + other: + collections: + - Tribunals statistics + - Civil justice statistics quarterly + - Offender management statistics quarterly nothing: description: | If an `other` object is provided with keys that have no values the component does not render. diff --git a/config/locales/en.yml b/config/locales/en.yml index 74f91695d..e8b7e8fa6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -26,6 +26,11 @@ en: common: last_updated: "Last updated" components: + publisher_metadata: + from: "From" + collections: "Collections" + show_all: "show all" + hide_all: "hide all" related_navigation: collections: "Collection" external_links: "Elsewhere on the web" diff --git a/test/components/publisher_metadata_test.rb b/test/components/publisher_metadata_test.rb index 4387437b9..45bf6f7af 100644 --- a/test/components/publisher_metadata_test.rb +++ b/test/components/publisher_metadata_test.rb @@ -10,7 +10,7 @@ def component_name end test "does not render when an 'other' object is provided without any values" do - assert_empty render_component(other: { From: [] }) + assert_empty render_component(other: { from: [] }) assert_empty render_component(other: { a: false, b: "", c: [], d: {}, e: nil }) end @@ -23,13 +23,13 @@ def component_name test "renders two from links when two publishers are given" do - render_component(other: { From: ["Ministry of Defence", "Education Funding Agency"] }) + render_component(other: { from: ["Ministry of Defence", "Education Funding Agency"] }) assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence' assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/education-funding-agency']", text: 'Education Funding Agency' end test "renders a sentence when multiple publishers are given" do - render_component(other: { From: ["Department for Education", "Education Funding Agency"] }) + render_component(other: { from: ["Department for Education", "Education Funding Agency"] }) assert_select ".app-c-publisher-metadata__other dt", text: 'From:' assert_select ".app-c-publisher-metadata__other dd", text: 'Department for Education and Education Funding Agency' end @@ -45,7 +45,7 @@ def component_name end test "renders full metadata component when all parameters are given" do - render_component(other: { From: ["Ministry of Defence"] }, published: "31 July 2017", last_updated: "20 September 2017", link_to_history: true) + render_component(other: { from: ["Ministry of Defence"] }, published: "31 July 2017", last_updated: "20 September 2017", link_to_history: true) assert_select ".app-c-published-dates" assert_select ".app-c-publisher-metadata__other a[href='/government/organisations/ministry-of-defence']", text: 'Ministry of Defence' assert_select ".app-c-publisher-metadata__other dt", text: 'From:' @@ -53,7 +53,24 @@ def component_name end test "link tracking is enabled" do - render_component(other: { From: ["Ministry of Defence"] }) + render_component(other: { from: ["Ministry of Defence"] }) assert_select ".app-c-publisher-metadata__other dl[data-module='track-click']" end + + test "renders two collection links when two collections are given" do + render_component(other: { collections: ["Tribunals statistics", "Civil justice statistics quarterly"] }) + assert_select ".app-c-publisher-metadata__other dt", text: 'Collections:' + assert_select ".app-c-publisher-metadata__other dd a[href='/government/collections/tribunals-statistics']", text: 'Tribunals statistics' + assert_select ".app-c-publisher-metadata__other dd a[href='/government/collections/civil-justice-statistics-quarterly']", text: 'Civil justice statistics quarterly' + end + + test "renders the first collection and a toggle link when more than two collections are given" do + render_component(other: { collections: ["Tribunals statistics", "Civil justice statistics quarterly", "Offender management statistics quarterly"] }) + assert_select ".app-c-publisher-metadata__other dt", text: 'Collections:' + assert_select ".app-c-publisher-metadata__other .app-c-publisher-metadata__definition_sentence", text: 'Tribunals statistics and 2 others' + assert_select ".app-c-publisher-metadata__other a", text: '+ show all' + assert_select ".app-c-publisher-metadata__other a[href='/government/collections/tribunals-statistics']", text: 'Tribunals statistics' + assert_select ".app-c-publisher-metadata__other a[href='/government/collections/civil-justice-statistics-quarterly']", text: 'Civil justice statistics quarterly' + assert_select ".app-c-publisher-metadata__other a[href='/government/collections/offender-management-statistics-quarterly']", text: 'Offender management statistics quarterly' + end end diff --git a/test/integration/content_pages_related_navigation_test.rb b/test/integration/content_pages_related_navigation_test.rb index bf6641699..3591b9fb8 100644 --- a/test/integration/content_pages_related_navigation_test.rb +++ b/test/integration/content_pages_related_navigation_test.rb @@ -35,6 +35,29 @@ def setup refute page.has_css?('.gem-c-related-navigation__sub-heading', text: 'Collection') end + test "ContentPagesNav variant A does not show collections as publisher metadata" do + stub_rummager + setup_variant_a + + setup_and_visit_content_item_with_taxons('case_study', SINGLE_TAXON) + + within '.app-c-publisher-metadata' do + refute page.has_css?('.app-c-publisher-metadata__term', text: 'Collections') + end + end + + test "ContentPagesNav variant B shows collections as publisher metadata" do + stub_rummager + setup_variant_b + + setup_and_visit_content_item_with_taxons('case_study', SINGLE_TAXON) + + within '.app-c-publisher-metadata' do + assert page.has_css?('.app-c-publisher-metadata__term', text: 'Collections') + assert page.has_css?('.app-c-publisher-metadata__definition a', text: 'Work Programme real life stories') + end + end + def setup_variant_a ContentItemsController.any_instance.stubs(:show_new_navigation?).returns(false) end