/
context-settings.test.ts
119 lines (102 loc) · 4.63 KB
/
context-settings.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { expect } from '@playwright/test'
import { sidebarSignin } from './common'
import { type ExpectedEvents, newChat, test } from './helpers'
import type { RepoListResponse } from '@sourcegraph/cody-shared/src/sourcegraph-api/graphql/client'
test.extend<ExpectedEvents>({
// list of events we expect this test to log, add to this list as needed
expectedEvents: [
'CodyVSCodeExtension:auth:clickOtherSignInOptions',
'CodyVSCodeExtension:login:clicked',
'CodyVSCodeExtension:auth:selectSigninMenu',
'CodyVSCodeExtension:auth:fromToken',
'CodyVSCodeExtension:Auth:connected',
'CodyVSCodeExtension:useEnhancedContextToggler:clicked',
],
})('enhanced context selector is keyboard accessible', async ({ page, sidebar }, testInfo) => {
// This test requires that the window be focused in the OS's window manager. This
// does not work when other tests are running in parallel. TODO(sqs): make this testable in parallel.
const isParallelTest = process.env.TEST_PARALLEL_INDEX !== undefined
if (isParallelTest) {
testInfo.skip()
return
}
await page.bringToFront()
await sidebarSignin(page, sidebar)
const chatFrame = await newChat(page)
const contextSettingsButton = chatFrame.getByTitle('Configure Enhanced Context')
await contextSettingsButton.focus()
await page.keyboard.press('Space')
// Opening the enhanced context settings should focus the checkbox for toggling it.
const enhancedContextCheckbox = chatFrame.locator('#enhanced-context-checkbox')
await expect(enhancedContextCheckbox).toBeFocused()
// Enhanced context should be enabled by default.
await expect(enhancedContextCheckbox).toBeChecked()
await page.keyboard.press('Space')
// The keyboard should toggle the checkbox, but not dismiss the popup.
await expect(enhancedContextCheckbox).not.toBeChecked()
await expect(enhancedContextCheckbox).toBeVisible()
// The popup should be dismiss-able with the keyboard.
await page.keyboard.press('Escape')
// Closing the enhanced context settings should close the dialog...
await expect(enhancedContextCheckbox).not.toBeVisible()
// ... and focus the button which re-opens it.
await expect(contextSettingsButton.and(page.locator(':focus'))).toBeVisible()
})
test('enterprise context selector can pick repos', async ({ page, sidebar, server, expectedEvents }) => {
const repos1: RepoListResponse = {
repositories: {
nodes: [
{
id: 'WOOZL',
name: 'repo/foo',
},
],
pageInfo: {
endCursor: 'WOOZL',
},
},
}
const repos2: RepoListResponse = {
repositories: {
nodes: [
{
id: 'WUZLE',
name: 'repo/bar',
},
],
pageInfo: {
endCursor: null,
},
},
}
server.onGraphQl('Repositories').replyJson({ data: repos1 }).next().replyJson({ data: repos2 })
await sidebarSignin(page, sidebar)
const chatFrame = await newChat(page)
// Because there are no repositories in the workspace, none should be selected by default.
await chatFrame.getByTitle('Configure Enhanced Context').click()
await expect(chatFrame.getByText('No repositories selected')).toBeVisible()
// Choosing a repository should open the repository picker.
const chooseReposButton = chatFrame.getByRole('button', { name: 'Choose Repositories' })
await chooseReposButton.click()
const repoPicker = page.getByText(/Choose up to \d+ more repositories/)
await expect(repoPicker).toBeVisible()
// Opening the picker should not close the enhanced context status widget.
await expect(chooseReposButton).toBeVisible()
// Repositories listed on the remote should be present in the picker.
const repoFoo = page.getByText('repo/foo')
const repoBar = page.getByText('repo/bar')
await expect(repoFoo).toBeVisible()
await expect(repoBar).toBeVisible()
// Typing should filter the list of repositories.
await page.keyboard.type('o/f')
await expect(repoBar).not.toBeVisible()
// Choosing should dismiss the repo picker, but not the enhanced context
// settings widget.
await repoFoo.click()
await page.waitForTimeout(100)
await page.keyboard.type('\n')
await expect(repoPicker).not.toBeVisible()
await expect(chooseReposButton).toBeVisible()
// The chosen repo should appear in the picker.
await expect(chatFrame.getByTitle('repo/foo').getByText(/^foo$/)).toBeVisible()
})