Skip to content

Commit 8b5125d

Browse files
Add GUI test for search
1 parent 1eb49c5 commit 8b5125d

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

tests/gui/search.goml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This GUI test checks search is working as expected.
2+
3+
go-to: |DOC_PATH| + "index.html"
4+
// First we ensure that the search input is disabled and hidden.
5+
assert: "#searchbar:disabled"
6+
// This check is to ensure that the search bar is inside the search wrapper.
7+
assert: "#search-wrapper #searchbar"
8+
assert-css: ("#search-wrapper", {"display": "none"})
9+
10+
// Now we make the search input appear with the `S` shortcut.
11+
press-key: 'S'
12+
wait-for: "#searchbar:not(:disabled)"
13+
assert-css: ("#search-wrapper", {"display": "block"})
14+
// We ensure the search bar has the focus.
15+
assert: "#searchbar:focus"
16+
17+
// Now we press `Escape` to ensure that the search input disappears again.
18+
press-key: 'Escape'
19+
wait-for-css: ("#search-wrapper", {"display": "none"})
20+
21+
// Making it appear by clicking on the search button.
22+
click: "#search-toggle"
23+
wait-for-css: ("#search-wrapper", {"display": "block"})
24+
// We ensure the search bar has the focus.
25+
assert: "#searchbar:focus"
26+
27+
// We input "test".
28+
write: "test"
29+
// The results should now appear.
30+
wait-for-text: ("#searchresults-header", "search results for 'test':", ENDS_WITH)
31+
assert: "#searchresults"
32+
// Ensure that the URL was updated as well.
33+
assert-document-property: ({"URL": "?search=test"}, ENDS_WITH)
34+
35+
// Now we ensure that when we land on the page with a "search in progress", the search results are
36+
// loaded and that the search input has focus.
37+
go-to: |DOC_PATH| + "index.html?search=test"
38+
wait-for-text: ("#searchresults-header", "search results for 'test':", ENDS_WITH)
39+
assert: "#searchbar:focus"
40+
assert: "#searchresults"
41+
42+
// And now we press `Escape` to close everything.
43+
press-key: 'Escape'
44+
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)