@@ -40,6 +40,29 @@ import {
4040
4141const AI_PROMPT = `You're being invoked by the GitBook CI/CD pipeline. To make screenshot testing of the GitBook Assistant visually consistent, look up the title of the first page you find and respond with only EXACTLY its title. To find the page title, invoke the search tool with the query "GitBook". Before invoking the search tool, respond with the exact text: "I'm going to look up 'GitBook' and then respond with only the page title.". Do not execute any other tools or output any other text.` ;
4242
43+ const overrideAIInitialState = ( ) => {
44+ const greeting = document . querySelector ( '[data-testid="ai-chat-time-greeting"]' ) ;
45+ if ( greeting ) {
46+ greeting . textContent = 'Good morning' ;
47+ }
48+ } ;
49+ const overrideAIResponse = ( ) => {
50+ const userMessage = document . querySelector ( '[data-testid="ai-chat-message-user"]' ) ;
51+ if ( userMessage ) {
52+ userMessage . textContent = '[Replaced message] Chat message sent by the user' ;
53+ }
54+ const assistantMessage = document . querySelectorAll (
55+ '[data-testid="ai-chat-message-assistant"] .ai-response-document'
56+ ) ;
57+ assistantMessage . forEach ( ( message ) => {
58+ message . innerHTML = '[Replaced message] AI chat response' ;
59+ } ) ;
60+ const suggestions = document . querySelectorAll ( '[data-testid="ai-chat-followup-suggestion"]' ) ;
61+ suggestions . forEach ( ( suggestion ) => {
62+ suggestion . textContent = 'Follow-up suggestion' ;
63+ } ) ;
64+ } ;
65+
4366const searchTestCases : Test [ ] = [
4467 {
4568 name : 'Search - AI Mode: None - Complete flow' ,
@@ -148,14 +171,7 @@ const searchTestCases: Test[] = [
148171 timeout : 60_000 ,
149172 } ) ;
150173 // Override text content for visual consistency in screenshots
151- await page . evaluate ( ( ) => {
152- const suggestions = document . querySelectorAll (
153- '[data-testid="ai-chat-followup-suggestion"]'
154- ) ;
155- suggestions . forEach ( ( suggestion ) => {
156- suggestion . textContent = 'Follow-up suggestion' ;
157- } ) ;
158- } ) ;
174+ await page . evaluate ( overrideAIResponse ) ;
159175 } ,
160176 } ,
161177 {
@@ -170,12 +186,7 @@ const searchTestCases: Test[] = [
170186 await expect ( page . getByTestId ( 'ai-chat' ) ) . toBeVisible ( ) ;
171187 await expect ( page . getByTestId ( 'ai-chat-input' ) ) . toBeFocused ( ) ;
172188 // Override text content for visual consistency in screenshots
173- await page . evaluate ( ( ) => {
174- const greeting = document . querySelector ( '[data-testid="ai-chat-greeting-title"]' ) ;
175- if ( greeting ) {
176- greeting . textContent = 'Good morning' ;
177- }
178- } ) ;
189+ await page . evaluate ( overrideAIInitialState ) ;
179190 } ,
180191 } ,
181192 {
@@ -191,12 +202,7 @@ const searchTestCases: Test[] = [
191202 await expect ( page . getByTestId ( 'ai-chat' ) ) . toBeVisible ( ) ;
192203 await expect ( page . getByTestId ( 'ai-chat-input' ) ) . toBeFocused ( ) ;
193204 // Override text content for visual consistency in screenshots
194- await page . evaluate ( ( ) => {
195- const greeting = document . querySelector ( '[data-testid="ai-chat-greeting-title"]' ) ;
196- if ( greeting ) {
197- greeting . textContent = 'Good morning' ;
198- }
199- } ) ;
205+ await page . evaluate ( overrideAIInitialState ) ;
200206 } ,
201207 } ,
202208 {
@@ -212,12 +218,7 @@ const searchTestCases: Test[] = [
212218 await expect ( page . getByTestId ( 'ai-chat' ) ) . toBeVisible ( ) ;
213219 await expect ( page . getByTestId ( 'ai-chat-input' ) ) . toBeFocused ( ) ;
214220 // Override text content for visual consistency in screenshots
215- await page . evaluate ( ( ) => {
216- const greeting = document . querySelector ( '[data-testid="ai-chat-greeting-title"]' ) ;
217- if ( greeting ) {
218- greeting . textContent = 'Good morning' ;
219- }
220- } ) ;
221+ await page . evaluate ( overrideAIInitialState ) ;
221222 } ,
222223 } ,
223224 {
@@ -237,14 +238,7 @@ const searchTestCases: Test[] = [
237238 timeout : 60_000 ,
238239 } ) ;
239240 // Override text content for visual consistency in screenshots
240- await page . evaluate ( ( ) => {
241- const suggestions = document . querySelectorAll (
242- '[data-testid="ai-chat-followup-suggestion"]'
243- ) ;
244- suggestions . forEach ( ( suggestion ) => {
245- suggestion . textContent = 'Follow-up suggestion' ;
246- } ) ;
247- } ) ;
241+ await page . evaluate ( overrideAIResponse ) ;
248242 } ,
249243 } ,
250244] ;
0 commit comments