Skip to content

Commit d7e17c4

Browse files
committed
rustdoc: add test case for modnav position when TOC is off
1 parent 1e09d95 commit d7e17c4

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Verifies that, when TOC is hidden, modnav is always in exactly the same spot
2+
// This is driven by a reasonably common use case:
3+
//
4+
// - There are three or more items that might meet my needs.
5+
// - I open the first one, decide it's not what I want, switch to the second one using the sidebar.
6+
// - The second one also doesn't meet my needs, so I switch to the third.
7+
// - The third also doesn't meet my needs, so...
8+
//
9+
// because the sibling module nav is in exactly the same place every time,
10+
// it's very easy to find and switch between pages that way.
11+
12+
go-to: "file://" + |DOC_PATH| + "/test_docs/enum.WhoLetTheDogOut.html"
13+
show-text: true
14+
set-local-storage: {"rustdoc-hide-toc": "true"}
15+
16+
define-function: (
17+
"check-positions",
18+
[url],
19+
block {
20+
go-to: "file://" + |DOC_PATH| + |url|
21+
// Checking results colors.
22+
assert-position: ("#rustdoc-modnav > h2", {"x": |h2_x|, "y": |h2_y|})
23+
assert-position: (
24+
"#rustdoc-modnav > ul:first-of-type > li:first-of-type",
25+
{"x": |x|, "y": |y|}
26+
)
27+
},
28+
)
29+
30+
// First, at test_docs root
31+
go-to: "file://" + |DOC_PATH| + "/test_docs/enum.WhoLetTheDogOut.html"
32+
store-position: ("#rustdoc-modnav > h2", {"x": h2_x, "y": h2_y})
33+
store-position: ("#rustdoc-modnav > ul:first-of-type > li:first-of-type", {"x": x, "y": y})
34+
call-function: ("check-positions", {"url": "/test_docs/enum.WhoLetTheDogOut.html"})
35+
call-function: ("check-positions", {"url": "/test_docs/struct.StructWithPublicUndocumentedFields.html"})
36+
call-function: ("check-positions", {"url": "/test_docs/codeblock_sub/index.html"})
37+
38+
// Now in a submodule
39+
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/struct.Struct.html"
40+
store-position: ("#rustdoc-modnav > h2", {"x": h2_x, "y": h2_y})
41+
store-position: ("#rustdoc-modnav > ul:first-of-type > li:first-of-type", {"x": x, "y": y})
42+
call-function: ("check-positions", {"url": "/test_docs/fields/struct.Struct.html"})
43+
call-function: ("check-positions", {"url": "/test_docs/fields/union.Union.html"})
44+
call-function: ("check-positions", {"url": "/test_docs/fields/enum.Enum.html"})

0 commit comments

Comments
 (0)