2025-03-09 09:10:50 -07:00
|
|
|
// This tests basic search behavior.
|
|
|
|
|
|
2025-06-25 18:20:59 +02:00
|
|
|
fail-on-js-error: true
|
2025-10-14 14:23:40 -07:00
|
|
|
go-to: |DOC_PATH| + "search/index.html"
|
2025-03-09 09:10:50 -07:00
|
|
|
|
|
|
|
|
define-function: (
|
|
|
|
|
"open-search",
|
|
|
|
|
[],
|
|
|
|
|
block {
|
2025-08-19 19:38:22 -07:00
|
|
|
assert-css: ("#mdbook-search-wrapper", {"display": "none"})
|
2025-05-26 10:58:53 -07:00
|
|
|
press-key: 's'
|
2025-08-19 19:38:22 -07:00
|
|
|
wait-for-css-false: ("#mdbook-search-wrapper", {"display": "none"})
|
2025-03-09 09:10:50 -07:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
call-function: ("open-search", {})
|
2025-08-19 19:38:22 -07:00
|
|
|
assert-text: ("#mdbook-searchresults-header", "")
|
2025-10-14 14:23:40 -07:00
|
|
|
write: "extraordinary"
|
|
|
|
|
wait-for-text: ("#mdbook-searchresults-header", "2 search results for 'extraordinary':")
|
2025-03-09 09:10:50 -07:00
|
|
|
// Close the search display
|
|
|
|
|
press-key: 'Escape'
|
2025-08-19 19:38:22 -07:00
|
|
|
wait-for-css: ("#mdbook-search-wrapper", {"display": "none"})
|
2025-03-09 09:10:50 -07:00
|
|
|
// Reopening the search should show the last value
|
|
|
|
|
call-function: ("open-search", {})
|
2025-10-14 14:23:40 -07:00
|
|
|
assert-text: ("#mdbook-searchresults-header", "2 search results for 'extraordinary':")
|
2025-03-09 09:10:50 -07:00
|
|
|
// Navigate to a sub-chapter
|
2025-10-14 14:23:40 -07:00
|
|
|
go-to: "./inner/chapter_2.html"
|
2025-08-19 19:38:22 -07:00
|
|
|
assert-text: ("#mdbook-searchresults-header", "")
|
2025-03-09 09:10:50 -07:00
|
|
|
call-function: ("open-search", {})
|
2025-10-14 14:23:40 -07:00
|
|
|
write: "kaleidoscope"
|
|
|
|
|
wait-for-text: ("#mdbook-searchresults-header", "2 search results for 'kaleidoscope':")
|
2025-02-21 00:34:22 +01:00
|
|
|
|
|
|
|
|
// Now we test search shortcuts and more page changes.
|
2025-10-14 14:23:40 -07:00
|
|
|
go-to: |DOC_PATH| + "search/index.html"
|
2025-02-21 00:34:22 +01:00
|
|
|
|
|
|
|
|
// This check is to ensure that the search bar is inside the search wrapper.
|
2025-08-19 19:38:22 -07:00
|
|
|
assert: "#mdbook-search-wrapper #mdbook-searchbar"
|
|
|
|
|
assert-css: ("#mdbook-search-wrapper", {"display": "none"})
|
2025-02-21 00:34:22 +01:00
|
|
|
|
2025-05-31 09:55:58 +02:00
|
|
|
// Now we make sure the search input appear with the `S` shortcut.
|
|
|
|
|
press-key: 's'
|
2025-08-19 19:38:22 -07:00
|
|
|
wait-for-css-false: ("#mdbook-search-wrapper", {"display": "none"})
|
2025-02-21 00:34:22 +01:00
|
|
|
// We ensure the search bar has the focus.
|
2025-08-27 15:15:08 -07:00
|
|
|
wait-for: "#mdbook-searchbar:focus"
|
2025-06-25 18:20:59 +02:00
|
|
|
// Pressing a key will therefore update the search input.
|
|
|
|
|
press-key: 't'
|
2025-08-19 19:38:22 -07:00
|
|
|
assert-text: ("#mdbook-searchbar", "t")
|
2025-02-21 00:34:22 +01:00
|
|
|
|
|
|
|
|
// Now we press `Escape` to ensure that the search input disappears again.
|
|
|
|
|
press-key: 'Escape'
|
2025-08-19 19:38:22 -07:00
|
|
|
wait-for-css: ("#mdbook-search-wrapper", {"display": "none"})
|
2025-02-21 00:34:22 +01:00
|
|
|
|
|
|
|
|
// Making it appear by clicking on the search button.
|
2025-08-19 19:38:22 -07:00
|
|
|
click: "#mdbook-search-toggle"
|
|
|
|
|
wait-for-css: ("#mdbook-search-wrapper", {"display": "block"})
|
2025-02-21 00:34:22 +01:00
|
|
|
// We ensure the search bar has the focus.
|
2025-08-19 19:38:22 -07:00
|
|
|
assert: "#mdbook-searchbar:focus"
|
2025-02-21 00:34:22 +01:00
|
|
|
|
2025-10-14 14:23:40 -07:00
|
|
|
// We input "thunder".
|
|
|
|
|
write: "thunder"
|
2025-02-21 00:34:22 +01:00
|
|
|
// The results should now appear.
|
2025-10-14 14:23:40 -07:00
|
|
|
wait-for-text: ("#mdbook-searchresults-header", "1 search result for 'thunder':")
|
2025-08-19 19:38:22 -07:00
|
|
|
assert: "#mdbook-searchresults"
|
2025-02-21 00:34:22 +01:00
|
|
|
// Ensure that the URL was updated as well.
|
2025-10-14 14:23:40 -07:00
|
|
|
assert-document-property: ({"URL": "?search=thunder"}, ENDS_WITH)
|
2025-02-21 00:34:22 +01:00
|
|
|
|
|
|
|
|
// 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.
|
2025-10-14 14:23:40 -07:00
|
|
|
go-to: |DOC_PATH| + "search/index.html?search=thunder"
|
|
|
|
|
wait-for-text: ("#mdbook-searchresults-header", "1 search result for 'thunder':")
|
2025-08-19 19:38:22 -07:00
|
|
|
assert: "#mdbook-searchbar:focus"
|
|
|
|
|
assert: "#mdbook-searchresults"
|
2025-02-21 00:34:22 +01:00
|
|
|
|
|
|
|
|
// And now we press `Escape` to close everything.
|
|
|
|
|
press-key: 'Escape'
|
2025-08-19 19:38:22 -07:00
|
|
|
wait-for-css: ("#mdbook-search-wrapper", {"display": "none"})
|