summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-12 02:15:44 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-12 02:15:44 +0200
commit45bf65d04d046c0ea4a1150096b2a9b846d6c0b8 (patch)
tree24dad426779cb3b0ac59c405245aac1d28109982 /test
parent13c8cb415813e90c883a44b0c0888382161de92a (diff)
Give the sitemap its own view, with collapse and descendant counts
Extracted from admin#index's inline table into NodesController#sitemap. Nested <details>/<summary> per branch, one linear pass over the existing flat [node, level] list (no added queries) -- each node's own descendant count computed the same way, via a small stack rather than re-walking the tree per node. Branches under updates/, club/erfas, club/chaostreffs, and disclosure start collapsed by default (CccConventions::SITEMAP_COLLAPSED_PATHS); any branch currently collapsed, whether by that default or because someone just closed it, is highlighted via a plain :not([open]) selector -- no state tracked outside the DOM itself. Dropped the update?-post exclusion this view used to rely on -- no longer needed now that updates/ collapses instead of being filtered out, so its real children (previously silently absent) now show up correctly. admin#index's own, separate @sitemap query is unchanged; that view has no collapse mechanism to compensate and wasn't part of this.
Diffstat (limited to 'test')
-rw-r--r--test/controllers/nodes_controller_test.rb52
-rw-r--r--test/models/helpers/nodes_helper_test.rb11
2 files changed, 63 insertions, 0 deletions
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb
index 05cb195..b43d2de 100644
--- a/test/controllers/nodes_controller_test.rb
+++ b/test/controllers/nodes_controller_test.rb
@@ -575,4 +575,56 @@ class NodesControllerTest < ActionController::TestCase
575 get :chapters 575 get :chapters
576 assert_select "h1", "Chapters" 576 assert_select "h1", "Chapters"
577 end 577 end
578
579 test "sitemap collapses configured paths but leaves others open" do
580 club = Node.root.children.create!(:slug => "club")
581 erfas = club.children.create!(:slug => "erfas")
582 erfas.children.create!(:slug => "one_chapter")
583 other = Node.root.children.create!(:slug => "sitemap_controller_open_test")
584 other.children.create!(:slug => "sitemap_controller_open_child")
585
586 login_as :quentin
587 get :sitemap
588 assert_response :success
589
590 doc = Nokogiri::HTML::DocumentFragment.parse(response.body)
591
592 erfas_node_div = doc.css('.sitemap_node').find { |div| div.at_css('.field_hint')&.text&.include?(erfas.unique_name) }
593 other_node_div = doc.css('.sitemap_node').find { |div| div.at_css('.field_hint')&.text&.include?(other.unique_name) }
594
595 erfas_details = erfas_node_div.next_element
596 other_details = other_node_div.next_element
597
598 assert_equal 'details', erfas_details.name
599 assert_equal 'details', other_details.name
600 assert_not erfas_details.key?('open')
601 assert other_details.key?('open')
602 end
603
604 test "sitemap shows how many descendants a collapsed branch is hiding" do
605 club = Node.root.children.create!(:slug => "club")
606 erfas = club.children.create!(:slug => "erfas")
607 erfas.children.create!(:slug => "one_chapter")
608 erfas.children.create!(:slug => "another_chapter")
609
610 login_as :quentin
611 get :sitemap
612 assert_response :success
613
614 doc = Nokogiri::HTML::DocumentFragment.parse(response.body)
615 erfas_node_div = doc.css('.sitemap_node').find { |div| div.at_css('.field_hint')&.text&.include?(erfas.unique_name) }
616 erfas_details = erfas_node_div.next_element
617
618 assert_equal 'details', erfas_details.name
619 assert_match "2 descendants", erfas_details.at_css('summary').text
620 end
621
622 test "sitemap shows Show and Create Child, not Revisions" do
623 node = Node.root.children.create!(:slug => "sitemap_actions_test")
624 login_as :quentin
625 get :sitemap
626 assert_select ".sitemap_node_actions", :text => /Show/
627 assert_select ".sitemap_node_actions", :text => /Create Child/
628 assert_select ".sitemap_node_actions", :text => /Revisions/, :count => 0
629 end
578end 630end
diff --git a/test/models/helpers/nodes_helper_test.rb b/test/models/helpers/nodes_helper_test.rb
index 5d91a88..5ab924f 100644
--- a/test/models/helpers/nodes_helper_test.rb
+++ b/test/models/helpers/nodes_helper_test.rb
@@ -22,4 +22,15 @@ class NodesHelperTest < ActionView::TestCase
22 page = FakePage.new([]) 22 page = FakePage.new([])
23 assert_nil default_event_tag_list(page) 23 assert_nil default_event_tag_list(page)
24 end 24 end
25
26 test "sitemap_node_open? is false for a configured collapsed path" do
27 club = Node.root.children.create!(:slug => "club")
28 erfas = club.children.create!(:slug => "erfas")
29 assert_equal false, sitemap_node_open?(erfas)
30 end
31
32 test "sitemap_node_open? is true for anything not configured as collapsed" do
33 node = Node.root.children.create!(:slug => "sitemap_open_test")
34 assert_equal true, sitemap_node_open?(node)
35 end
25end 36end