Skip to content

Commit

Permalink
Add collections to publisher metadata if B variant
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgarner committed Aug 15, 2018
1 parent a3a949f commit 2fb963f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions app/presenters/content_item/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions app/views/components/_publisher-metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,33 @@
<%
values ||= []
values = Array(values)
toggle_id = "app-c-publisher-metadata__definition--#{title.to_s.parameterize(separator: '-')}"
%>
<% if values.any? %>
<dt class="app-c-publisher-metadata__term"><%= title %>: </dt>
<dd class="app-c-publisher-metadata__definition"><%= values.to_sentence.html_safe %></dd>
<dt class="app-c-publisher-metadata__term">
<%= t(title.to_s.parameterize(separator: '_'),
scope: 'components.publisher_metadata',
default: title.to_s.humanize) %>:
</dt>
<dd class="app-c-publisher-metadata__definition" data-module="gem-toggle">
<% 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') %>
<a href="#"
data-controls="<%= toggle_id %>"
data-expanded="false"
data-toggled-text="&minus; <%= t('components.publisher_metadata.hide_all') %>">
+ <%= t('components.publisher_metadata.show_all') %>
</a>
<span id="<%= toggle_id %>" class="js-hidden"><%= other_values.to_sentence.html_safe %></span>
<% end %>
<% else %>
<%= values.to_sentence.html_safe %>
<% end %>
</dd>
<% end %>
<% end %>
</dl>
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions test/integration/content_pages_related_navigation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fb963f

Please sign in to comment.