Skip to content

Commit bbe1b5d

Browse files
committed
tests(amazonq): Add e2e tests for general amazon q chat panel
1 parent c110675 commit bbe1b5d

File tree

7 files changed

+166
-12
lines changed

7 files changed

+166
-12
lines changed

packages/amazonq/test/e2e/amazonq/assert.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,14 @@ export function assertQuickActions(tab: Messenger, commands: string[]) {
2828
assert.fail(`Could not find commands: ${missingCommands.join(', ')} for ${tab.tabID}`)
2929
}
3030
}
31+
32+
export function assertContextCommands(tab: Messenger, contextCommands: string[]) {
33+
assert.deepStrictEqual(
34+
tab
35+
.getStore()
36+
.contextCommands?.map((x) => x.commands)
37+
.flat()
38+
.map((x) => x.command),
39+
contextCommands
40+
)
41+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import assert from 'assert'
7+
import { qTestingFramework } from './framework/framework'
8+
import sinon from 'sinon'
9+
import { Messenger } from './framework/messenger'
10+
import { MynahUIDataModel } from '@aws/mynah-ui'
11+
import { assertContextCommands, assertQuickActions } from './assert'
12+
import { registerAuthHook, using } from 'aws-core-vscode/test'
13+
import { loginToIdC } from './utils/setup'
14+
import { helpMessage } from 'aws-core-vscode/amazonq'
15+
16+
describe('Amazon Q Chat', function () {
17+
let framework: qTestingFramework
18+
let tab: Messenger
19+
let store: MynahUIDataModel
20+
21+
const availableCommands: string[] = []
22+
23+
before(async function () {
24+
/**
25+
* Login to the amazonq-test-account. When running in CI this has unlimited
26+
* calls to the backend api
27+
*/
28+
await using(registerAuthHook('amazonq-test-account'), async () => {
29+
await loginToIdC()
30+
})
31+
})
32+
33+
beforeEach(() => {
34+
// Make sure you're logged in before every test
35+
registerAuthHook('amazonq-test-account')
36+
framework = new qTestingFramework('cwc', true, [])
37+
tab = framework.createTab()
38+
store = tab.getStore()
39+
})
40+
41+
afterEach(() => {
42+
framework.removeTab(tab.tabID)
43+
framework.dispose()
44+
sinon.restore()
45+
})
46+
47+
it(`Shows quick actions: ${availableCommands.join(', ')}`, async () => {
48+
assertQuickActions(tab, availableCommands)
49+
})
50+
51+
it('Shows @workspace', () => {
52+
assertContextCommands(tab, ['@workspace'])
53+
})
54+
55+
it('Shows title', () => {
56+
assert.deepStrictEqual(store.tabTitle, 'Chat')
57+
})
58+
59+
it('Shows placeholder', () => {
60+
assert.deepStrictEqual(store.promptInputPlaceholder, 'Ask a question or enter "/" for quick actions')
61+
})
62+
63+
it('sends message', async () => {
64+
tab.addChatMessage({
65+
prompt: 'What is a lambda',
66+
})
67+
await tab.waitForChatFinishesLoading()
68+
const chatItems = tab.getChatItems()
69+
// the last item should be an answer
70+
assert.deepStrictEqual(chatItems[4].type, 'answer')
71+
})
72+
73+
describe('clicks examples', () => {
74+
it('click help', async () => {
75+
tab.clickButton('help')
76+
await tab.waitForText(helpMessage)
77+
const chatItems = tab.getChatItems()
78+
assert.deepStrictEqual(chatItems[4].type, 'answer')
79+
assert.deepStrictEqual(chatItems[4].body, helpMessage)
80+
})
81+
})
82+
})

packages/amazonq/test/e2e/amazonq/framework/framework.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class qTestingFramework {
2929
featureName: TabType,
3030
amazonQEnabled: boolean,
3131
featureConfigsSerialized: [string, FeatureContext][],
32-
welcomeCount = 0
32+
welcomeCount = 10 // by default don't show the welcome page
3333
) {
3434
/**
3535
* Instantiate the UI and override the postMessage to publish using the app message
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import assert from 'assert'
7+
import { qTestingFramework } from './framework/framework'
8+
import sinon from 'sinon'
9+
import { Messenger } from './framework/messenger'
10+
import { MynahUIDataModel } from '@aws/mynah-ui'
11+
import { assertQuickActions } from './assert'
12+
import { registerAuthHook, using } from 'aws-core-vscode/test'
13+
import { loginToIdC } from './utils/setup'
14+
15+
describe.skip('Amazon Q Test Template', function () {
16+
let framework: qTestingFramework
17+
let tab: Messenger
18+
let store: MynahUIDataModel
19+
20+
const availableCommands: string[] = []
21+
22+
before(async function () {
23+
/**
24+
* Login to the amazonq-test-account. When running in CI this has unlimited
25+
* calls to the backend api
26+
*/
27+
await using(registerAuthHook('amazonq-test-account'), async () => {
28+
await loginToIdC()
29+
})
30+
})
31+
32+
beforeEach(() => {
33+
// Make sure you're logged in before every test
34+
registerAuthHook('amazonq-test-account')
35+
36+
// TODO change unknown to the tab type you want to test
37+
framework = new qTestingFramework('unknown', true, [])
38+
tab = framework.getTabs()[0] // use the default tab that gets created
39+
framework.createTab() // alternatively you can create a new tab
40+
store = tab.getStore()
41+
})
42+
43+
afterEach(() => {
44+
framework.removeTab(tab.tabID)
45+
framework.dispose()
46+
sinon.restore()
47+
})
48+
49+
it(`Shows quick actions: ${availableCommands.join(', ')}`, async () => {
50+
assertQuickActions(tab, availableCommands)
51+
})
52+
53+
it('Shows title', () => {
54+
assert.deepStrictEqual(store.tabTitle, '')
55+
})
56+
57+
it('Shows placeholder', () => {
58+
assert.deepStrictEqual(store.promptInputPlaceholder, '')
59+
})
60+
61+
describe('clicks examples', () => {})
62+
63+
describe('sends message', async () => {})
64+
})

packages/amazonq/test/e2e/amazonq/welcome.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { qTestingFramework } from './framework/framework'
88
import sinon from 'sinon'
99
import { Messenger } from './framework/messenger'
1010
import { MynahUIDataModel } from '@aws/mynah-ui'
11-
import { assertQuickActions } from './assert'
1211
import { FeatureContext } from 'aws-core-vscode/shared'
12+
import { assertContextCommands, assertQuickActions } from './assert'
1313

1414
describe('Amazon Q Welcome page', function () {
1515
let framework: qTestingFramework
@@ -42,13 +42,7 @@ describe('Amazon Q Welcome page', function () {
4242
})
4343

4444
it('Shows context commands', async () => {
45-
assert.deepStrictEqual(
46-
store.contextCommands
47-
?.map((x) => x.commands)
48-
.flat()
49-
.map((x) => x.command),
50-
['@workspace', '@highlight']
51-
)
45+
assertContextCommands(tab, ['@workspace', '@highlight'])
5246
})
5347

5448
describe('shows 3 times', async () => {

packages/core/src/amazonq/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export { init as gumbyChatAppInit } from '../amazonqGumby/app'
2525
export { init as testChatAppInit } from '../amazonqTest/app'
2626
export { init as docChatAppInit } from '../amazonqDoc/app'
2727
export { amazonQHelpUrl } from '../shared/constants'
28+
export * from './webview/ui/texts/constants'
2829
export { listCodeWhispererCommandsWalkthrough } from '../codewhisperer/ui/statusBarMenu'
2930
export { focusAmazonQPanel, focusAmazonQPanelKeybinding } from '../codewhispererChat/commands/registerCommands'
3031
export { TryChatCodeLensProvider, tryChatCodeLensCommand } from '../codewhispererChat/editor/codelens'

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,19 @@ export class ChatController {
231231
this.openLinkInExternalBrowser(click)
232232
}
233233

234-
private processQuickActionCommand(quickActionCommand: ChatPromptCommandType) {
234+
private processQuickActionCommand(message: PromptMessage) {
235235
this.editorContextExtractor
236236
.extractContextForTrigger('QuickAction')
237237
.then((context) => {
238238
const triggerID = randomUUID()
239239

240+
const quickActionCommand = message.command as ChatPromptCommandType
241+
240242
this.messenger.sendQuickActionMessage(quickActionCommand, triggerID)
241243

242244
this.triggerEventsStorage.addTriggerEvent({
243245
id: triggerID,
244-
tabID: undefined,
246+
tabID: message.tabID,
245247
message: undefined,
246248
type: 'quick_action',
247249
quickAction: quickActionCommand,
@@ -484,7 +486,7 @@ export class ChatController {
484486
recordTelemetryChatRunCommand('clear')
485487
return
486488
default:
487-
this.processQuickActionCommand(message.command)
489+
this.processQuickActionCommand(message)
488490
}
489491
}
490492

0 commit comments

Comments
 (0)