mdbook/tests/gui/search.goml
Eric Huss e37e5314f8 Support multiple books in the GUI tests
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.
2025-10-15 07:00:33 -07:00

76 lines
2.8 KiB
Text

// This tests basic search behavior.
fail-on-js-error: true
go-to: |DOC_PATH| + "test_book/index.html"
define-function: (
"open-search",
[],
block {
assert-css: ("#mdbook-search-wrapper", {"display": "none"})
press-key: 's'
wait-for-css-false: ("#mdbook-search-wrapper", {"display": "none"})
}
)
call-function: ("open-search", {})
assert-text: ("#mdbook-searchresults-header", "")
write: "strikethrough"
wait-for-text: ("#mdbook-searchresults-header", "2 search results for 'strikethrough':")
// Close the search display
press-key: 'Escape'
wait-for-css: ("#mdbook-search-wrapper", {"display": "none"})
// Reopening the search should show the last value
call-function: ("open-search", {})
assert-text: ("#mdbook-searchresults-header", "2 search results for 'strikethrough':")
// Navigate to a sub-chapter
go-to: "./individual/strikethrough.html"
assert-text: ("#mdbook-searchresults-header", "")
call-function: ("open-search", {})
write: "strikethrough"
wait-for-text: ("#mdbook-searchresults-header", "2 search results for 'strikethrough':")
// Now we test search shortcuts and more page changes.
go-to: |DOC_PATH| + "test_book/index.html"
// This check is to ensure that the search bar is inside the search wrapper.
assert: "#mdbook-search-wrapper #mdbook-searchbar"
assert-css: ("#mdbook-search-wrapper", {"display": "none"})
// Now we make sure the search input appear with the `S` shortcut.
press-key: 's'
wait-for-css-false: ("#mdbook-search-wrapper", {"display": "none"})
// We ensure the search bar has the focus.
wait-for: "#mdbook-searchbar:focus"
// Pressing a key will therefore update the search input.
press-key: 't'
assert-text: ("#mdbook-searchbar", "t")
// Now we press `Escape` to ensure that the search input disappears again.
press-key: 'Escape'
wait-for-css: ("#mdbook-search-wrapper", {"display": "none"})
// Making it appear by clicking on the search button.
click: "#mdbook-search-toggle"
wait-for-css: ("#mdbook-search-wrapper", {"display": "block"})
// We ensure the search bar has the focus.
assert: "#mdbook-searchbar:focus"
// We input "test".
write: "test"
// The results should now appear.
wait-for-text: ("#mdbook-searchresults-header", "search results for 'test':", ENDS_WITH)
assert: "#mdbook-searchresults"
// Ensure that the URL was updated as well.
assert-document-property: ({"URL": "?search=test"}, ENDS_WITH)
// Now we ensure that when we land on the page with a "search in progress", the search results are
// loaded and that the search input has focus.
go-to: |DOC_PATH| + "test_book/index.html?search=test"
wait-for-text: ("#mdbook-searchresults-header", "search results for 'test':", ENDS_WITH)
assert: "#mdbook-searchbar:focus"
assert: "#mdbook-searchresults"
// And now we press `Escape` to close everything.
press-key: 'Escape'
wait-for-css: ("#mdbook-search-wrapper", {"display": "none"})