diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index 5b053c5634..aecc60843f 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 3e4e6610c2..6daa7d2e96 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 c121346aba..876359e522 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 9136eca641..b6c55968e8 100644 --- a/app/views/components/_publisher-metadata.html.erb +++ b/app/views/components/_publisher-metadata.html.erb @@ -16,10 +16,33 @@ <% 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 == :collections %> + <% if values.size <= 2 %> + <%= values.take(2).to_sentence.html_safe %> + <% else %> + <% featured_values, *other_values = values %> + <%= featured_values %> 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/config/locales/en.yml b/config/locales/en.yml index 74f91695d4..e8b7e8fa64 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/integration/content_pages_related_navigation_test.rb b/test/integration/content_pages_related_navigation_test.rb index bf66416997..3591b9fb83 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