Skip to content

Commit 3a8e4b6

Browse files
'Ask free question' Playwright e2e test body shows explicit assertion
Re-engineered the test to not use shared helper function. This requires unloading askQuestion helper contents in 'Ask free question' test body, then removing the askQuestion helper. NOTE: the 'Hide/Show chatbot panel' test was using the same shared helper, so I performed unloading askQuestion helper contents into this test also.
1 parent cc92547 commit 3a8e4b6

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

webviewer-ask-ai/__tests__/e2e/webviewer-ask-ai.spec.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import { test, expect } from '@playwright/test';
55
import { 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
4749
test('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.
7184
test('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

Comments
 (0)