diff --git a/app/presenters/document_collection_presenter.rb b/app/presenters/document_collection_presenter.rb
index 67440920c..282d76d90 100644
--- a/app/presenters/document_collection_presenter.rb
+++ b/app/presenters/document_collection_presenter.rb
@@ -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
diff --git a/test/integration/document_collection_test.rb b/test/integration/document_collection_test.rb
index d3c4e27d3..4edcde5d2 100644
--- a/test/integration/document_collection_test.rb
+++ b/test/integration/document_collection_test.rb
@@ -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
+
+
#{Faker::Lorem.characters(number: 200)}
+
#{Faker::Lorem.characters(number: 200)}
+
#{Faker::Lorem.characters(number: 200)}
+
+ HTML
+
+ content_item["details"]["collection_groups"] = [
+ {
+ "body" => "\n
",
+ "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
@@ -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
diff --git a/test/presenters/document_collection_presenter_test.rb b/test/presenters/document_collection_presenter_test.rb
index efe9d7cd2..e2b782b8f 100644
--- a/test/presenters/document_collection_presenter_test.rb
+++ b/test/presenters/document_collection_presenter_test.rb
@@ -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 = 'Heading with Spaces
'