Make theme switching closer to reality

This commit is contained in:
Guillaume Gomez 2024-04-08 12:14:41 +02:00
parent cf65764920
commit 66bc97cc88
5 changed files with 34 additions and 20 deletions

View file

@ -2,23 +2,25 @@
include: "utils.goml" include: "utils.goml"
go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
// Otherwise, we can't check text color
show-text: true
// We check that without this setting, there is no line number displayed. // We check that without this setting, there is no line number displayed.
assert-false: "pre.example-line-numbers" assert-false: "pre.example-line-numbers"
// We set the setting to show the line numbers on code examples.
set-local-storage: {"rustdoc-line-numbers": "true"}
reload:
// We wait for the line numbers to be added into the DOM by the JS...
wait-for: "pre.example-line-numbers"
// Otherwise, we can't check text color
show-text: true
// Let's now check some CSS properties... // Let's now check some CSS properties...
define-function: ( define-function: (
"check-colors", "check-colors",
[theme, color], [theme, color],
block { block {
// We now set the setting to show the line numbers on code examples.
set-local-storage: {"rustdoc-line-numbers": "true"}
// Page will be reloaded in "switch-theme". // Page will be reloaded in "switch-theme".
call-function: ("switch-theme", {"theme": |theme|}) call-function: ("switch-theme", {"theme": |theme|})
// We wait for the line numbers to be added into the DOM by the JS...
wait-for: "pre.example-line-numbers"
// If the test didn't fail, it means that it was found! // If the test didn't fail, it means that it was found!
assert-css: ( assert-css: (
"pre.example-line-numbers", "pre.example-line-numbers",

View file

@ -9,6 +9,7 @@ define-function: (
[theme, toggle_line_color, toggle_line_hover_color], [theme, toggle_line_color, toggle_line_hover_color],
block { block {
call-function: ("switch-theme", {"theme": |theme|}) call-function: ("switch-theme", {"theme": |theme|})
reload:
// Clicking "More examples..." will open additional examples // Clicking "More examples..." will open additional examples
assert-attribute-false: (".more-examples-toggle", {"open": ""}) assert-attribute-false: (".more-examples-toggle", {"open": ""})
@ -21,6 +22,8 @@ define-function: (
".toggle-line:hover .toggle-line-inner", ".toggle-line:hover .toggle-line-inner",
{"background-color": |toggle_line_hover_color|}, {"background-color": |toggle_line_hover_color|},
) )
// We put the toggle in the original state.
click: ".more-examples-toggle"
// Moving cursor away from the toggle line to prevent disrupting next test. // Moving cursor away from the toggle line to prevent disrupting next test.
move-cursor-to: ".search-input" move-cursor-to: ".search-input"
}, },

View file

@ -210,24 +210,21 @@ call-function: ("check-search-color", {
// Check the alias. // Check the alias.
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
// If the text isn't displayed, the browser doesn't compute color style correctly...
show-text: true write-into: (".search-input", "thisisanalias")
// To be SURE that the search will be run.
press-key: 'Enter'
// Waiting for the search results to appear...
wait-for: "#search-tabs"
define-function: ( define-function: (
"check-alias", "check-alias",
[theme, alias, grey], [theme, alias, grey],
block { block {
call-function: ("switch-theme", {"theme": |theme|}) call-function: ("switch-theme", {"theme": |theme|})
write-into: (".search-input", "thisisanalias")
// To be SURE that the search will be run.
press-key: 'Enter'
// Waiting for the search results to appear...
wait-for: "#search-tabs"
// Checking that the colors for the alias element are the ones expected. // Checking that the colors for the alias element are the ones expected.
assert-css: (".result-name .path .alias", {"color": |alias|}) assert-css: (".result-name .path .alias", {"color": |alias|})
assert-css: (".result-name .path .alias > .grey", {"color": |grey|}) assert-css: (".result-name .path .alias > .grey", {"color": |grey|})
// Leave the search results to prevent reloading with an already filled search input.
press-key: "Escape"
}, },
) )

View file

@ -36,7 +36,12 @@ wait-for: "#alternative-display #search"
assert: "#main-content.hidden" assert: "#main-content.hidden"
// Now let's check the content of the settings menu. // Now let's check the content of the settings menu.
call-function: ("switch-theme", {"theme": "dark"}) // If we are on the settings page, the menu doesn't work the same so we set
// the theme manually.
set-local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
// We reload the page so the local storage settings are being used.
reload:
click: "#settings-menu" click: "#settings-menu"
wait-for: "#settings" wait-for: "#settings"

View file

@ -4,8 +4,15 @@ define-function: (
[theme], [theme],
block { block {
// Set the theme. // Set the theme.
set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} // Open the settings menu.
// We reload the page so the local storage settings are being used. click: "#settings-menu"
reload: // Wait for the popover to appear...
wait-for: "#settings"
// Change the setting.
click: "#theme-"+ |theme|
// Close the popover.
click: "#settings-menu"
// Ensure that the local storage was correctly updated.
assert-local-storage: {"rustdoc-theme": |theme|}
}, },
) )