fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// Checks that the interactions with the source code pages are working as expected. 2go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" 3show-text: true 4// Check that we can click on the line number. 5click: ".src-line-numbers > a:nth-child(4)" // This is the anchor for line 4. 6// Ensure that the page URL was updated. 7assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH) 8assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"}) 9// Ensure that the default style, with the right border, isn't used. 10assert-css: ("//*[@id='4']", {"border-right-width": "0px"}) 11reload: 12assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"}) 13assert-css: ("//*[@id='4']", {"border-right-width": "0px"}) 14// We now check that the good anchors are highlighted 15go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4-6" 16assert-attribute-false: (".src-line-numbers > a:nth-child(3)", {"class": "line-highlighted"}) 17assert-attribute: (".src-line-numbers > a:nth-child(4)", {"class": "line-highlighted"}) 18assert-attribute: (".src-line-numbers > a:nth-child(5)", {"class": "line-highlighted"}) 19assert-attribute: (".src-line-numbers > a:nth-child(6)", {"class": "line-highlighted"}) 20assert-attribute-false: (".src-line-numbers > a:nth-child(7)", {"class": "line-highlighted"}) 21 22define-function: ( 23 "check-colors", 24 (theme, color, background_color, highlight_color, highlight_background_color), 25 block { 26 set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} 27 reload: 28 assert-css: ( 29 ".src-line-numbers > a:not(.line-highlighted)", 30 {"color": |color|, "background-color": |background_color|}, 31 ALL, 32 ) 33 assert-css: ( 34 ".src-line-numbers > a.line-highlighted", 35 {"color": |highlight_color|, "background-color": |highlight_background_color|}, 36 ALL, 37 ) 38 }, 39) 40 41call-function: ("check-colors", { 42 "theme": "ayu", 43 "color": "#5c6773", 44 "background_color": "transparent", 45 "highlight_color": "#708090", 46 "highlight_background_color": "rgba(255, 236, 164, 0.06)", 47}) 48call-function: ("check-colors", { 49 "theme": "dark", 50 "color": "#3b91e2", 51 "background_color": "transparent", 52 "highlight_color": "#3b91e2", 53 "highlight_background_color": "#0a042f", 54}) 55call-function: ("check-colors", { 56 "theme": "light", 57 "color": "#c67e2d", 58 "background_color": "transparent", 59 "highlight_color": "#c67e2d", 60 "highlight_background_color": "#fdffd3", 61}) 62 63// This is to ensure that the content is correctly align with the line numbers. 64compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y")) 65// Check the `href` property so that users can treat anchors as links. 66assert-property: (".src-line-numbers > a:nth-child(1)", { 67 "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#1" 68}, ENDS_WITH) 69assert-property: (".src-line-numbers > a:nth-child(2)", { 70 "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#2" 71}, ENDS_WITH) 72assert-property: (".src-line-numbers > a:nth-child(3)", { 73 "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#3" 74}, ENDS_WITH) 75assert-property: (".src-line-numbers > a:nth-child(4)", { 76 "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#4" 77}, ENDS_WITH) 78assert-property: (".src-line-numbers > a:nth-child(5)", { 79 "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#5" 80}, ENDS_WITH) 81assert-property: (".src-line-numbers > a:nth-child(6)", { 82 "href": |DOC_PATH| + "/src/test_docs/lib.rs.html#6" 83}, ENDS_WITH) 84 85// Assert that the line numbers text is aligned to the right. 86assert-css: (".src-line-numbers", {"text-align": "right"}) 87 88// Now let's check that clicking on something else than the line number doesn't 89// do anything (and certainly not add a `#NaN` to the URL!). 90go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" 91// We use this assert-position to know where we will click. 92assert-position: ("//*[@id='1']", {"x": 88, "y": 112}) 93// We click on the left of the "1" anchor but still in the "src-line-number" `<pre>`. 94click: (87, 103) 95assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH) 96 97// Checking the source code sidebar. 98 99// First we "open" it. 100click: "#src-sidebar-toggle" 101assert: ".src-sidebar-expanded" 102 103// We check that the first entry of the sidebar is collapsed 104assert-property: ("#src-sidebar details:first-of-type", {"open": "false"}) 105assert-text: ("#src-sidebar details:first-of-type > summary", "extend_css") 106// We now click on it. 107click: "#src-sidebar details:first-of-type > summary" 108assert-property: ("#src-sidebar details:first-of-type", {"open": "true"}) 109 110// And now we collapse it again. 111click: "#src-sidebar details:first-of-type > summary" 112assert-property: ("#src-sidebar details:first-of-type", {"open": "false"}) 113 114// And open it again, since it'll be the reference we use to check positions. 115click: "#src-sidebar details:first-of-type > summary" 116assert-property: ("#src-sidebar details:first-of-type", {"open": "true"}) 117 118// Check the sidebar directory entries have a marker and spacing (desktop). 119store-property: ( 120 "#src-sidebar > details:first-of-type.dir-entry[open] > .files > a", 121 {"offsetHeight": link_height}, 122) 123define-function: ( 124 "check-sidebar-dir-entry", 125 (x, y), 126 block { 127 assert: "details:first-of-type.dir-entry[open] > summary::marker" 128 assert-css: ("#src-sidebar > details:first-of-type.dir-entry", {"padding-left": "4px"}) 129 // This check ensures that the summary is only one line. 130 assert-property: ( 131 "#src-sidebar > details:first-of-type.dir-entry[open] > summary", 132 {"offsetHeight": |link_height|} 133 ) 134 assert-position: ( 135 "#src-sidebar > details:first-of-type.dir-entry[open] > summary", 136 {"x": |x|, "y": |y|} 137 ) 138 assert-property: ( 139 "#src-sidebar > details:first-of-type.dir-entry[open] > .files > a", 140 {"offsetHeight": |link_height|} 141 ) 142 assert-position: ( 143 "#src-sidebar > details:first-of-type.dir-entry[open] > .files > a", 144 // left margin 145 {"x": |x| + 27, "y": |y| + |link_height|} 146 ) 147 } 148) 149store-property: ("#src-sidebar > .title", { 150 "offsetHeight": source_sidebar_title_height, 151 "offsetTop": source_sidebar_title_y, 152}) 153call-function: ("check-sidebar-dir-entry", { 154 "x": 0, 155 // border + margin = 6 156 "y": |source_sidebar_title_y| + |source_sidebar_title_height| + 6, 157}) 158 159// Check the search form 160assert-css: ("nav.sub", {"flex-direction": "row"}) 161// The goal of this test is to ensure the search input is perfectly centered 162// between the top of the page and the top of the gray code block. 163// To check this, we maintain the invariant: 164// 165// offsetTop[nav.sub form] = offsetTop[#main-content] - offsetHeight[nav.sub form] - offsetTop[nav.sub form] 166assert-property: ("nav.sub form", {"offsetTop": 28, "offsetHeight": 34}) 167assert-property: ("#main-content", {"offsetTop": 90}) 168// 28 = 90 - 34 - 28 169 170// Now do the same check on moderately-sized, tablet mobile. 171set-window-size: (700, 700) 172assert-css: ("nav.sub", {"flex-direction": "row"}) 173assert-property: ("nav.sub form", {"offsetTop": 21, "offsetHeight": 34}) 174assert-property: ("#main-content", {"offsetTop": 76}) 175// 21 = 76 - 34 - 21 176 177// Check the sidebar directory entries have a marker and spacing (tablet). 178store-property: ("#src-sidebar > .title", { 179 "offsetHeight": source_sidebar_title_height, 180 "offsetTop": source_sidebar_title_y, 181}) 182call-function: ("check-sidebar-dir-entry", { 183 "x": 0, 184 "y": |source_sidebar_title_y| + |source_sidebar_title_height| + 6, 185}) 186 187// Tiny, phone mobile gets a different display where the logo is stacked on top. 188set-window-size: (450, 700) 189assert-css: ("nav.sub", {"flex-direction": "column"}) 190 191// Check the sidebar directory entries have a marker and spacing (phone). 192store-property: ("#src-sidebar > .title", { 193 "offsetHeight": source_sidebar_title_height, 194 "offsetTop": source_sidebar_title_y, 195}) 196call-function: ("check-sidebar-dir-entry", { 197 "x": 0, 198 "y": |source_sidebar_title_y| + |source_sidebar_title_height| + 6, 199}) 200 201// Now we check that the logo has a bottom margin so it's not stuck to the search input. 202assert-css: (".sub-logo-container > img", {"margin-bottom": "8px"}) 203store-property: (".sub-logo-container", {"clientHeight": logo_height}) 204assert-position: (".search-form", {"y": |logo_height| + 8})