diff --git a/app/presenters/content_item/withdrawable.rb b/app/presenters/content_item/withdrawable.rb index c0733e09d..67b528dd2 100644 --- a/app/presenters/content_item/withdrawable.rb +++ b/app/presenters/content_item/withdrawable.rb @@ -5,7 +5,15 @@ def withdrawn? end def page_title - withdrawn? ? "[Withdrawn] #{title}" : title + if withdrawn? && context_title? && publication_overview? + "[Withdrawn] #{context_title}: #{title}" + elsif withdrawn? + "[Withdrawn] #{title}" + elsif context_title? && publication_overview? + "#{context_title}: #{title}" + else + title + end end def withdrawal_notice_component @@ -21,6 +29,19 @@ def withdrawal_notice_component private + def context_title? + context_title.present? + end + + def publication_overview? + publication_overview.present? + end + + def publication_overview + overview = (I18n.exists?("content_item.#{schema_name}") == "publication" || "statistical_data_set") + overview.presence + end + def withdrawal_notice content_item["withdrawn_notice"] end @@ -29,6 +50,12 @@ def withdrawal_notice_title "This #{withdrawal_notice_context.downcase} was withdrawn on #{withdrawal_notice_time}".html_safe end + def context_title + if I18n.exists?("content_item.schema_name.#{document_type}", count: 1, locale: :en) + I18n.t("content_item.schema_name.#{document_type}", count: 1, locale: :en) + end + end + def withdrawal_notice_context I18n.t("content_item.schema_name.#{schema_name}", count: 1, locale: :en) end diff --git a/app/views/content_items/_context_and_title.html.erb b/app/views/content_items/_context_and_title.html.erb index c68512a07..6eb2b7b7b 100644 --- a/app/views/content_items/_context_and_title.html.erb +++ b/app/views/content_items/_context_and_title.html.erb @@ -1,26 +1,7 @@ -<% - context_string = t("content_item.schema_name.#{@content_item.document_type}", count: 1); - context_inside = false; - %> - -<% @content_item&.featured_attachments.each do |fa| %> - <% return if !@content_item.attachment_details(fa).present? %> - <% if @content_item.attachment_details(fa)['title'] == @content_item.title %> - <% content_for :title do %> - <%= t("content_item.schema_name.#{@content_item.document_type}.overview", count: 1) %>: <%= @content_item.title %> - <% end %> - <% - context_string = t("content_item.schema_name.#{@content_item.document_type}.overview", count: 1) << ":" - context_inside = true - %> - <% break %> - <% end %> -<% end %> - <%= render 'govuk_publishing_components/components/title', - context: context_string, - context_locale: t_locale_fallback("content_item.schema_name.#{@content_item.document_type}", count: 1), - context_inside: context_inside, + context: t("content_item.schema_name.#{@content_item.document_type}", count: 1) << ":", + context_locale: t_locale_fallback("content_item.schema_name.#{@content_item.document_type}", count: 1) , + context_inside: true, title: @content_item.title, average_title_length: "long" %> diff --git a/test/integration/fatality_notice_test.rb b/test/integration/fatality_notice_test.rb index 7fbd034f7..5b5b3be4b 100644 --- a/test/integration/fatality_notice_test.rb +++ b/test/integration/fatality_notice_test.rb @@ -69,7 +69,7 @@ class FatalityNoticeTest < ActionDispatch::IntegrationTest setup_and_visit_content_item("withdrawn_fatality_notice") assert page.has_title?( - "[Withdrawn] Sir George Pomeroy Colley killed in Boer War - Fatality notice - GOV.UK", + "[Withdrawn] Fatality notice: Sir George Pomeroy Colley killed in Boer War - Fatality notice - GOV.UK", ) within ".gem-c-notice" do diff --git a/test/presenters/content_item/withdrawable_test.rb b/test/presenters/content_item/withdrawable_test.rb index 8935465c9..4d19b9be6 100644 --- a/test/presenters/content_item/withdrawable_test.rb +++ b/test/presenters/content_item/withdrawable_test.rb @@ -33,17 +33,26 @@ def title content_item["title"] end + def schema_name + content_item["schema_name"] + end + + def document_type + content_item["document_type"] + end + def content_item { "title" => "Proportion of residents who do any walking or cycling (at local authority level) (CW010)", "withdrawn_notice" => { "withdrawn_at" => "2016-07-12T09:47:15Z", }, + "document_type" => "statistical_data_set", } end end - assert_equal @withdrawable.page_title, "[Withdrawn] Proportion of residents who do any walking or cycling (at local authority level) (CW010)" + assert_equal @withdrawable.page_title, "[Withdrawn] Statistical data set: Proportion of residents who do any walking or cycling (at local authority level) (CW010)" end test "notice title and description are generated correctly" do