summaryrefslogtreecommitdiffstats
path: root/tests/rustdoc-gui/sidebar-mobile.goml
blob: 4b8337ace3a2f3165be399e635a1bef510af9909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// This test ensure that the sidebar isn't "hidden" on mobile but instead moved out of the viewport.
// This is especially important for devices for "text-first" content (like for users with
// sight issues).
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
// Switching to "mobile view" by reducing the width to 600px.
set-window-size: (600, 600)
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
// Opening the sidebar menu.
click: ".sidebar-menu-toggle"
assert-css: (".sidebar", {"display": "block", "left": "0px"})
// Closing the sidebar menu.
click: ".sidebar-menu-toggle"
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
// Force the sidebar open by focusing a link inside it.
// This makes it easier for keyboard users to get to it.
focus: ".sidebar-elems h3 a"
assert-css: (".sidebar", {"display": "block", "left": "0px"})
// When we tab out of the sidebar, close it.
focus: ".search-input"
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})

// Open the sidebar menu.
click: ".sidebar-menu-toggle"
assert-css: (".sidebar", {"left": "0px"})

// Make sure the "struct Foo" header is hidden, since the mobile topbar already does it.
assert-css: ("//nav[contains(@class, 'sidebar')]//h2/a[text()='Foo']/parent::h2", {"display": "none"})
// Make sure the global navigation is still here.
assert-css: ("//nav[contains(@class, 'sidebar')]//h2/a[text()='In test_docs']/parent::h2", {"display": "block"})

// Click elsewhere.
click: "body"
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})

// Open the sidebar menu, and make sure pressing Escape closes it.
click: ".sidebar-menu-toggle"
assert-css: (".sidebar", {"left": "0px"})
press-key: "Escape"
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})

// Check that the topbar is visible
assert-property: (".mobile-topbar", {"clientHeight": "45"})

// Check that clicking an element from the sidebar scrolls to the right place
// so the target is not obscured by the topbar.
click: ".sidebar-menu-toggle"
click: ".sidebar-elems section .block li > a"
assert-position: ("#method\.must_use", {"y": 46})

// Check that the bottom-most item on the sidebar menu can be scrolled fully into view.
click: ".sidebar-menu-toggle"
scroll-to: ".block.keyword li:nth-child(1)"
compare-elements-position-near: (".block.keyword li:nth-child(1)", ".mobile-topbar", {"y": 543.19})

// Now checking the background color of the sidebar.
show-text: true

define-function: (
    "check-colors",
    (theme, color, background),
    block {
        set-local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": |theme|}
        reload:

        // Open the sidebar menu.
        click: ".sidebar-menu-toggle"
        assert-css: (".sidebar", {
            "background-color": |background|,
            "color": |color|,
        })
    },
)

call-function: ("check-colors", {
    "theme": "ayu",
    "color": "#c5c5c5",
    "background": "#14191f",
})
call-function: ("check-colors", {
    "theme": "dark",
    "color": "#ddd",
    "background": "#505050",
})
call-function: ("check-colors", {
    "theme": "light",
    "color": "black",
    "background": "#F5F5F5",
})