mdbook/tests/gui/heading-nav-collapsed.goml
Eric Huss 5282083dec Fix heading nav with folded chapters
This fixes an issue when folding is enabled. The folding was not
properly hiding the sub-chapters because it was assuming it could hide
the next list element. However, the heading nav was the next list
element, so the remaining chapters remained visible.

The solution required some deeper changes to how the chapters were
organized in the sidebar. Instead of nested chapters being a list
element *sibling*, the nested chapter's `ol` is now a *child* of its
parent chapter. This makes it much easier to just hide everything
without regard of the exact sibling order.

This required wrapping the chapter title and the toggle chevron inside a
span so that the flex layout could be localized to just those elements,
and allow the following `ol` elements to lay out regularly.

Closes https://github.com/rust-lang/mdBook/issues/2880
2025-10-20 17:31:40 -07:00

56 lines
3.2 KiB
Text

// Tests for collapsed heading sidebar navigation.
set-window-size: (1400, 800)
go-to: |DOC_PATH| + "heading-nav/collapsed.html"
assert-count: (".header-item", 11)
assert-count: (".current-header", 1)
assert-text: (".current-header", "Heading 1")
// Collapsed elements do not have "expanded" class.
assert-attribute: ("li:has(> span > a[href='#heading-12'])", {"class": "header-item"})
assert-attribute: ("li:has(> span > a[href='#heading-21'])", {"class": "header-item"})
// Click 1.2, expands it.
click: "a.header-in-summary[href='#heading-12']"
assert-attribute: ("li:has(> span > a[href='#heading-12'])", {"class": "header-item expanded"})
assert-attribute: ("li:has(> span > a[href='#heading-21'])", {"class": "header-item"})
assert-css: ("//a[@href='#heading-12']/../following-sibling::ol", {"display": "block"})
// Click 1.1, should collapse it.
click: "a.header-in-summary[href='#heading-11']"
assert-attribute: ("li:has(> span > a[href='#heading-12'])", {"class": "header-item"})
assert-attribute: ("li:has(> span > a[href='#heading-21'])", {"class": "header-item"})
assert-css: ("//a[@href='#heading-12']/../following-sibling::ol", {"display": "none"})
// Click the chevron, should expand it.
click: "a.header-in-summary[href='#heading-12'] ~ a.header-toggle"
assert-attribute: ("li:has(> span > a[href='#heading-12'])", {"class": "header-item expanded"})
assert-attribute: ("li:has(> span > a[href='#heading-21'])", {"class": "header-item"})
assert-css: ("//a[@href='#heading-12']/../following-sibling::ol", {"display": "block"})
// Click 1.3
click: "a.header-in-summary[href='#heading-13']"
// Everything should be collapsed
assert-attribute: ("li:has(> span > a[href='#heading-12'])", {"class": "header-item"})
assert-attribute: ("li:has(> span > a[href='#heading-21'])", {"class": "header-item"})
assert-css: ("//a[@href='#heading-12']/../following-sibling::ol", {"display": "none"})
assert-css: ("//a[@href='#heading-21']/../following-sibling::ol", {"display": "none"})
assert-attribute: ("li:has(> span > a[href='#heading-12'])", {"class": "header-item"})
assert-attribute: ("li:has(> span > a[href='#heading-21'])", {"class": "header-item"})
assert-attribute: ("li:has(> span > a[href='#heading-211'])", {"class": "header-item"})
assert-attribute: ("li:has(> span > a[href='#heading-2111'])", {"class": "header-item"})
// Scroll to bottom of page
press-key: 'PageDown'
press-key: 'PageDown'
press-key: 'PageDown'
press-key: 'PageDown'
// 2.1.1.1.1 should be visible, and all the chevrons should be open, and expanded should be on each one
assert-attribute: ("li:has(> span > a[href='#heading-12'])", {"class": "header-item"})
assert-attribute: ("li:has(> span > a[href='#heading-21'])", {"class": "header-item expanded"})
assert-attribute: ("li:has(> span > a[href='#heading-211'])", {"class": "header-item expanded"})
assert-attribute: ("li:has(> span > a[href='#heading-2111'])", {"class": "header-item expanded"})
assert-css: ("//a[@href='#heading-12']/../following-sibling::ol", {"display": "none"})
assert-css: ("//a[@href='#heading-21']/../following-sibling::ol", {"display": "block"})
assert-css: ("//a[@href='#heading-211']/../following-sibling::ol", {"display": "block"})
assert-css: ("//a[@href='#heading-2111']/../following-sibling::ol", {"display": "block"})