diff --git a/app/models/landing_page/block/document_list.rb b/app/models/landing_page/block/document_list.rb index bd818cdd11..c0efef59cd 100644 --- a/app/models/landing_page/block/document_list.rb +++ b/app/models/landing_page/block/document_list.rb @@ -1,6 +1,6 @@ module LandingPage::Block class DocumentList < Base - attr_reader :taxon_base_path + attr_reader :taxon_base_path, :heading TAXON_SEARCH_FIELDS = %w[title link @@ -12,6 +12,7 @@ def initialize(block_hash, landing_page) super @taxon_base_path = data["taxon_base_path"] + @heading = data["heading"] end def full_width? diff --git a/app/models/landing_page/block/press_notices.rb b/app/models/landing_page/block/press_notices.rb deleted file mode 100644 index 12217a878a..0000000000 --- a/app/models/landing_page/block/press_notices.rb +++ /dev/null @@ -1,4 +0,0 @@ -module LandingPage::Block - class PressNotices < DocumentList - end -end diff --git a/app/views/landing_page/blocks/_document_list.html.erb b/app/views/landing_page/blocks/_document_list.html.erb index fe463546f2..bc414195ac 100644 --- a/app/views/landing_page/blocks/_document_list.html.erb +++ b/app/views/landing_page/blocks/_document_list.html.erb @@ -1,4 +1,15 @@ -<%= render "govuk_publishing_components/components/document_list", { - margin_bottom: 4, - items: block.items, -} %> +<% heading = block.heading || "Latest Updates" %> + +<% if block.items.any? %> + <%= render "govuk_publishing_components/components/heading", { + text: heading, + padding: true, + border_top: 5, + margin_bottom: 3 + } %> + + <%= render "govuk_publishing_components/components/document_list", { + margin_bottom: 0, + items: block.items, + } %> +<% end %> diff --git a/app/views/landing_page/blocks/_press_notices.html.erb b/app/views/landing_page/blocks/_press_notices.html.erb deleted file mode 100644 index 97f498ed8e..0000000000 --- a/app/views/landing_page/blocks/_press_notices.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -<% if block.items.any? %> - <%= render "govuk_publishing_components/components/heading", { - text: "Press Notices", - padding: true, - border_top: 5, - margin_bottom: 3 - } %> - - <%= render "govuk_publishing_components/components/document_list", { - margin_bottom: 0, - items: block.items, - } %> -<% end %> diff --git a/docs/building_blocks_for_flexible_content.md b/docs/building_blocks_for_flexible_content.md index b716afe214..e978e78861 100644 --- a/docs/building_blocks_for_flexible_content.md +++ b/docs/building_blocks_for_flexible_content.md @@ -36,7 +36,6 @@ Simple blocks generally render one component or "thing". They can either be rend - [Heading](#heading) - [Image](#image) - [Main Navigation](#main-navigation) -- [Press notices](#press-notices) - [Quote](#quote) - [Share links](#share-links) - [Side Navigation](#side-navigation) @@ -64,14 +63,17 @@ A wrapper around the [Big number component](https://components.publishing.servic #### Document list -A wrapper around the [Document list component](https://components.publishing.service.gov.uk/component-guide/document_list) +A wrapper around the [Document list component](https://components.publishing.service.gov.uk/component-guide/document_list) with a title that will only appear if there are any items in the list (if the list is entirely empty the heading will not appear either) The document list can either be populated with the most recent content tagged to a taxon or from a hard-coded list. If the `taxon_base_path` is provided and the taxon exists and it has content tagged to it, the document list will be populated with that content. If not, it will default to the hard-coded list. +If the `heading` is provided that will be used, otherwise it will default to the hard-coded heading. + ```yaml - type: document_list + heading: My Favourite Things taxon_base_path: /government/government-efficiency-transparency-and-accountability items: - text: An example link @@ -159,34 +161,6 @@ The top-level navigation. It supports multiple headings, each with a row of link navigation_group_id: Top Menu ``` -#### Press notices - -A wrapper around the [Document list component](https://components.publishing.service.gov.uk/component-guide/document_list) with a hardcoded title that will only appear if there are any items in the list (if the list is entirely empty the heading will not appear either) - -The document list can either be populate with the most recent content tagged to a taxon, or from a hard-coded list. - -If the `taxon_base_path` is provided, the taxon exists and it has content tagged to it, the document list will be populated with that content, otherwise it will default to the hard-coded list. - -##### Example - -```yaml -- type: press_notices - taxon_base_path: /government/government-efficiency-transparency-and-accountability - items: - - text: An example link - path: https://www.gov.uk - document_type: Press release - public_updated_at: "2016-06-27 10:29:44 +0000" - - text: Another example link - path: https://www.gov.uk - document_type: News article - public_updated_at: "2021-01-16 11:34:12 +0000" - - text: A third example link - path: https://www.gov.uk - document_type: Consultation - public_updated_at: "2024-02-01 09:00:11 +0000" - - #### Quote A blockquote. diff --git a/lib/data/landing_page_content_items/tasks.yaml b/lib/data/landing_page_content_items/tasks.yaml index 3ecfa28790..bc801d36c3 100644 --- a/lib/data/landing_page_content_items/tasks.yaml +++ b/lib/data/landing_page_content_items/tasks.yaml @@ -176,7 +176,8 @@ blocks: - type: two_column_layout theme: two_thirds_one_third blocks: - - type: press_notices + - type: document_list + heading: "Latest things" items: - text: An example title for this press notice 1 path: "https://www.gov.uk" diff --git a/spec/models/landing_page/block/document_list_spec.rb b/spec/models/landing_page/block/document_list_spec.rb index ec4ba9a4b5..7c43d0bccb 100644 --- a/spec/models/landing_page/block/document_list_spec.rb +++ b/spec/models/landing_page/block/document_list_spec.rb @@ -1,8 +1,6 @@ -require "gds_api/test_helpers/search" - RSpec.describe LandingPage::Block::DocumentList do - include GdsApi::TestHelpers::Search include ContentStoreHelpers + include SearchHelpers describe "#items" do context "when the list is hard-coded" do @@ -133,24 +131,4 @@ end end end - - def stub_taxon_search_results - results = [ - { - "title" => "Doc one", - "link" => "/doc-one", - "description" => "Doc one description", - "format" => "press_release", - "public_timestamp" => Time.zone.local(2024, 1, 1, 10, 24, 0), - }, - ] - - body = { - "results" => results, - "start" => "0", - "total" => results.size, - } - - stub_any_search.to_return("body" => body.to_json) - end end diff --git a/spec/models/landing_page/block/press_notices_spec.rb b/spec/models/landing_page/block/press_notices_spec.rb deleted file mode 100644 index cf98d186e3..0000000000 --- a/spec/models/landing_page/block/press_notices_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -RSpec.describe LandingPage::Block::PressNotices do - let(:blocks_hash) do - { "type" => "press_notices", - "items" => [ - { "text" => "link 1", "path" => "/a-link", "document_type" => "Press release", "public_updated_at" => "2024-01-01 10:24:00" }, - { "text" => "link 2", "path" => "/another-link", "document_type" => "Press release", "public_updated_at" => "2023-01-01 10:24:00" }, - ] } - end - - describe "#items" do - it "returns an array of link details" do - result = described_class.new(blocks_hash, build(:landing_page)).items - expect(result.size).to eq 2 - expect(result.first).to eq(link: { text: "link 1", path: "/a-link" }, metadata: { document_type: "Press release", public_updated_at: "2024-01-01 10:24:00" }) - expect(result.second).to eq(link: { text: "link 2", path: "/another-link" }, metadata: { document_type: "Press release", public_updated_at: "2023-01-01 10:24:00" }) - end - end -end diff --git a/spec/support/search_helpers.rb b/spec/support/search_helpers.rb new file mode 100644 index 0000000000..e6a489f049 --- /dev/null +++ b/spec/support/search_helpers.rb @@ -0,0 +1,28 @@ +require "govuk_schemas" +require "gds_api/test_helpers/search" + +module SearchHelpers + include GdsApi::TestHelpers::Search + + def stub_taxon_search_results(slug = "doc-one") + title = slug.tr("-", " ").capitalize + + results = [ + { + "title" => title, + "link" => "/#{slug}", + "description" => "#{title} description", + "format" => "press_release", + "public_timestamp" => Time.zone.local(2024, 1, 1, 10, 24, 0), + }, + ] + + body = { + "results" => results, + "start" => "0", + "total" => results.size, + } + + stub_any_search.to_return("body" => body.to_json) + end +end diff --git a/spec/system/landing_page_spec.rb b/spec/system/landing_page_spec.rb index 467a107e73..76f1cc741d 100644 --- a/spec/system/landing_page_spec.rb +++ b/spec/system/landing_page_spec.rb @@ -1,7 +1,5 @@ -require "gds_api/test_helpers/search" - RSpec.describe "LandingPage" do - include GdsApi::TestHelpers::Search + include SearchHelpers context "show" do let(:content_item) do @@ -46,7 +44,7 @@ stub_content_store_has_item(base_path, content_item) stub_request(:get, %r{/media/000000000000000000000001/data_one.csv}).to_return(status: 200, body: File.read("spec/fixtures/landing_page_statistics_data/data_one.csv"), headers: {}) stub_content_store_has_item(basic_taxon["base_path"], basic_taxon) - stub_any_search_to_return_no_results + stub_taxon_search_results end it "displays the page" do @@ -95,5 +93,12 @@ assert_selector ".govuk-breadcrumbs" end + + it "renders a document list" do + visit base_path + + assert_selector ".gem-c-heading" + assert_selector ".gem-c-document-list" + end end end