2022-06-14 04:21:28 -05:00
|
|
|
// Checks that the interactions with the source code pages are working as expected.
|
2024-04-05 14:38:55 -05:00
|
|
|
include: "utils.goml"
|
2023-04-11 12:11:34 -05:00
|
|
|
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
|
2022-10-26 10:51:20 -05:00
|
|
|
show-text: true
|
2021-05-10 07:12:00 -05:00
|
|
|
// Check that we can click on the line number.
|
2022-10-27 13:16:30 -05:00
|
|
|
click: ".src-line-numbers > a:nth-child(4)" // This is the anchor for line 4.
|
2022-05-30 10:07:21 -05:00
|
|
|
// Ensure that the page URL was updated.
|
2022-05-30 10:14:46 -05:00
|
|
|
assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
|
2022-05-30 10:07:21 -05:00
|
|
|
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
|
2022-10-28 11:51:57 -05:00
|
|
|
// Ensure that the default style, with the right border, isn't used.
|
|
|
|
assert-css: ("//*[@id='4']", {"border-right-width": "0px"})
|
|
|
|
reload:
|
|
|
|
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
|
|
|
|
assert-css: ("//*[@id='4']", {"border-right-width": "0px"})
|
2022-10-27 13:16:30 -05:00
|
|
|
// We now check that the good anchors are highlighted
|
2023-04-11 12:11:34 -05:00
|
|
|
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4-6"
|
2022-10-27 13:16:30 -05:00
|
|
|
assert-attribute-false: (".src-line-numbers > a:nth-child(3)", {"class": "line-highlighted"})
|
|
|
|
assert-attribute: (".src-line-numbers > a:nth-child(4)", {"class": "line-highlighted"})
|
|
|
|
assert-attribute: (".src-line-numbers > a:nth-child(5)", {"class": "line-highlighted"})
|
|
|
|
assert-attribute: (".src-line-numbers > a:nth-child(6)", {"class": "line-highlighted"})
|
|
|
|
assert-attribute-false: (".src-line-numbers > a:nth-child(7)", {"class": "line-highlighted"})
|
2022-10-26 10:51:20 -05:00
|
|
|
|
|
|
|
define-function: (
|
|
|
|
"check-colors",
|
2024-04-01 14:11:22 -05:00
|
|
|
[theme, color, background_color, highlight_color, highlight_background_color],
|
2023-01-06 08:18:51 -06:00
|
|
|
block {
|
2024-04-05 14:38:55 -05:00
|
|
|
call-function: ("switch-theme", {"theme": |theme|})
|
2023-01-06 08:18:51 -06:00
|
|
|
assert-css: (
|
2022-10-27 13:16:30 -05:00
|
|
|
".src-line-numbers > a:not(.line-highlighted)",
|
2022-10-26 10:51:20 -05:00
|
|
|
{"color": |color|, "background-color": |background_color|},
|
|
|
|
ALL,
|
2023-01-06 08:18:51 -06:00
|
|
|
)
|
|
|
|
assert-css: (
|
2022-10-27 13:16:30 -05:00
|
|
|
".src-line-numbers > a.line-highlighted",
|
2022-10-26 10:51:20 -05:00
|
|
|
{"color": |highlight_color|, "background-color": |highlight_background_color|},
|
|
|
|
ALL,
|
2023-01-06 08:18:51 -06:00
|
|
|
)
|
|
|
|
},
|
2022-10-26 10:51:20 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
call-function: ("check-colors", {
|
|
|
|
"theme": "ayu",
|
2023-05-18 10:02:51 -05:00
|
|
|
"color": "#5c6773",
|
|
|
|
"background_color": "transparent",
|
|
|
|
"highlight_color": "#708090",
|
2022-10-26 10:51:20 -05:00
|
|
|
"highlight_background_color": "rgba(255, 236, 164, 0.06)",
|
|
|
|
})
|
|
|
|
call-function: ("check-colors", {
|
|
|
|
"theme": "dark",
|
2023-05-18 10:02:51 -05:00
|
|
|
"color": "#3b91e2",
|
|
|
|
"background_color": "transparent",
|
|
|
|
"highlight_color": "#3b91e2",
|
|
|
|
"highlight_background_color": "#0a042f",
|
2022-10-26 10:51:20 -05:00
|
|
|
})
|
|
|
|
call-function: ("check-colors", {
|
|
|
|
"theme": "light",
|
2023-05-18 10:02:51 -05:00
|
|
|
"color": "#c67e2d",
|
|
|
|
"background_color": "transparent",
|
|
|
|
"highlight_color": "#c67e2d",
|
|
|
|
"highlight_background_color": "#fdffd3",
|
2022-10-26 10:51:20 -05:00
|
|
|
})
|
|
|
|
|
2021-06-22 04:17:53 -05:00
|
|
|
// This is to ensure that the content is correctly align with the line numbers.
|
2024-04-01 14:11:22 -05:00
|
|
|
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ["y"])
|
2022-10-27 13:16:30 -05:00
|
|
|
// Check the `href` property so that users can treat anchors as links.
|
|
|
|
assert-property: (".src-line-numbers > a:nth-child(1)", {
|
2023-06-14 09:23:00 -05:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#1"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 13:16:30 -05:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(2)", {
|
2023-06-14 09:23:00 -05:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#2"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 13:16:30 -05:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(3)", {
|
2023-06-14 09:23:00 -05:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#3"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 13:16:30 -05:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(4)", {
|
2023-06-14 09:23:00 -05:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#4"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 13:16:30 -05:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(5)", {
|
2023-06-14 09:23:00 -05:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#5"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 13:16:30 -05:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(6)", {
|
2023-06-14 09:23:00 -05:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#6"
|
|
|
|
}, ENDS_WITH)
|
2022-03-07 05:08:14 -06:00
|
|
|
|
|
|
|
// Assert that the line numbers text is aligned to the right.
|
2022-09-26 12:50:51 -05:00
|
|
|
assert-css: (".src-line-numbers", {"text-align": "right"})
|
2022-05-30 10:14:46 -05:00
|
|
|
|
|
|
|
// Now let's check that clicking on something else than the line number doesn't
|
|
|
|
// do anything (and certainly not add a `#NaN` to the URL!).
|
2023-04-11 12:11:34 -05:00
|
|
|
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
|
2022-05-30 10:14:46 -05:00
|
|
|
// We use this assert-position to know where we will click.
|
2024-10-23 18:15:23 -05:00
|
|
|
assert-position: ("//*[@id='1']", {"x": 88, "y": 171})
|
2022-10-27 13:16:30 -05:00
|
|
|
// We click on the left of the "1" anchor but still in the "src-line-number" `<pre>`.
|
rustdoc: redesign toolbar and disclosure widgets
This adds labels to the icons and moves them away from the search box.
These changes are made together, because they work together, but are based on
several complaints:
* The [+/-] thing are a Reddit-ism. They don't look like buttons, but look
like syntax
<https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/More.20visual.20difference.20for.20the.20.2B.2F-.20.20Icons>,
<https://github.com/rust-lang/rust/issues/59851>
(some of these are laundry lists with more suggestions, but they all
mention [+/-] looking wrong)
* The settings, help, and summary buttons are also too hard to recognize
<https://lwn.net/Articles/987070/>,
<https://github.com/rust-lang/rust/issues/90310>,
<https://github.com/rust-lang/rust/issues/14475#issuecomment-274241997>,
<https://internals.rust-lang.org/t/improve-rustdoc-design/12758>
("Not all functionality is self-explanatory, for example the [+] button in
the top right corner, the theme picker or the settings button.")
The toggle-all and toggle-individual buttons both need done at once, since we
want them to look like they go together. This changes them from both being
[+/-] to both being arrows.
Settings and Help are also migrated, so that the whole group can benefit from
being described using actual words.
Additionally, the Help button is only shown on SERPs, not all the time.
This is done for two major reasons:
* Most of what's in there is search-related. The things that aren't are
keyboard commands, and the search box tells you about that anyway.
Pressing <kbd>?</kbd> will temporarily show the button and its popover.
* I'm trading it off by showing the help button, even on mobile.
It's useful since you can use the search engine suggestions there.
* The three buttons were causing line wrapping on too many desktop layouts.
2024-08-25 01:11:30 -05:00
|
|
|
click: (163, 77)
|
2022-05-30 10:14:46 -05:00
|
|
|
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
|
2022-06-14 04:21:28 -05:00
|
|
|
|
|
|
|
// Checking the source code sidebar.
|
|
|
|
|
|
|
|
// First we "open" it.
|
2023-12-18 00:06:31 -06:00
|
|
|
click: "#sidebar-button"
|
2023-07-14 18:38:01 -05:00
|
|
|
assert: ".src-sidebar-expanded"
|
2022-06-14 04:21:28 -05:00
|
|
|
|
2022-07-01 12:33:06 -05:00
|
|
|
// We check that the first entry of the sidebar is collapsed
|
2023-07-14 18:38:01 -05:00
|
|
|
assert-property: ("#src-sidebar details:first-of-type", {"open": "false"})
|
|
|
|
assert-text: ("#src-sidebar details:first-of-type > summary", "extend_css")
|
2022-06-14 04:21:28 -05:00
|
|
|
// We now click on it.
|
2023-07-14 18:38:01 -05:00
|
|
|
click: "#src-sidebar details:first-of-type > summary"
|
|
|
|
assert-property: ("#src-sidebar details:first-of-type", {"open": "true"})
|
2022-06-14 04:21:28 -05:00
|
|
|
|
|
|
|
// And now we collapse it again.
|
2023-07-14 18:38:01 -05:00
|
|
|
click: "#src-sidebar details:first-of-type > summary"
|
|
|
|
assert-property: ("#src-sidebar details:first-of-type", {"open": "false"})
|
2022-07-02 11:42:49 -05:00
|
|
|
|
2022-12-31 12:23:30 -06:00
|
|
|
// And open it again, since it'll be the reference we use to check positions.
|
2023-07-14 18:38:01 -05:00
|
|
|
click: "#src-sidebar details:first-of-type > summary"
|
|
|
|
assert-property: ("#src-sidebar details:first-of-type", {"open": "true"})
|
2022-12-31 12:23:30 -06:00
|
|
|
|
|
|
|
// Check the sidebar directory entries have a marker and spacing (desktop).
|
|
|
|
store-property: (
|
2023-07-14 18:38:01 -05:00
|
|
|
"#src-sidebar > details:first-of-type.dir-entry[open] > .files > a",
|
2023-05-10 03:56:59 -05:00
|
|
|
{"offsetHeight": link_height},
|
2022-12-31 12:23:30 -06:00
|
|
|
)
|
|
|
|
define-function: (
|
|
|
|
"check-sidebar-dir-entry",
|
2024-04-01 14:11:22 -05:00
|
|
|
[x, y],
|
2023-01-06 08:18:51 -06:00
|
|
|
block {
|
|
|
|
assert: "details:first-of-type.dir-entry[open] > summary::marker"
|
2023-07-14 18:38:01 -05:00
|
|
|
assert-css: ("#src-sidebar > details:first-of-type.dir-entry", {"padding-left": "4px"})
|
2022-12-31 12:23:30 -06:00
|
|
|
// This check ensures that the summary is only one line.
|
2023-01-06 08:18:51 -06:00
|
|
|
assert-property: (
|
2023-07-14 18:38:01 -05:00
|
|
|
"#src-sidebar > details:first-of-type.dir-entry[open] > summary",
|
2022-12-31 12:23:30 -06:00
|
|
|
{"offsetHeight": |link_height|}
|
2023-01-06 08:18:51 -06:00
|
|
|
)
|
|
|
|
assert-position: (
|
2023-07-14 18:38:01 -05:00
|
|
|
"#src-sidebar > details:first-of-type.dir-entry[open] > summary",
|
2022-12-31 12:23:30 -06:00
|
|
|
{"x": |x|, "y": |y|}
|
2023-01-06 08:18:51 -06:00
|
|
|
)
|
|
|
|
assert-property: (
|
2023-07-14 18:38:01 -05:00
|
|
|
"#src-sidebar > details:first-of-type.dir-entry[open] > .files > a",
|
2022-12-31 12:23:30 -06:00
|
|
|
{"offsetHeight": |link_height|}
|
2023-01-06 08:18:51 -06:00
|
|
|
)
|
|
|
|
assert-position: (
|
2023-07-14 18:38:01 -05:00
|
|
|
"#src-sidebar > details:first-of-type.dir-entry[open] > .files > a",
|
2022-12-31 12:23:30 -06:00
|
|
|
// left margin
|
|
|
|
{"x": |x| + 27, "y": |y| + |link_height|}
|
2023-01-06 08:18:51 -06:00
|
|
|
)
|
|
|
|
}
|
2022-12-31 12:23:30 -06:00
|
|
|
)
|
2023-12-18 13:11:14 -06:00
|
|
|
store-property: (".src-sidebar-title", {
|
2023-05-10 03:56:59 -05:00
|
|
|
"offsetHeight": source_sidebar_title_height,
|
|
|
|
"offsetTop": source_sidebar_title_y,
|
|
|
|
})
|
2022-12-31 12:23:30 -06:00
|
|
|
call-function: ("check-sidebar-dir-entry", {
|
|
|
|
"x": 0,
|
2023-12-18 19:22:35 -06:00
|
|
|
// margin = 7px
|
|
|
|
"y": |source_sidebar_title_y| + |source_sidebar_title_height| + 7,
|
2022-12-31 12:23:30 -06:00
|
|
|
})
|
2022-10-20 15:22:36 -05:00
|
|
|
|
|
|
|
// Check the search form
|
|
|
|
assert-css: ("nav.sub", {"flex-direction": "row"})
|
|
|
|
// The goal of this test is to ensure the search input is perfectly centered
|
2024-09-02 21:42:28 -05:00
|
|
|
// between the top of the page and the header.
|
2022-10-20 15:22:36 -05:00
|
|
|
// To check this, we maintain the invariant:
|
|
|
|
//
|
|
|
|
// offsetTop[nav.sub form] = offsetTop[#main-content] - offsetHeight[nav.sub form] - offsetTop[nav.sub form]
|
2024-09-02 21:42:28 -05:00
|
|
|
assert-position: ("nav.sub form", {"y": 15})
|
|
|
|
assert-property: ("nav.sub form", {"offsetHeight": 34})
|
2024-10-23 18:15:23 -05:00
|
|
|
assert-position: ("h1", {"y": 68})
|
2023-09-19 20:08:55 -05:00
|
|
|
// 15 = 64 - 34 - 15
|
2022-10-20 15:22:36 -05:00
|
|
|
|
2022-12-31 12:23:30 -06:00
|
|
|
// Now do the same check on moderately-sized, tablet mobile.
|
2023-04-11 12:11:34 -05:00
|
|
|
set-window-size: (700, 700)
|
2022-10-20 15:22:36 -05:00
|
|
|
assert-css: ("nav.sub", {"flex-direction": "row"})
|
2024-09-02 21:42:28 -05:00
|
|
|
assert-position: ("nav.sub form", {"y": 8})
|
|
|
|
assert-property: ("nav.sub form", {"offsetHeight": 34})
|
2024-10-23 18:15:23 -05:00
|
|
|
assert-position: ("h1", {"y": 54})
|
2023-09-19 20:08:55 -05:00
|
|
|
// 8 = 50 - 34 - 8
|
2022-10-20 15:22:36 -05:00
|
|
|
|
2022-12-31 12:23:30 -06:00
|
|
|
// Check the sidebar directory entries have a marker and spacing (tablet).
|
2023-12-18 13:11:14 -06:00
|
|
|
store-property: (".src-sidebar-title", {
|
2023-05-10 03:56:59 -05:00
|
|
|
"offsetHeight": source_sidebar_title_height,
|
|
|
|
"offsetTop": source_sidebar_title_y,
|
|
|
|
})
|
2022-12-31 12:23:30 -06:00
|
|
|
call-function: ("check-sidebar-dir-entry", {
|
|
|
|
"x": 0,
|
2023-12-18 19:22:35 -06:00
|
|
|
// margin = 7px
|
|
|
|
"y": |source_sidebar_title_y| + |source_sidebar_title_height| + 7,
|
2022-12-31 12:23:30 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
// Tiny, phone mobile gets a different display where the logo is stacked on top.
|
2023-04-11 12:11:34 -05:00
|
|
|
set-window-size: (450, 700)
|
2022-10-20 15:22:36 -05:00
|
|
|
assert-css: ("nav.sub", {"flex-direction": "column"})
|
2022-12-31 12:23:30 -06:00
|
|
|
|
|
|
|
// Check the sidebar directory entries have a marker and spacing (phone).
|
2023-12-18 13:11:14 -06:00
|
|
|
store-property: (".src-sidebar-title", {
|
2023-05-10 03:56:59 -05:00
|
|
|
"offsetHeight": source_sidebar_title_height,
|
|
|
|
"offsetTop": source_sidebar_title_y,
|
|
|
|
})
|
2022-12-31 12:23:30 -06:00
|
|
|
call-function: ("check-sidebar-dir-entry", {
|
|
|
|
"x": 0,
|
2023-12-18 19:22:35 -06:00
|
|
|
// margin = 7px
|
|
|
|
"y": |source_sidebar_title_y| + |source_sidebar_title_height| + 7,
|
2022-12-31 12:23:30 -06:00
|
|
|
})
|