Skip to content

Commit

Permalink
Dont show see all udpdates links for pending stats pages
Browse files Browse the repository at this point in the history
  • Loading branch information
georges1996 committed Feb 6, 2024
1 parent 7e3e1fc commit 547d3da
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 12 deletions.
16 changes: 14 additions & 2 deletions app/presenters/content_item/manual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ def other_metadata
end

def updated_metadata(updated_at)
updates_link = view_context.link_to(I18n.t("manuals.see_all_updates"), "#{base_path}/updates")
{ I18n.t("manuals.updated") => "#{display_date(updated_at)}, #{updates_link}" }
current_path = view_context.request.path

if (hmrc? || manual?) && current_path == "#{base_path}/updates"
update_at_text = display_date(updated_at).to_s
else
updates_link = view_context.link_to(I18n.t("manuals.see_all_updates"), "#{base_path}/updates")
update_at_text = "#{display_date(updated_at)} - #{updates_link}"
end

{ I18n.t("manuals.updated") => update_at_text }
end

def details
Expand All @@ -55,5 +63,9 @@ def details
def hmrc?
%w[hmrc_manual hmrc_manual_section].include?(schema_name)
end

def manual?
%w[manual manual_section].include?(schema_name)
end
end
end
14 changes: 12 additions & 2 deletions app/presenters/content_item/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ def important_metadata
end

def publisher_metadata
{
display_date = details_display_date
metadata = {
from:,
first_published: published,
last_updated: updated,
see_updates_link: true,
}

unless display_date.present? && Time.zone.parse(display_date).future?
metadata[:see_updates_link] = true
end

metadata
end

def details_display_date
content_item["details"]["display_date"]
end
end
end
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ en:
hide_all_updates: hide all updates
last_updated: Last updated %{date}
published: Published %{date}
see_all_updates: see all updates
see_all_updates: See all updates
show_all_updates: show all updates
publisher_metadata:
hide_all: hide all
Expand Down Expand Up @@ -484,7 +484,7 @@ en:
pages_in_manual_section: Manual section pages
previous_page: Previous page
search_this_manual: Search this manual
see_all_updates: see all updates
see_all_updates: See all updates
title: "%{title}Guidance"
updated: Updated
updates_amendments: published amendments
Expand Down
4 changes: 1 addition & 3 deletions test/integration/hmrc_manual_updates_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class HmrcManualUpdatesTest < ActionDispatch::IntegrationTest
{
from: { "HM Revenue & Customs": "/government/organisations/hm-revenue-customs" },
first_published: "11 February 2015",
other: {
I18n.t("manuals.see_all_updates") => "#{@content_item['base_path']}/updates",
},
other: {},
},
extra_metadata_classes: ".gem-c-metadata--inverse",
)
Expand Down
4 changes: 1 addition & 3 deletions test/integration/manual_updates_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class ManualUpdatesTest < ActionDispatch::IntegrationTest
{
from: { "Government Digital Service": "/government/organisations/government-digital-service" },
first_published: "27 April 2015",
other: {
I18n.t("manuals.see_all_updates") => "#{@content_item['base_path']}/updates",
},
other: {},
},
extra_metadata_classes: ".gem-c-metadata--inverse",
)
Expand Down
61 changes: 61 additions & 0 deletions test/presenters/content_item/metadata_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require "test_helper"

class ContentItemMetadataTest < ActiveSupport::TestCase
class DummyContentItem
include ContentItem::Metadata
attr_reader :content_item, :view_context, :base_path, :public_updated_at, :title, :schema_name

def initialize(schema_name = "manual")
@view_context = ApplicationController.new.view_context
@content_item = {
"title" => "Super title",
"base_path" => "/a/base/path",
"public_updated_at" => "2022-03-23T08:30:20.000+00:00",
"schema_name" => schema_name,
"details" => {
"body" => "body",
"child_section_groups" => [{ "title" => "thing" }],
"display_date" => "23 March 2000",
},
"links" => {
"organisations" => [
{ "content_id" => SecureRandom.uuid, "title" => "blah", "base_path" => "/blah" },
],
},
}
@base_path = content_item["base_path"]
@public_updated_at = content_item["public_updated_at"]
@title = content_item["title"]
@schema_name = content_item["schema_name"]
end
end

test "returns see_updates_link true if published" do
item = DummyContentItem.new
item.stubs(:display_date).returns("23 March 2000")

expected_publisher_metadata = {
from: ["<a class=\"govuk-link\" href=\"/blah\">blah</a>"],
first_published: "23 March 2000",
last_updated: nil,
see_updates_link: true,
}

assert_equal expected_publisher_metadata, item.publisher_metadata
end

test "does not return see_updates_link if pending" do
item = DummyContentItem.new
item.stubs(:display_date).returns("23 March 3000")

item.content_item["details"]["display_date"] = "23 March 3000"

expected_publisher_metadata = {
from: ["<a class=\"govuk-link\" href=\"/blah\">blah</a>"],
first_published: "23 March 3000",
last_updated: nil,
}

assert_equal expected_publisher_metadata, item.publisher_metadata
end
end

0 comments on commit 547d3da

Please sign in to comment.