Skip to content

Commit 38b4ea7

Browse files
Add GUI test for search
1 parent 286d323 commit 38b4ea7

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

tests/gui/search.goml

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

tests/gui/sidebar-nojs.goml

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 3 deletions
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)