mirror of
https://github.com/rust-lang/mdBook.git
synced 2025-12-27 10:16:09 -05:00
This adds the ability to use multiple books for the GUI tests. This is helpful since some tests need special configuration, and sharing the same book can make it difficult or impossible to test different configurations. It also makes it difficult to make changes to the test_book since it can affect other tests. This works by placing the books in the tests/gui/books directory. The test runner will automatically build all the books. The gui tests can then just access the DOC_PATH with the name of the book. Books are now saved in a temp directory to make it easier to use the DOC_PATH variable, instead of being tests/gui/books/book_name/book which is a little awkward. Following commits will restructure the existing book. This is just a mechanical move.
70 lines
2.7 KiB
Plaintext
70 lines
2.7 KiB
Plaintext
// This GUI test checks sidebar hide/show and also its behaviour on smaller
|
|
// width.
|
|
|
|
go-to: |DOC_PATH| + "test_book/index.html"
|
|
set-window-size: (1100, 600)
|
|
// Need to reload for the new size to be taken account by the JS.
|
|
reload:
|
|
|
|
store-value: (content_indent, 308)
|
|
store-value: (sidebar_storage_value, "mdbook-sidebar")
|
|
store-value: (sidebar_storage_hidden_value, "hidden")
|
|
store-value: (sidebar_storage_displayed_value, "visible")
|
|
|
|
define-function: (
|
|
"hide-sidebar",
|
|
[],
|
|
block {
|
|
assert-position: ("#mdbook-page-wrapper", {"x": |content_indent|})
|
|
|
|
// We now hide the sidebar.
|
|
click: "#mdbook-sidebar-toggle"
|
|
wait-for-css: ("#mdbook-sidebar", {"display": "none"})
|
|
assert-local-storage: {|sidebar_storage_value|: |sidebar_storage_hidden_value|}
|
|
},
|
|
)
|
|
|
|
define-function: (
|
|
"show-sidebar",
|
|
[],
|
|
block {
|
|
assert-css: ("#mdbook-sidebar", {"display": "none"})
|
|
assert-position: ("#mdbook-page-wrapper", {"x": 0})
|
|
|
|
// We expand the sidebar.
|
|
click: "#mdbook-sidebar-toggle"
|
|
wait-for-css-false: ("#mdbook-sidebar", {"display": "none"})
|
|
// `transform` is 0.3s so we need to wait a bit (0.5s) to ensure the animation is done.
|
|
wait-for: 5000
|
|
assert-css-false: ("#mdbook-sidebar", {"transform": "matrix(1, 0, 0, 1, -308, 0)"})
|
|
// The page content should be moved to the right.
|
|
assert-position: ("#mdbook-page-wrapper", {"x": |content_indent|})
|
|
assert-local-storage: {|sidebar_storage_value|: |sidebar_storage_displayed_value|}
|
|
},
|
|
)
|
|
|
|
// Since the sidebar is visible, we should be able to find this text.
|
|
assert-find-text: ("3.9. Links and Horizontal Rule", {"case-sensitive": true})
|
|
call-function: ("hide-sidebar", {})
|
|
// Text should not be findeable anymore since the sidebar is collapsed.
|
|
assert-find-text-false: ("3.9. Links and Horizontal Rule", {"case-sensitive": true})
|
|
call-function: ("show-sidebar", {})
|
|
// We should be able to find this text again.
|
|
assert-find-text: ("3.9. Links and Horizontal Rule", {"case-sensitive": true})
|
|
|
|
// We now test on smaller width to ensure that the sidebar is collapsed by default.
|
|
set-window-size: (900, 600)
|
|
reload:
|
|
call-function: ("show-sidebar", {})
|
|
call-function: ("hide-sidebar", {})
|
|
|
|
// We now test that if the sidebar is considered open and we reload the page, since
|
|
// the width is small, it will still be collapsed.
|
|
set-local-storage: {|sidebar_storage_value|: |sidebar_storage_displayed_value|}
|
|
reload:
|
|
// The stored value shouldn't have changed.
|
|
assert-local-storage: {|sidebar_storage_value|: |sidebar_storage_displayed_value|}
|
|
// But the sidebar should be hidden anyway.
|
|
assert-css: ("#mdbook-sidebar", {"display": "none"})
|
|
assert-position: ("#mdbook-page-wrapper", {"x": 0})
|