Skip to content

Commit 3afb6a4

Browse files
committed
added reusable steps
1 parent bb0eeb1 commit 3afb6a4

File tree

4 files changed

+85
-101
lines changed

4 files changed

+85
-101
lines changed

ui/desktop/tests/e2e/chat.spec.ts

Lines changed: 24 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { test } from './fixtures.electron.packaged';
22
import { expect } from '@playwright/test';
3-
import { waitForLoadingDone } from './helpers/video';
4-
5-
const LLM_TIMEOUT = 30000;
3+
import { expectChatContainsMessage, expectLastChatMessageContains, expectChatMessageCount, expectSessionCount, goToChatHistory, goToHome, openSession, sendMessage } from './helpers/test-steps';
64

75
test.describe('Goose App', {tag: '@release'}, () => {
86
test('goose conversation', async ({ goosePage }) => {
@@ -11,9 +9,7 @@ test.describe('Goose App', {tag: '@release'}, () => {
119
await expect(goosePage.getByRole('button', { name: 'New Chat' }).first()).toBeVisible();
1210
await expect(goosePage.getByTestId('chat-show-all')).toHaveCount(0);
1311

14-
await goosePage.getByTestId('sidebar-home-button').click();
15-
const chatInput = goosePage.locator('[data-testid="chat-input"]:visible').first();
16-
await expect(chatInput).toBeVisible();
12+
await goToHome(goosePage);
1713

1814
const costTrigger = goosePage.getByTestId('bottom-menu-cost-trigger').first();
1915
const costTooltip = goosePage.getByTestId('bottom-menu-cost-tooltip').first();
@@ -23,61 +19,29 @@ test.describe('Goose App', {tag: '@release'}, () => {
2319
'Input: 0 tokens ($0.000000) | Output: 0 tokens ($0.000000)'
2420
);
2521

26-
await chatInput.fill('Hello First');
27-
await chatInput.press('Enter');
28-
29-
await waitForLoadingDone(goosePage, LLM_TIMEOUT);
30-
await expect(goosePage.locator('[data-testid="message-container"]:visible').last()).toBeVisible();
22+
await sendMessage(goosePage, 'Hello First');
3123

32-
await chatInput.fill('Hello First');
33-
await chatInput.press('Enter');
34-
await waitForLoadingDone(goosePage, LLM_TIMEOUT);
24+
await sendMessage(goosePage, 'Hello Second');
3525

3626
await costTrigger.hover();
3727
await expect(costTrigger).not.toContainText('0.0000');
3828
await expect(costTooltip).not.toContainText(
3929
'Input: 0 tokens ($0.000000) | Output: 0 tokens ($0.000000)'
4030
);
4131

42-
const showAllAfterChat = goosePage.getByTestId('chat-show-all').first();
43-
if (!(await showAllAfterChat.isVisible().catch(() => false))) {
44-
await goosePage.getByTestId('sidebar-chat-button').click();
45-
}
46-
await expect(showAllAfterChat).toBeVisible();
47-
await showAllAfterChat.click();
48-
await expect(goosePage.getByRole('heading', { name: 'Chat history' })).toBeVisible();
49-
const historyCards = goosePage.getByTestId('session-history-card');
50-
const historyCountAfterFirstConversation = await historyCards.count();
51-
expect(historyCountAfterFirstConversation).toBeGreaterThanOrEqual(1);
52-
53-
await goosePage.getByTestId('sidebar-home-button').click();
54-
const hubChatInput = goosePage.locator('[data-testid="chat-input"]:visible').first();
55-
await expect(hubChatInput).toBeVisible();
56-
await expect(goosePage.locator('[data-testid="message-container"]:visible')).toHaveCount(0);
57-
58-
await hubChatInput.fill('Hello from hub');
59-
await hubChatInput.press('Enter');
60-
await waitForLoadingDone(goosePage, LLM_TIMEOUT);
61-
await expect(goosePage.locator('[data-testid="message-container"]:visible')).toHaveCount(2);
62-
63-
const showAllAfterHubConversation = goosePage.getByTestId('chat-show-all').first();
64-
if (!(await showAllAfterHubConversation.isVisible().catch(() => false))) {
65-
await goosePage.getByTestId('sidebar-chat-button').click();
66-
}
67-
await expect(showAllAfterHubConversation).toBeVisible();
68-
await showAllAfterHubConversation.click();
69-
await expect(goosePage.getByRole('heading', { name: 'Chat history' })).toBeVisible();
70-
71-
const originalSessionCard = goosePage.getByTestId('session-history-card').nth(1);
72-
await originalSessionCard.click();
73-
const resumedChatInput = goosePage.locator('[data-testid="chat-input"]:visible').first();
74-
await expect(resumedChatInput).toBeVisible();
75-
await expect(
76-
goosePage
77-
.locator('[data-testid="message-container"]:visible')
78-
.filter({ hasText: 'Hello First' })
79-
.first()
80-
).toBeVisible();
32+
await goToChatHistory(goosePage);
33+
await expectSessionCount(goosePage, 1);
34+
35+
await goToHome(goosePage);
36+
await expectChatMessageCount(goosePage, 0);
37+
38+
await sendMessage(goosePage, 'Hello from hub');
39+
await expectChatMessageCount(goosePage, 2);
40+
41+
await goToChatHistory(goosePage);
42+
43+
await openSession(goosePage, 2);
44+
await expectChatContainsMessage(goosePage, 'Hello Second');
8145

8246
const workingDirButton = goosePage.locator('[data-testid="bottom-menu-dir-switcher"]:visible').first();
8347
await expect(workingDirButton).toBeVisible();
@@ -89,26 +53,18 @@ test.describe('Goose App', {tag: '@release'}, () => {
8953
const updatedWorkingDir = (await workingDirButton.textContent())?.trim() ?? '';
9054
expect(updatedWorkingDir.length).toBeGreaterThan(0);
9155

92-
await resumedChatInput.fill('what is your working directory? reply with exact path only');
93-
await resumedChatInput.press('Enter');
94-
await waitForLoadingDone(goosePage, LLM_TIMEOUT);
95-
await expect(goosePage.locator('[data-testid="message-container"]:visible').last()).toContainText(
96-
updatedWorkingDir
97-
);
56+
await sendMessage(goosePage, 'what is your working directory? reply with exact path only');
57+
await expectLastChatMessageContains(goosePage, updatedWorkingDir);
9858
});
9959

10060
test('developer tool is called', async ({ goosePage }) => {
10161

102-
await goosePage.getByTestId('sidebar-home-button').click();
103-
const chatInput = goosePage.locator('[data-testid="chat-input"]:visible').first();
104-
await expect(chatInput).toBeVisible();
62+
await goToHome(goosePage);
10563

10664
const toolCalls = goosePage.locator('.goose-message-tool');
10765
await expect(toolCalls).toHaveCount(0);
10866

109-
await chatInput.fill('show the number of files in current directory');
110-
await chatInput.press('Enter');
111-
await waitForLoadingDone(goosePage, LLM_TIMEOUT);
67+
await sendMessage(goosePage, 'show the number of files in current directory');
11268

11369
await expect(toolCalls).toHaveCount(1);
11470
const newestToolCall = toolCalls.first();
@@ -120,17 +76,9 @@ test.describe('Goose App', {tag: '@release'}, () => {
12076
});
12177

12278
test('verify chat history', async ({ goosePage }) => {
123-
const chatInput = goosePage.getByTestId('chat-input');
124-
await chatInput.fill('What is 2+2?');
125-
await chatInput.press('Enter');
126-
127-
await waitForLoadingDone(goosePage, LLM_TIMEOUT);
128-
129-
const response = goosePage.getByTestId('message-container').last();
130-
const responseText = await response.textContent();
131-
expect(responseText).toBeTruthy();
132-
133-
await expect(goosePage.getByTestId('message-container')).toHaveCount(2);
79+
await expectChatMessageCount(goosePage, 0);
80+
await sendMessage(goosePage, 'What is 2+2?');
81+
await expectChatMessageCount(goosePage, 2);
13482

13583
const chatInputForHistory = goosePage.getByTestId('chat-input');
13684
await chatInputForHistory.press('Control+ArrowUp');

ui/desktop/tests/e2e/extensions.spec.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { test } from './fixtures.electron.packaged';
22
import { expect } from '@playwright/test';
3-
import { waitForLoadingDone } from './helpers/video';
3+
import { expectLastChatMessageContains, goToHome, sendMessage } from './helpers/test-steps';
44
import { join } from 'path';
55

66
const { runningQuotes } = require('./basic-mcp');
7-
8-
const LLM_TIMEOUT = 30000;
97
const PLAYWRIGHT_DEEPLINK =
108
'goose://extension?cmd=npx&arg=-y&arg=@playwright/mcp@latest&id=playwright&name=Playwright&description=Modern%20web%20testing%20and%20automation';
119

@@ -31,22 +29,16 @@ test.describe('Goose App Extensions', {tag: '@release'}, () => {
3129
goosePage.locator('#extension-playwright button[role="switch"][data-state="checked"]')
3230
).toBeVisible();
3331

34-
await goosePage.getByTestId('sidebar-home-button').click();
35-
const chatInput = goosePage.locator('[data-testid="chat-input"]:visible').first();
36-
await expect(chatInput).toBeVisible();
37-
38-
await chatInput.fill('open a browser and search on google for cats');
39-
await chatInput.press('Enter');
40-
await waitForLoadingDone(goosePage, LLM_TIMEOUT);
32+
await goToHome(goosePage);
33+
await sendMessage(goosePage, 'open a browser and search on google for cats');
4134

4235
const toolCalls = goosePage.locator('.goose-message-tool');
4336
await expect(toolCalls.first()).toBeVisible();
4437

4538
const toolCallsText = ((await toolCalls.allTextContents()) || []).join(' ').toLowerCase();
4639
expect(toolCallsText).toMatch(/playwright|browser|navigate|google|cats/);
4740

48-
const latestMessage = goosePage.locator('[data-testid="message-container"]:visible').last();
49-
await expect(latestMessage).toContainText(/google|cats/i);
41+
await expectLastChatMessageContains(goosePage, /google|cats/i);
5042
});
5143

5244
test('add custom extension', async ({ goosePage }) => {
@@ -66,13 +58,8 @@ test.describe('Goose App Extensions', {tag: '@release'}, () => {
6658
goosePage.locator('#extension-running-quotes button[role="switch"][data-state="checked"]')
6759
).toBeVisible();
6860

69-
await goosePage.getByTestId('sidebar-home-button').click();
70-
71-
const chatInput = goosePage.getByTestId('chat-input');
72-
await chatInput.fill('Can you give me an inspirational running quote using the runningQuote tool?');
73-
await chatInput.press('Enter');
74-
75-
await waitForLoadingDone(goosePage, LLM_TIMEOUT);
61+
await goToHome(goosePage);
62+
await sendMessage(goosePage, 'Can you give me an inspirational running quote using the runningQuote tool?');
7663

7764
const lastMessage = goosePage.locator('.goose-message').last();
7865
const outputText = await lastMessage.textContent();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { expect, Page } from '@playwright/test';
2+
import { waitForLoadingDone } from './video';
3+
4+
export const LLM_TIMEOUT = 30000;
5+
6+
export async function sendMessage(page: Page, text: string): Promise<void> {
7+
const chatInput = page.locator('[data-testid="chat-input"]:visible').first();
8+
await chatInput.fill(text);
9+
await chatInput.press('Enter');
10+
await waitForLoadingDone(page, LLM_TIMEOUT);
11+
}
12+
13+
export async function expectChatMessageCount(page: Page, count: number): Promise<void> {
14+
await expect(page.locator('[data-testid="message-container"]:visible')).toHaveCount(count);
15+
}
16+
17+
export async function expectChatContainsMessage(page: Page, text: string): Promise<void> {
18+
await expect(
19+
page.locator('[data-testid="message-container"]:visible').filter({ hasText: text }).first()
20+
).toBeVisible();
21+
}
22+
23+
export async function expectLastChatMessageContains(page: Page, text: string | RegExp): Promise<void> {
24+
await expect(page.locator('[data-testid="message-container"]:visible').last()).toContainText(text);
25+
}
26+
27+
export async function goToHome(page: Page): Promise<void> {
28+
await page.getByTestId('sidebar-home-button').click();
29+
}
30+
31+
export async function expectSessionCount(page: Page, count: number): Promise<void> {
32+
await expect(page.getByTestId('session-history-card')).toHaveCount(count);
33+
}
34+
35+
export async function goToChatHistory(page: Page): Promise<void> {
36+
const showAll = page.getByTestId('chat-show-all').first();
37+
if (!(await showAll.isVisible().catch(() => false))) {
38+
await page.getByTestId('sidebar-chat-button').click();
39+
}
40+
await expect(showAll).toBeVisible();
41+
await showAll.click();
42+
await expect(page.getByRole('heading', { name: 'Chat history' })).toBeVisible();
43+
}
44+
45+
export async function openSession(page: Page, position: number): Promise<void> {
46+
await page.getByTestId('session-history-card').nth(position - 1).click();
47+
}
48+
49+
export async function openSettingsAppTab(page: Page): Promise<void> {
50+
await page.getByTestId('sidebar-settings-button').click();
51+
await page.getByTestId('settings-app-tab').click();
52+
}

ui/desktop/tests/e2e/settings.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { test } from './fixtures.electron.packaged';
22
import { expect } from '@playwright/test';
3+
import { goToHome, openSettingsAppTab } from './helpers/test-steps';
34

45
test.describe('Settings', {tag: '@release'}, () => {
56
test('dark mode toggle', async ({ goosePage }) => {
67
console.log('Testing dark mode toggle...');
78

8-
await expect(goosePage.getByTestId('chat-input')).toBeVisible();
9-
10-
await goosePage.getByTestId('sidebar-settings-button').click();
11-
12-
await goosePage.getByTestId('settings-app-tab').click();
9+
await openSettingsAppTab(goosePage);
1310

1411
const darkModeButton = goosePage.getByTestId('dark-mode-button');
1512
const lightModeButton = goosePage.getByTestId('light-mode-button');
@@ -32,6 +29,6 @@ test.describe('Settings', {tag: '@release'}, () => {
3229

3330
await lightModeButton.click();
3431

35-
await goosePage.getByTestId('sidebar-home-button').click();
32+
await goToHome(goosePage);
3633
});
3734
});

0 commit comments

Comments
 (0)