Debian Codegraph @

tests/gui/sidebar.goml

raw
1 // This GUI test checks sidebar hide/show and also its behaviour on smaller
2 // width.
3
4 go-to: |DOC_PATH| + "all-summary/index.html"
5 set-window-size: (1100, 600)
6 // Need to reload for the new size to be taken account by the JS.
7 reload:
8
9 store-value: (content_indent, 308)
10 store-value: (sidebar_storage_value, "mdbook-sidebar")
11 store-value: (sidebar_storage_hidden_value, "hidden")
12 store-value: (sidebar_storage_displayed_value, "visible")
13
14 define-function: (
15 "hide-sidebar",
16 [],
17 block {
18 assert-position: ("#mdbook-page-wrapper", {"x": |content_indent|})
19
20 // We now hide the sidebar.
21 click: "#mdbook-sidebar-toggle"
22 wait-for-css: ("#mdbook-sidebar", {"display": "none"})
23 assert-local-storage: {|sidebar_storage_value|: |sidebar_storage_hidden_value|}
24 },
25 )
26
27 define-function: (
28 "show-sidebar",
29 [],
30 block {
31 assert-css: ("#mdbook-sidebar", {"display": "none"})
32 assert-position: ("#mdbook-page-wrapper", {"x": 0})
33
34 // We expand the sidebar.
35 click: "#mdbook-sidebar-toggle"
36 wait-for-css-false: ("#mdbook-sidebar", {"display": "none"})
37 // `transform` is 0.3s so we need to wait a bit (0.5s) to ensure the animation is done.
38 wait-for: 5000
39 assert-css-false: ("#mdbook-sidebar", {"transform": "matrix(1, 0, 0, 1, -308, 0)"})
40 // The page content should be moved to the right.
41 assert-position: ("#mdbook-page-wrapper", {"x": |content_indent|})
42 assert-local-storage: {|sidebar_storage_value|: |sidebar_storage_displayed_value|}
43 },
44 )
45
46 // Since the sidebar is visible, we should be able to find this text.
47 assert-find-text: ("3. P1 C1", {"case-sensitive": true})
48 call-function: ("hide-sidebar", {})
49 // Text should not be findeable anymore since the sidebar is collapsed.
50 assert-find-text-false: ("3. P1 C1", {"case-sensitive": true})
51 call-function: ("show-sidebar", {})
52 // We should be able to find this text again.
53 assert-find-text: ("3. P1 C1", {"case-sensitive": true})
54
55 // We now test on smaller width to ensure that the sidebar is collapsed by default.
56 set-window-size: (900, 600)
57 reload:
58 call-function: ("show-sidebar", {})
59 call-function: ("hide-sidebar", {})
60
61 // We now test that if the sidebar is considered open and we reload the page, since
62 // the width is small, it will still be collapsed.
63 set-local-storage: {|sidebar_storage_value|: |sidebar_storage_displayed_value|}
64 reload:
65 // The stored value shouldn't have changed.
66 assert-local-storage: {|sidebar_storage_value|: |sidebar_storage_displayed_value|}
67 // But the sidebar should be hidden anyway.
68 assert-css: ("#mdbook-sidebar", {"display": "none"})
69 assert-position: ("#mdbook-page-wrapper", {"x": 0})