9
9
CustomizationSidebarListStyle ,
10
10
CustomizationThemeMode ,
11
11
} from '@gitbook/api' ;
12
- import { expect } from '@playwright/test' ;
12
+ import { type Page , expect } from '@playwright/test' ;
13
13
import jwt from 'jsonwebtoken' ;
14
14
15
15
import {
@@ -36,6 +36,10 @@ import {
36
36
waitForNotFound ,
37
37
} from './util' ;
38
38
39
+ async function expectResultsToBeVisible ( page : Page ) {
40
+ await expect ( page . getByTestId ( 'search-results' ) ) . toBeVisible ( { timeout : 15_000 } ) ;
41
+ }
42
+
39
43
const searchTestCases : Test [ ] = [
40
44
{
41
45
name : 'Search - AI Mode: None - Complete flow' ,
@@ -48,11 +52,12 @@ const searchTestCases: Test[] = [
48
52
run : async ( page ) => {
49
53
const searchInput = page . getByTestId ( 'search-input' ) ;
50
54
await searchInput . focus ( ) ;
55
+ await expectResultsToBeVisible ( page ) ;
51
56
await expect ( page . getByTestId ( 'search-results' ) ) . toHaveCount ( 0 ) ; // No pop-up yet because there's no recommended questions.
52
57
53
58
// Fill search input, expecting search results
54
59
await searchInput . fill ( 'gitbook' ) ;
55
- await expect ( page . getByTestId ( 'search-results' ) ) . toBeVisible ( ) ;
60
+ await expectResultsToBeVisible ( page ) ;
56
61
const pageResults = await page . getByTestId ( 'search-page-result' ) . all ( ) ;
57
62
await expect ( pageResults . length ) . toBeGreaterThan ( 2 ) ;
58
63
const pageSectionResults = await page . getByTestId ( 'search-page-section-result' ) . all ( ) ;
@@ -81,6 +86,7 @@ const searchTestCases: Test[] = [
81
86
} ,
82
87
} ) } &q=`,
83
88
run : async ( page ) => {
89
+ await expectResultsToBeVisible ( page ) ;
84
90
await expect ( page . getByTestId ( 'search-results' ) ) . toHaveCount ( 0 ) ; // No pop-up yet because there's no recommended questions.
85
91
} ,
86
92
} ,
@@ -94,7 +100,7 @@ const searchTestCases: Test[] = [
94
100
run : async ( page ) => {
95
101
await expect ( page . getByTestId ( 'search-input' ) ) . toBeFocused ( ) ;
96
102
await expect ( page . getByTestId ( 'search-input' ) ) . toHaveValue ( 'gitbook' ) ;
97
- await expect ( page . getByTestId ( 'search-results' ) ) . toBeVisible ( ) ;
103
+ await expectResultsToBeVisible ( page ) ;
98
104
} ,
99
105
} ,
100
106
{
@@ -110,15 +116,15 @@ const searchTestCases: Test[] = [
110
116
111
117
// Focus search input, expecting recommended questions
112
118
await searchInput . focus ( ) ;
113
- await expect ( page . getByTestId ( 'search-results' ) ) . toBeVisible ( ) ;
119
+ await expectResultsToBeVisible ( page ) ;
114
120
const recommendedQuestions = await page
115
121
. getByTestId ( 'search-recommended-question' )
116
122
. all ( ) ;
117
123
await expect ( recommendedQuestions . length ) . toBeGreaterThan ( 2 ) ; // Expect at least 3 questions
118
124
119
125
// Fill search input, expecting AI search option
120
126
await searchInput . fill ( 'What is gitbook?' ) ;
121
- await expect ( page . getByTestId ( 'search-results' ) ) . toBeVisible ( ) ;
127
+ await expectResultsToBeVisible ( page ) ;
122
128
const aiSearchResult = page . getByTestId ( 'search-ask-question' ) ;
123
129
await expect ( aiSearchResult ) . toBeVisible ( ) ;
124
130
await aiSearchResult . click ( ) ;
@@ -137,7 +143,7 @@ const searchTestCases: Test[] = [
137
143
screenshot : false ,
138
144
run : async ( page ) => {
139
145
await expect ( page . getByTestId ( 'search-input' ) ) . toBeFocused ( ) ;
140
- await expect ( page . getByTestId ( 'search-results' ) ) . toBeVisible ( ) ;
146
+ await expectResultsToBeVisible ( page ) ;
141
147
const recommendedQuestions = await page
142
148
. getByTestId ( 'search-recommended-question' )
143
149
. all ( ) ;
@@ -155,7 +161,7 @@ const searchTestCases: Test[] = [
155
161
run : async ( page ) => {
156
162
await expect ( page . getByTestId ( 'search-input' ) ) . toBeFocused ( ) ;
157
163
await expect ( page . getByTestId ( 'search-input' ) ) . toHaveValue ( 'gitbook' ) ;
158
- await expect ( page . getByTestId ( 'search-results' ) ) . toBeVisible ( ) ;
164
+ await expectResultsToBeVisible ( page ) ;
159
165
} ,
160
166
} ,
161
167
{
@@ -168,7 +174,7 @@ const searchTestCases: Test[] = [
168
174
screenshot : false ,
169
175
run : async ( page ) => {
170
176
await expect ( page . getByTestId ( 'search-input' ) ) . toBeFocused ( ) ;
171
- await expect ( page . getByTestId ( 'search-results' ) ) . toBeVisible ( ) ;
177
+ await expectResultsToBeVisible ( page ) ;
172
178
const recommendedQuestions = await page
173
179
. getByTestId ( 'search-recommended-question' )
174
180
. all ( ) ;
@@ -204,7 +210,7 @@ const searchTestCases: Test[] = [
204
210
205
211
// Focus search input, expecting recommended questions
206
212
await searchInput . focus ( ) ;
207
- await expect ( page . getByTestId ( 'search-results' ) ) . toBeVisible ( ) ;
213
+ await expectResultsToBeVisible ( page ) ;
208
214
const recommendedQuestions = await page
209
215
. getByTestId ( 'search-recommended-question' )
210
216
. all ( ) ;
0 commit comments