Skip to content

Commit 06345c8

Browse files
authored
test: add playwright test for ask interaction (#94)
1 parent eeb8fa1 commit 06345c8

File tree

3 files changed

+135
-1
lines changed

3 files changed

+135
-1
lines changed

packages/chat-component/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export class ChatComponent extends LitElement {
340340
}
341341
// Render text entries in bubbles
342342
renderTextEntry(textEntry: ChatMessageText) {
343-
const entries = [html`<p>${unsafeHTML(textEntry.value)}</p>`];
343+
const entries = [html`<p class="chat__txt--entry">${unsafeHTML(textEntry.value)}</p>`];
344344

345345
// render steps
346346
if (textEntry.followingSteps && textEntry.followingSteps.length > 0) {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"log": {
3+
"version": "1.2",
4+
"creator": {
5+
"name": "Playwright",
6+
"version": "1.39.0"
7+
},
8+
"browser": {
9+
"name": "chromium",
10+
"version": "119.0.6045.9"
11+
},
12+
"entries": [
13+
{
14+
"startedDateTime": "2023-10-27T08:26:30.487Z",
15+
"time": 260.506,
16+
"request": {
17+
"method": "POST",
18+
"url": "http://localhost:5173/ask",
19+
"httpVersion": "HTTP/2.0",
20+
"cookies": [],
21+
"headers": [
22+
{ "name": ":authority", "value": "http://localhost:5173" },
23+
{ "name": ":method", "value": "POST" },
24+
{ "name": ":path", "value": "/ask" },
25+
{ "name": ":scheme", "value": "https" },
26+
{ "name": "accept", "value": "*/*" },
27+
{ "name": "accept-encoding", "value": "gzip, deflate, br" },
28+
{ "name": "accept-language", "value": "en-US" },
29+
{ "name": "content-length", "value": "416" },
30+
{ "name": "content-type", "value": "application/json" },
31+
{ "name": "origin", "value": "http://localhost:5173" },
32+
{ "name": "sec-fetch-dest", "value": "empty" },
33+
{ "name": "sec-fetch-mode", "value": "cors" },
34+
{ "name": "sec-fetch-site", "value": "cross-site" },
35+
{
36+
"name": "user-agent",
37+
"value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.9 Safari/537.36"
38+
}
39+
],
40+
"queryString": [],
41+
"headersSize": -1,
42+
"bodySize": -1,
43+
"postData": {
44+
"mimeType": "application/json",
45+
"text": "{\"messages\":[{\"content\":\"How to search and book rentals?\",\"role\":\"user\"}],\"context\":{\"retrieval_mode\":\"hybrid\",\"semantic_ranker\":true,\"semantic_captions\":false,\"suggest_followup_questions\":true,\"retrievalMode\":\"hybrid\",\"retrieveCount\":3,\"useSemanticRanker\":true,\"useSemanticCaptions\":false,\"excludeCategory\":\"\",\"promptTemplate\":\"\",\"promptTemplatePrefix\":\"\",\"promptTemplateSuffix\":\"\",\"approach\":\"rrr\"},\"stream\":false}",
46+
"params": []
47+
}
48+
},
49+
"response": {
50+
"status": 200,
51+
"statusText": "",
52+
"httpVersion": "HTTP/2.0",
53+
"cookies": [],
54+
"headers": [
55+
{ "name": "access-control-allow-origin", "value": "http://localhost:5173" },
56+
{ "name": "content-length", "value": "277" },
57+
{ "name": "content-type", "value": "application/json; charset=utf-8" },
58+
{ "name": "date", "value": "Fri, 27 Oct 2023 08:26:31 GMT" },
59+
{ "name": "vary", "value": "Origin" }
60+
],
61+
"content": {
62+
"size": -1,
63+
"mimeType": "application/json; charset=utf-8",
64+
"text": "{\"choices\":[{\"index\":0,\"message\":{\"content\":\"I don't know the answer to that question.\",\"role\":\"assistant\",\"context\":{\"data_points\":[],\"thoughts\":\"[chain/start] [<b>1:chain:AgentExecutor</b>] Entering chain<br><br>[chain/end] Finished chain<br>\"}}}],\"object\":\"chat.completion\"}"
65+
},
66+
"headersSize": -1,
67+
"bodySize": -1,
68+
"redirectURL": ""
69+
},
70+
"cache": {},
71+
"timings": { "send": -1, "wait": -1, "receive": 260.506 }
72+
}
73+
]
74+
}
75+
}

tests/e2e/webapp.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ test.describe('default', () => {
2929
await page.routeFromHAR('./tests/e2e/hars/default-chat-response-stream.har', {
3030
url: '/chat',
3131
update: false,
32+
updateContent: 'embed',
3233
});
3334

3435
const showThoughtProcess = page.getByTestId('chat-show-thought-process');
@@ -58,6 +59,64 @@ test.describe('default', () => {
5859
});
5960
});
6061

62+
test('ask interaction', async ({ page }) => {
63+
await page.goto('/');
64+
const chatLink = page.getByRole('link', { name: 'Chat' });
65+
const askLink = page.getByRole('link', { name: 'Ask a question' });
66+
67+
await expect(chatLink).toHaveAttribute('aria-current', 'page');
68+
await expect(askLink).not.toHaveAttribute('aria-current');
69+
await askLink.click();
70+
await expect(chatLink).not.toHaveAttribute('aria-current');
71+
await expect(askLink).toHaveAttribute('aria-current', 'page');
72+
73+
const defaultQuestions = page.getByTestId('default-question');
74+
75+
// expect there to be at least 3 default question buttons on page load
76+
await test.step('Get default questions', async () => {
77+
await expect(defaultQuestions).toHaveCount(3);
78+
});
79+
80+
const chatInput = page.getByTestId('question-input');
81+
const firstQuestionButton = defaultQuestions.nth(0);
82+
const firstQuestionText = ((await firstQuestionButton.textContent()) ?? '').replace('Ask now', '').trim();
83+
84+
// should not have any text at the start
85+
await test.step('Use default question', async () => {
86+
await expect(chatInput).toHaveValue('');
87+
88+
await firstQuestionButton.click();
89+
await expect(chatInput).toHaveValue(firstQuestionText);
90+
});
91+
92+
// Set to replay the response for a local route (will not be used for the official)
93+
await page.routeFromHAR('./tests/e2e/hars/default-ask-response.har', {
94+
url: '/ask',
95+
update: false,
96+
updateContent: 'embed',
97+
});
98+
99+
const showThoughtProcess = page.getByTestId('chat-show-thought-process');
100+
await test.step('Get answer', async () => {
101+
await expect(showThoughtProcess).not.toBeVisible();
102+
103+
await page.getByTestId('submit-question-button').click();
104+
105+
// wait for the thought process button to be enabled.
106+
await expect(showThoughtProcess).toBeEnabled({ timeout: 30_000 });
107+
108+
// expect some response
109+
await expect(page.locator('.chat__txt--entry')).not.toHaveText('');
110+
await expect(defaultQuestions).toHaveCount(0);
111+
});
112+
113+
await test.step('Reset chat', async () => {
114+
await page.getByTestId('chat-reset-button').click();
115+
await expect(page.locator('.chat__txt--entry')).not.toBeVisible();
116+
await expect(defaultQuestions).toHaveCount(3);
117+
});
118+
});
119+
61120
test('waiting for response', async ({ page }) => {
62121
await page.goto('/');
63122
await page.getByTestId('default-question').nth(0).click();

0 commit comments

Comments
 (0)