Add new "hide deprecated items" setting in rustdoc This PR adds a new JS setting which allows the JS to hide deprecated items. This is especially useful for crates like `std` which accumulates deprecated items but never removes them. Nicely enough, the "deprecation" information was already in the search index, meaning I didn't need to change anything there. Before this PR, it was only used to make the deprecated items rank lower. Well now it's also used to generate an extra CSS class, allowing the JS setting to work. This is taking over https://github.com/rust-lang/rust/pull/149551. This feature got approved by the rustdoc team in the [meeting of december](https://rust-lang.zulipchat.com/#narrow/channel/393423-t-rustdoc.2Fmeetings/topic/2025-12-08/near/562553156). You can give it a try [here](https://rustdoc.crud.net/imperio/hide-deprecated-items/foo/index.html). r? @lolbinarycat
133 lines
4.2 KiB
Text
133 lines
4.2 KiB
Text
// This file contains code to be re-used by other tests.
|
|
|
|
define-function: (
|
|
"click-settings-button",
|
|
[],
|
|
block {
|
|
store-count: ("rustdoc-topbar", __topbar_count)
|
|
store-value: (__topbar_display, "none")
|
|
// The `rustdoc-topbar` element is created with JS when the window size is below a given
|
|
// size, however if the window size gets bigger again, the element isn't deleted, just
|
|
// hidden, so we need to check for both that it exists and is visible.
|
|
if: (|__topbar_count| != 0, block {
|
|
store-css: ("rustdoc-topbar", {"display": __topbar_display})
|
|
})
|
|
|
|
// Open the settings menu.
|
|
if: (|__topbar_display| != "none", block {
|
|
// In mobile mode, this is instead the "topbar" the settings button is located into.
|
|
click: "rustdoc-topbar .settings-menu"
|
|
})
|
|
else: block {
|
|
// We're not in mobile mode so clicking on the "normal" sidebar.
|
|
click: "rustdoc-toolbar .settings-menu"
|
|
}
|
|
}
|
|
)
|
|
|
|
define-function: (
|
|
"open-settings-menu",
|
|
[],
|
|
block {
|
|
store-count: ("#settings", nb_settings_menu)
|
|
if: (|nb_settings_menu| != 0, block {
|
|
store-css: ("#settings", {"display": settings_display})
|
|
})
|
|
else: block {
|
|
store-value: (settings_display, "none")
|
|
}
|
|
if: (|settings_display| != "block", block {
|
|
call-function: ("click-settings-button", {})
|
|
// Wait for the popover to appear...
|
|
wait-for-css: ("#settings", {"display": "block"})
|
|
})
|
|
}
|
|
)
|
|
|
|
define-function: (
|
|
"close-settings-menu",
|
|
[],
|
|
block {
|
|
store-count: ("#settings", nb_settings_menu)
|
|
if: (|nb_settings_menu| != 0, block {
|
|
store-css: ("#settings", {"display": settings_display})
|
|
})
|
|
else: block {
|
|
store-value: (settings_display, "block")
|
|
}
|
|
if: (|settings_display| == "block", block {
|
|
call-function: ("click-settings-button", {})
|
|
// Wait for the popover to disappear...
|
|
wait-for-css-false: ("#settings", {"display": "block"})
|
|
})
|
|
}
|
|
)
|
|
|
|
define-function: (
|
|
"switch-theme",
|
|
[theme],
|
|
block {
|
|
// Set the theme.
|
|
call-function: ("open-settings-menu", {})
|
|
// Change the setting.
|
|
click: "#theme-"+ |theme|
|
|
call-function: ("close-settings-menu", {})
|
|
// Ensure that the local storage was correctly updated.
|
|
assert-local-storage: {"rustdoc-theme": |theme|}
|
|
},
|
|
)
|
|
|
|
define-function: (
|
|
"open-search",
|
|
[],
|
|
block {
|
|
store-count: (".search-input", __search_input_count)
|
|
if: (|__search_input_count| != 0, block {
|
|
store-css: ("#alternative-display", {"display": __search_input_display})
|
|
})
|
|
else: block {
|
|
// Block requests with doubled `//`.
|
|
// Amazon S3 doesn't support them, but other web hosts do,
|
|
// and so do file:/// URLs, which means we need to block
|
|
// it here if we want to avoid breaking the main docs site.
|
|
// https://github.com/rust-lang/rust/issues/145646
|
|
block-network-request: "file://*//*"
|
|
store-value: (__search_input_display, "none")
|
|
}
|
|
|
|
if: (|__search_input_display| == "none", block {
|
|
// Open search
|
|
click: "#search-button"
|
|
wait-for: ".search-input"
|
|
})
|
|
}
|
|
)
|
|
|
|
define-function: (
|
|
"perform-search",
|
|
[query],
|
|
block {
|
|
call-function: ("open-search", {})
|
|
// We empty the search input in case it wasn't empty.
|
|
set-property: (".search-input", {"value": ""})
|
|
// We write the actual query.
|
|
write-into: (".search-input", |query|)
|
|
press-key: 'Enter'
|
|
// wait for the search to start
|
|
wait-for: "#search-tabs"
|
|
// then wait for it to finish
|
|
wait-for-false: "#search-tabs .count.loading"
|
|
}
|
|
)
|
|
|
|
define-function: (
|
|
"switch-line-numbers-setting",
|
|
[expected_status],
|
|
block {
|
|
call-function: ("open-settings-menu", {})
|
|
// We change the line numbers setting.
|
|
click: "#line-numbers"
|
|
call-function: ("close-settings-menu", {})
|
|
assert-local-storage: {"rustdoc-line-numbers": |expected_status|}
|
|
}
|
|
)
|