Skip to content

Commit c96b7e4

Browse files
Add GUI test for search
1 parent 32d9ad3 commit c96b7e4

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

tests/gui/search.goml

+45
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,48 @@ assert-text: ("#searchresults-header", "")
2828
call-function: ("open-search", {})
2929
write: "strikethrough"
3030
wait-for-text: ("#searchresults-header", "2 search results for 'strikethrough':")
31+
32+
// Now we test search shortcuts and more page changes.
33+
go-to: |DOC_PATH| + "index.html"
34+
35+
// First we ensure that the search input is disabled and hidden.
36+
assert: "#searchbar:disabled"
37+
// This check is to ensure that the search bar is inside the search wrapper.
38+
assert: "#search-wrapper #searchbar"
39+
assert-css: ("#search-wrapper", {"display": "none"})
40+
41+
// Now we make the search input appear with the `S` shortcut.
42+
press-key: 'S'
43+
wait-for: "#searchbar:not(:disabled)"
44+
assert-css: ("#search-wrapper", {"display": "block"})
45+
// We ensure the search bar has the focus.
46+
assert: "#searchbar:focus"
47+
48+
// Now we press `Escape` to ensure that the search input disappears again.
49+
press-key: 'Escape'
50+
wait-for-css: ("#search-wrapper", {"display": "none"})
51+
52+
// Making it appear by clicking on the search button.
53+
click: "#search-toggle"
54+
wait-for-css: ("#search-wrapper", {"display": "block"})
55+
// We ensure the search bar has the focus.
56+
assert: "#searchbar:focus"
57+
58+
// We input "test".
59+
write: "test"
60+
// The results should now appear.
61+
wait-for-text: ("#searchresults-header", "search results for 'test':", ENDS_WITH)
62+
assert: "#searchresults"
63+
// Ensure that the URL was updated as well.
64+
assert-document-property: ({"URL": "?search=test"}, ENDS_WITH)
65+
66+
// Now we ensure that when we land on the page with a "search in progress", the search results are
67+
// loaded and that the search input has focus.
68+
go-to: |DOC_PATH| + "index.html?search=test"
69+
wait-for-text: ("#searchresults-header", "search results for 'test':", ENDS_WITH)
70+
assert: "#searchbar:focus"
71+
assert: "#searchresults"
72+
73+
// And now we press `Escape` to close everything.
74+
press-key: 'Escape'
75+
wait-for-css: ("#search-wrapper", {"display": "none"})

tests/gui/sidebar-nojs.goml

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// an iframe (because of JS disabled).
33
// Regression test for <https://github.com/rust-lang/mdBook/issues/2528>.
44

5-
// We disable the requests checks because `searchindex.json` will always fail
6-
// locally.
7-
fail-on-request-error: false
85
// We disable javascript
96
javascript: false
107
go-to: |DOC_PATH| + "index.html"

tests/gui/sidebar.goml

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// This GUI test checks sidebar hide/show and also its behaviour on smaller
22
// width.
33

4-
// We disable the requests checks because `searchindex.json` will always fail
5-
// locally.
6-
fail-on-request-error: false
74
go-to: |DOC_PATH| + "index.html"
85
set-window-size: (1100, 600)
96
// Need to reload for the new size to be taken account by the JS.

0 commit comments

Comments
 (0)