Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit 2266647

Browse files
committed
Fixes to tests
1 parent a3bdb1f commit 2266647

9 files changed

Lines changed: 90 additions & 161 deletions

vscode/test/e2e/attribution.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import * as mockServer from '../fixtures/mock-server'
55
import { getChatInputs, getChatSidebarPanel, sidebarSignin } from './common'
66

77
import type { SearchAttributionResponse } from '@sourcegraph/cody-shared/src/sourcegraph-api/graphql/client'
8-
import { test as baseTest } from './helpers'
9-
10-
const test = baseTest
8+
import { test } from './helpers'
119

1210
test('attribution search enabled in chat', async ({ page, sidebar, server }) => {
1311
server.onGraphQl('SnippetAttribution').replyJson({

vscode/test/e2e/chat-atFile.test.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { isWindows } from '@sourcegraph/cody-shared'
22
import { expect } from 'playwright/test'
3-
import * as mockServer from '../fixtures/mock-server'
43
import {
54
atMentionMenuMessage,
65
chatInputMentions,
@@ -17,7 +16,6 @@ import {
1716
sidebarSignin,
1817
} from './common'
1918
import {
20-
type DotcomUrlOverride,
2119
type ExpectedV2Events,
2220
executeCommandInPalette,
2321
mockEnterpriseRepoIdMapping,
@@ -29,23 +27,17 @@ import {
2927
//
3028
// NOTE: Creating new chats is slow, and setup is slow, so collapse these into fewer tests.
3129

32-
test
33-
.extend<ExpectedV2Events>({
34-
expectedV2Events: [
35-
'cody.extension:installed',
36-
'cody.auth.login:firstEver',
37-
'cody.auth.login.token:clicked',
38-
'cody.auth:connected',
39-
'cody.chat-question:submitted',
40-
'cody.chat-question:executed',
41-
'cody.chatResponse:noCode',
42-
],
43-
})
44-
.extend<DotcomUrlOverride>({
45-
// To exercise the "current directory" filename filtering without a git repository
46-
// for the workspace, simulate dotcom.
47-
dotcomUrl: mockServer.SERVER_URL,
48-
})('@-mention file in chat', async ({ page, sidebar, workspaceDirectory, server }) => {
30+
test.extend<ExpectedV2Events>({
31+
expectedV2Events: [
32+
'cody.extension:installed',
33+
'cody.auth.login:firstEver',
34+
'cody.auth.login.token:clicked',
35+
'cody.auth:connected',
36+
'cody.chat-question:submitted',
37+
'cody.chat-question:executed',
38+
'cody.chatResponse:noCode',
39+
],
40+
})('@-mention file in chat', async ({ page, sidebar, workspaceDirectory, server }) => {
4941
mockEnterpriseRepoIdMapping(server)
5042

5143
// This test requires that the window be focused in the OS window manager because it deals with
@@ -59,7 +51,9 @@ test
5951
await chatInput.dblclick()
6052
await chatInput.focus()
6153
await page.keyboard.type('@')
62-
await expect(mentionMenu(chatPanelFrame).getByRole('option', { selected: true })).toHaveText('Files')
54+
await expect(mentionMenu(chatPanelFrame).getByRole('option', { selected: true })).toHaveText(
55+
'Repositories'
56+
)
6357
await page.keyboard.press('Backspace')
6458

6559
// No results

vscode/test/e2e/chat-input.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ test.extend<DotcomUrlOverride>({ dotcomUrl: mockServer.SERVER_URL })
183183
await expect(humanRow0.toolbar.submit).not.toBeVisible()
184184
})
185185

186-
test.extend<DotcomUrlOverride>({ dotcomUrl: mockServer.SERVER_URL }).extend<ExpectedV2Events>({
186+
test.extend<ExpectedV2Events>({
187187
expectedV2Events: [
188188
'cody.extension:installed',
189189
'cody.auth.login:firstEver',
Lines changed: 62 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect } from '@playwright/test'
2-
import * as mockServer from '../fixtures/mock-server'
32
import {
43
chatInputMentions,
54
clickEditorTab,
@@ -10,7 +9,7 @@ import {
109
selectLineRangeInEditorTab,
1110
sidebarSignin,
1211
} from './common'
13-
import { type DotcomUrlOverride, executeCommandInPalette, test } from './helpers'
12+
import { executeCommandInPalette, test } from './helpers'
1413

1514
test.skip('chat keyboard shortcuts for sidebar chat', async ({ page, sidebar }) => {
1615
await page.bringToFront()
@@ -54,71 +53,68 @@ test.skip('re-opening chat adds selection', async ({ page, sidebar }) => {
5453
await expect(chatInputMentions(lastChatInput)).toHaveText(/^buzz.ts:2-4$/)
5554
})
5655

57-
test.extend<DotcomUrlOverride>({ dotcomUrl: mockServer.SERVER_URL })(
58-
'chat mode keyboard shortcut respects permissions',
59-
async ({ page, sidebar }) => {
60-
await sidebarSignin(page, sidebar)
61-
const chatFrame = getChatSidebarPanel(page)
62-
const chatInput = getChatInputs(chatFrame).last()
63-
64-
// Get the initial mode (should be "Chat" by default)
65-
await chatFrame.getByLabel('switch-mode').click()
56+
test('chat mode keyboard shortcut respects permissions', async ({ page, sidebar }) => {
57+
await sidebarSignin(page, sidebar)
58+
const chatFrame = getChatSidebarPanel(page)
59+
const chatInput = getChatInputs(chatFrame).last()
60+
61+
// Get the initial mode (should be "Chat" by default)
62+
await chatFrame.getByLabel('switch-mode').click()
63+
64+
// Escape to close the mode selector
65+
await page.keyboard.press('Escape')
66+
67+
// Try to cycle through modes using keyboard shortcut
68+
await page.keyboard.press(process.platform === 'darwin' ? 'Meta+.' : 'Control+.')
69+
70+
// Wait a moment for any state changes
71+
await page.waitForTimeout(500)
72+
73+
// Check if the mode changed based on user permissions
74+
// For dotcom users, it should stay as "Chat"
75+
const modeSelectorButton = chatFrame.getByLabel('switch-mode')
76+
await modeSelectorButton.click()
77+
// Select the first option in the dropdown
78+
await chatFrame.getByRole('option', { name: 'Chat' }).click()
79+
await expect(modeSelectorButton).toHaveText('Chat')
80+
81+
// Get the current mode after shortcut
82+
const newMode = await modeSelectorButton.textContent()
83+
84+
// Check which options are available and not disabled in the dropdown
85+
const availableOptions = await page.locator('.tw-command-item:not([disabled])').count()
86+
87+
// If there are multiple available options, the keyboard shortcut should have changed the mode
88+
if (availableOptions > 1) {
89+
// The mode should have changed from the default "Chat"
90+
expect(newMode).not.toBe('Chat')
91+
} else {
92+
// If only one option is available, the mode should still be "Chat"
93+
expect(newMode).toBe('Chat')
94+
}
6695

67-
// Escape to close the mode selector
68-
await page.keyboard.press('Escape')
96+
// Close the dropdown
97+
await page.keyboard.press('Escape')
6998

70-
// Try to cycle through modes using keyboard shortcut
99+
let currentMode = await modeSelectorButton.textContent()
100+
// Try cycling through modes multiple times to ensure we don't get stuck
101+
for (let i = 0; i < 3; i++) {
71102
await page.keyboard.press(process.platform === 'darwin' ? 'Meta+.' : 'Control+.')
72-
73-
// Wait a moment for any state changes
74-
await page.waitForTimeout(500)
75-
76-
// Check if the mode changed based on user permissions
77-
// For dotcom users, it should stay as "Chat"
78-
const modeSelectorButton = chatFrame.getByLabel('switch-mode')
79-
await modeSelectorButton.click()
80-
// Select the first option in the dropdown
81-
await chatFrame.getByRole('option', { name: 'Chat' }).click()
82-
await expect(modeSelectorButton).toHaveText('Chat')
83-
84-
// Get the current mode after shortcut
85-
const newMode = await modeSelectorButton.textContent()
86-
87-
// Check which options are available and not disabled in the dropdown
88-
const availableOptions = await page.locator('.tw-command-item:not([disabled])').count()
89-
90-
// If there are multiple available options, the keyboard shortcut should have changed the mode
91-
if (availableOptions > 1) {
92-
// The mode should have changed from the default "Chat"
93-
expect(newMode).not.toBe('Chat')
94-
} else {
95-
// If only one option is available, the mode should still be "Chat"
96-
expect(newMode).toBe('Chat')
97-
}
98-
99-
// Close the dropdown
100-
await page.keyboard.press('Escape')
101-
102-
let currentMode = await modeSelectorButton.textContent()
103-
// Try cycling through modes multiple times to ensure we don't get stuck
104-
for (let i = 0; i < 3; i++) {
105-
await page.keyboard.press(process.platform === 'darwin' ? 'Meta+.' : 'Control+.')
106-
await page.waitForTimeout(300)
107-
const nextMode = await modeSelectorButton.textContent()
108-
expect(currentMode).not.toBe(nextMode)
109-
currentMode = nextMode
110-
}
111-
112-
// Move back to Chat mode
113-
await modeSelectorButton.click()
114-
await chatFrame.getByRole('option', { name: 'Chat' }).click()
115-
await expect(modeSelectorButton).toHaveText('Chat')
116-
117-
// Verify we can still interact with the chat after cycling
118-
await chatInput.fill('Test message after cycling modes')
119-
await chatInput.press('Enter')
120-
121-
// Verify a response is received
122-
await expect(chatFrame.getByText('hello from the assistant')).toBeVisible()
103+
await page.waitForTimeout(300)
104+
const nextMode = await modeSelectorButton.textContent()
105+
expect(currentMode).not.toBe(nextMode)
106+
currentMode = nextMode
123107
}
124-
)
108+
109+
// Move back to Chat mode
110+
await modeSelectorButton.click()
111+
await chatFrame.getByRole('option', { name: 'Chat' }).click()
112+
await expect(modeSelectorButton).toHaveText('Chat')
113+
114+
// Verify we can still interact with the chat after cycling
115+
await chatInput.fill('Test message after cycling modes')
116+
await chatInput.press('Enter')
117+
118+
// Verify a response is received
119+
await expect(chatFrame.getByText('hello from the assistant')).toBeVisible()
120+
})

vscode/test/e2e/chat-rateLimit.test.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,7 @@ import { expect } from '@playwright/test'
33
import * as mockServer from '../fixtures/mock-server'
44

55
import { chatMessageRows, getChatInputs, getChatSidebarPanel, sidebarSignin } from './common'
6-
import { type DotcomUrlOverride, type ExpectedV2Events, test as baseTest } from './helpers'
7-
8-
const test = baseTest.extend<DotcomUrlOverride>({ dotcomUrl: mockServer.SERVER_URL })
9-
10-
test.extend<ExpectedV2Events>({
11-
expectedV2Events: [
12-
'cody.extension:installed',
13-
'cody.auth.login:firstEver',
14-
'cody.auth.login.token:clicked',
15-
'cody.auth:connected',
16-
'cody.chat-question:submitted',
17-
'cody.chat-question:executed',
18-
'cody.chatResponse:noCode',
19-
'cody.abuseUsageLimitCTA:shown',
20-
],
21-
})('shows standard rate limit message for pro users', async ({ page, sidebar }) => {
22-
await fetch(`${mockServer.SERVER_URL}/.test/completions/triggerRateLimit/pro`, {
23-
method: 'POST',
24-
})
25-
26-
await sidebarSignin(page, sidebar)
27-
const chatFrame = getChatSidebarPanel(page)
28-
const chatInput = getChatInputs(chatFrame).last()
29-
await chatInput.fill('test message')
30-
await chatInput.press('Enter')
31-
32-
await expect(chatFrame.getByRole('heading', { name: 'Unable to Send Message' })).toBeVisible()
33-
await expect(chatMessageRows(chatFrame).getByRole('button', { name: 'Learn More' })).toBeVisible()
34-
})
6+
import { type ExpectedV2Events, test } from './helpers'
357

368
test.extend<ExpectedV2Events>({
379
expectedV2Events: [

vscode/test/e2e/code-actions.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Page, expect } from '@playwright/test'
2-
import * as mockServer from '../fixtures/mock-server'
32

43
import {
54
focusSidebar,
@@ -9,14 +8,7 @@ import {
98
sidebarExplorer,
109
sidebarSignin,
1110
} from './common'
12-
import {
13-
type DotcomUrlOverride,
14-
type ExpectedV2Events,
15-
test as baseTest,
16-
executeCommandInPalette,
17-
} from './helpers'
18-
19-
const test = baseTest.extend<DotcomUrlOverride>({ dotcomUrl: mockServer.SERVER_URL })
11+
import { type ExpectedV2Events, executeCommandInPalette, test } from './helpers'
2012

2113
const ERROR_DECORATION_SELECTOR = 'div.view-overlays[role="presentation"] div[class*="squiggly-error"]'
2214

vscode/test/e2e/initial-context.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@ import {
2121
testWithGitRemote,
2222
} from './helpers'
2323

24-
testWithGitRemote.extend<DotcomUrlOverride>({ dotcomUrl: mockServer.SERVER_URL })(
25-
'initial context - self-serve repo',
26-
async ({ page, sidebar }) => {
27-
await sidebarSignin(page, sidebar)
28-
const chatFrame = getChatSidebarPanel(page)
29-
const lastChatInput = getChatInputs(chatFrame).last()
24+
testWithGitRemote('initial context - self-serve repo', async ({ page, sidebar }) => {
25+
await sidebarSignin(page, sidebar)
26+
const chatFrame = getChatSidebarPanel(page)
27+
const lastChatInput = getChatInputs(chatFrame).last()
3028

31-
// The current repository should be initially present in the chat input.
32-
await expect(chatInputMentions(lastChatInput)).toHaveText(['myrepo'])
33-
}
34-
)
29+
// The current repository should be initially present in the chat input.
30+
await expect(chatInputMentions(lastChatInput)).toHaveText(['myrepo'])
31+
})
3532

3633
testWithGitRemote('initial context - enterprise repo', async ({ page, sidebar, server }) => {
3734
mockEnterpriseRepoMapping(server, 'codehost.example/user/myrepo')

vscode/test/e2e/support-menu-items.test.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
11
import { expect } from '@playwright/test'
2-
import * as mockServer from '../fixtures/mock-server'
32

43
import { sidebarSignin } from './common'
5-
import { type DotcomUrlOverride, test as baseTest } from './helpers'
6-
7-
const test = baseTest.extend<DotcomUrlOverride>({ dotcomUrl: mockServer.SERVER_URL })
8-
9-
test('shows support link for free users', async ({ page, sidebar }) => {
10-
await sidebarSignin(page, sidebar)
11-
12-
// Check it's in settings quickpick
13-
14-
const statusBarButton = page.getByRole('button', { name: 'cody-logo-heavy, Cody Settings' })
15-
await statusBarButton.click()
16-
17-
const input = page.getByPlaceholder('Choose an option')
18-
await input.fill('support')
19-
20-
const supportItem = page.getByLabel('question Cody Support')
21-
expect(supportItem).toBeVisible()
22-
})
23-
24-
test('shows support link for pro users', async ({ page, sidebar }) => {
25-
await fetch(`${mockServer.SERVER_URL}/.test/currentUser/codyProEnabled`, { method: 'POST' })
4+
import { test } from './helpers'
265

6+
test('shows support link', async ({ page, sidebar }) => {
277
await sidebarSignin(page, sidebar)
288

299
// Check it's in settings quickpick

vscode/test/fixtures/mock-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ export class MockServer {
623623
}
624624
});
625625

626-
app.post("/.test/currentUser/codyProEnabled", (req, res) => {
626+
app.post("/.test/currentUser/codyProEnabled", (req, res) => { // todo: remove
627627
codyPro = true;
628628
res.sendStatus(200);
629629
});

0 commit comments

Comments
 (0)