Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: alphagov/government-frontend
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bb4e9841f8e05d7d63a2d79e56c91c9f220cbc5f
Choose a base ref
..
head repository: alphagov/government-frontend
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 872a75664662e33e4990bd8f3485220486734e4a
Choose a head ref
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@ GEM
govuk_personalisation (1.0.0)
plek (>= 1.9.0)
rails (>= 6, < 8)
govuk_publishing_components (44.0.0)
govuk_publishing_components (44.2.0)
govuk_app_config
govuk_personalisation (>= 0.7.0)
kramdown
@@ -639,7 +639,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.18)
zeitwerk (2.7.0)

PLATFORMS
ruby
7 changes: 0 additions & 7 deletions app/presenters/content_item/contents_list.rb
Original file line number Diff line number Diff line change
@@ -109,12 +109,5 @@ def first_item
def no_first_item?
first_item.nil?
end

def exclude_contents_list_for_manual_section?
# MOJ require contents lists for manual section pages.

moj_content = content_item.dig("links", "organisations", 0, "content_id") == "dcc907d6-433c-42df-9ffb-d9c68be5dc4d"
document_type == "manual_section" && !moj_content
end
end
end
10 changes: 10 additions & 0 deletions app/presenters/manual_section_presenter.rb
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ class ManualSectionPresenter < ContentItemPresenter
include ContentItem::ContentsList
include ContentItem::ManualSection

MOJ_ORGANISATION_CONTENT_ID = "dcc907d6-433c-42df-9ffb-d9c68be5dc4d".freeze

def base_path
manual["base_path"]
end
@@ -52,6 +54,14 @@ def main
end
end

def show_contents_list?
organisation_content_id == MOJ_ORGANISATION_CONTENT_ID
end

def organisation_content_id
content_item.dig("links", "organisations", 0, "content_id")
end

private

def manual
33 changes: 2 additions & 31 deletions test/presenters/content_item/contents_list_test.rb
Original file line number Diff line number Diff line change
@@ -2,20 +2,9 @@

class ContentItemContentsListTest < ActiveSupport::TestCase
def setup
content_item = {
"title" => "thing",
"document_type" => "manual_section",
"links" => {
"organisations" => [
{
"content_id" => "dcc907d6-433c-42df-9ffb-d9c68be5dc4d",
},
],
},
}
content_item = { "title" => "thing" }
@contents_list = Object.new
@contents_list.stubs(:content_item).returns(content_item)
@contents_list.stubs(:document_type).returns(content_item["document_type"])
@contents_list.stubs(:view_context)
.returns(ApplicationController.new.view_context)
@contents_list.extend(ContentItem::ContentsList)
@@ -107,25 +96,7 @@ def body
assert @contents_list.show_contents_list?
end

test "#show_contents_list? returns false if the content item is a manual section but excluded from displaying content lists" do
content_item = {
"title" => "thing",
"document_type" => "manual_section",
"links" => {
"organisations" => [
{
"content_id" => "91cd6143-69d5-4f27-99ff-a52fb0d51c74",
},
],
},
}

@contents_list.stubs(:content_item).returns(content_item)
@contents_list.stubs(:document_type).returns(content_item["document_type"])
assert_not @contents_list.show_contents_list?
end

test "#show_contents_list? returns true if the first item's character count is above 415 including a list" do
test "#show_contents_list? returns true if number of contents items is 2 and the first item's character count is above 415 including a list" do
class << @contents_list
def body
"<h2 id='one'>One</h2>
14 changes: 14 additions & 0 deletions test/presenters/manual_section_presenter_test.rb
Original file line number Diff line number Diff line change
@@ -76,6 +76,20 @@ class PresentedManualSectionTest < ManualSectionPresenterTestCase
assert_match first_section_content_sample, presented_manual_section.main.first[:content]
end

test "hides the contents list by default" do
manual_section = schema_item("what-is-content-design")
assert_equal false, present_example(manual_section).show_contents_list?
end

test "shows the contents list if organisation is MOJ" do
content_item = schema_item("what-is-content-design", "manual_section")
moj_content_id = ManualSectionPresenter::MOJ_ORGANISATION_CONTENT_ID
content_item["links"]["organisations"] = [{ "content_id" => moj_content_id }]
presented = present_example(content_item)

assert_equal true, presented.show_contents_list?
end

def presented_manual_section(overrides = {})
presented_item("what-is-content-design", overrides)
end