44import { test , expect } from '@playwright/test' ;
55import { MOCK_RESPONSE , registerApiChatMock } from '../../__mocks__/webviewer-ask-ai.mock.js' ;
66
7+ const question = 'What social responsibility initiatives did Rosneft undertake in 2011?' ;
8+
79// Register the API chat mock before each test
810// to ensure consistent and predictable responses
911// from the chatbot during testing.
@@ -45,7 +47,16 @@ test('Summarizing selection button visibility', async ({ page }) => {
4547
4648// Simulates user asking free question within the chatbot panel
4749test ( 'Ask free question' , async ( { page } ) => {
48- await askQuestion ( page ) ;
50+ await page . goto ( '/client/index.html' ) ;
51+
52+ // Locate the question input field, enter a question, and submit it by pressing 'Enter'
53+ const questionInput = page . locator ( '#askWebSDKQuestionInput' ) ;
54+ await questionInput . fill ( question ) ;
55+ await questionInput . press ( 'Enter' ) ;
56+
57+ // Validate that the assistant's response contains the expected text from the mock response
58+ const assistantResponse = page . locator ( '.askWebSDKAssistantMessageClass' ) . last ( ) ;
59+ await expect ( assistantResponse ) . toContainText ( MOCK_RESPONSE . DOCUMENT_QUESTION ) ;
4960} ) ;
5061
5162// Simulates user selecting text on the document and asking the chatbot to summarize it
@@ -67,9 +78,16 @@ test('Summarize selected text', async ({ page }) => {
6778 await expect ( assistantResponse ) . toContainText ( MOCK_RESPONSE . SELECTED_TEXT_SUMMARY ) ;
6879} ) ;
6980
70- // Simulates user hiding and showing the chatbot panel using the toggle button in the header
81+ // Simulates user hiding and showing the chatbot panel
82+ // via clicking the toggle button in the header.
83+ // Chatbot panel should maintain the visibility of the conversation.
7184test ( 'Hide/Show chatbot panel' , async ( { page } ) => {
72- await askQuestion ( page ) ;
85+ await page . goto ( '/client/index.html' ) ;
86+
87+ // Locate the question input field, enter a question, and submit it by pressing 'Enter'
88+ const questionInput = page . locator ( '#askWebSDKQuestionInput' ) ;
89+ await questionInput . fill ( question ) ;
90+ await questionInput . press ( 'Enter' ) ;
7391
7492 // Locate the toggle button and chatbot panel
7593 const toggle = page . locator ( 'button[data-element="askWebSDKPanelToggle"]' ) ;
@@ -110,18 +128,4 @@ const simulateDocumentTextSelection = async (page, { pageNumber, start, end }) =
110128 const instance = globalThis . WebViewer . getInstance ( ) ;
111129 instance . UI . openElements ( [ 'textPopup' ] ) ;
112130 } ) ;
113- } ;
114-
115- // Helper function to simulate asking a free question in the chatbot panel
116- const askQuestion = async ( page ) => {
117- await page . goto ( '/client/index.html' ) ;
118-
119- // Locate the question input field, enter a question, and submit it by pressing 'Enter'
120- const questionInput = page . locator ( '#askWebSDKQuestionInput' ) ;
121- await questionInput . fill ( 'What social responsibility initiatives did Rosneft undertake in 2011?' ) ;
122- await questionInput . press ( 'Enter' ) ;
123-
124- // Validate that the assistant's response contains the expected text from the mock response
125- const assistantResponse = page . locator ( '.askWebSDKAssistantMessageClass' ) . last ( ) ;
126- await expect ( assistantResponse ) . toContainText ( MOCK_RESPONSE . DOCUMENT_QUESTION ) ;
127131} ;
0 commit comments