Skip to content

Commit

Permalink
Merge pull request #3507 from alphagov/3148-enable-headings-in-body-t…
Browse files Browse the repository at this point in the history
…ext-on-document-collections-to-appear-in-contents-section-m

Enable headings in body text on document collections to appear in contents section
  • Loading branch information
unoduetre authored Jan 9, 2025
2 parents f5278f0 + 4cb2b15 commit 449d130
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/presenters/document_collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DocumentCollectionPresenter < ContentItemPresenter
include DocumentCollection::SignupLink

def contents_items
groups.map do |group|
super + groups.map do |group|
title = group["title"]
{ text: title, id: group_title_id(title) }
end
Expand Down
32 changes: 30 additions & 2 deletions test/integration/document_collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,33 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest
assert page.has_css?(".gem-c-contents-list", text: "Contents")
end

test "renders no contents list if body has multiple h2s and is long, but collection groups are empty" do
test "renders no contents list if body has no h2s and is long and collection groups are empty" do
content_item = get_content_example("document_collection")

content_item["details"]["body"] = <<~HTML
<div class="empty group">
<p>#{Faker::Lorem.characters(number: 200)}</p>
<p>#{Faker::Lorem.characters(number: 200)}</p>
<p>#{Faker::Lorem.characters(number: 200)}</p>
</div>
HTML

content_item["details"]["collection_groups"] = [
{
"body" => "<div class=\"empty group\">\n</div>",
"documents" => [],
"title" => "Empty Group",
},
]

content_item["base_path"] += "-no-h2s"

stub_content_store_has_item(content_item["base_path"], content_item.to_json)
visit(content_item["base_path"])
assert_not page.has_css?(".gem-c-contents-list")
end

test "renders contents list if body has h2s and collection groups are empty" do
content_item = get_content_example("document_collection")

content_item["details"]["body"] = <<~HTML
Expand All @@ -72,9 +98,11 @@ class DocumentCollectionTest < ActionDispatch::IntegrationTest
},
]

content_item["base_path"] += "-h2s"

stub_content_store_has_item(content_item["base_path"], content_item.to_json)
visit(content_item["base_path"])
assert_not page.has_css?(".gem-c-contents-list")
assert page.has_css?(".gem-c-contents-list")
end

test "renders each collection group" do
Expand Down
9 changes: 9 additions & 0 deletions test/presenters/document_collection_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ class PresentedDocumentCollection < TestCase
assert_equal contents, presented_item.contents
end

test "presents a contents list based on body h2 headers and collection groups" do
contents = [
{ text: "Consolidated list", id: "consolidated-list", href: "#consolidated-list" },
{ text: "Documents", id: "documents", href: "#documents" },
]

assert_equal contents, presented_item("document_collection_with_body").contents
end

test "presents a group heading with generated ID" do
heading = '<h3 class="govuk-heading-m govuk-!-font-size-27" id="heading-with-spaces">Heading with Spaces</h3>'

Expand Down

0 comments on commit 449d130

Please sign in to comment.