Skip to content

Commit ff72ea1

Browse files
author
David Hasani
committed
add all files needed for UI test
1 parent ec64432 commit ff72ea1

File tree

2 files changed

+158
-1
lines changed

2 files changed

+158
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ export class Messenger {
5959
this.mynahUIProps.onFollowUpClicked(this.tabID, lastChatItem?.messageId ?? '', option[0])
6060
}
6161

62+
clickCustomFormButton(action: { id: string; text?: string; formItemValues?: Record<string, string> }) {
63+
if (!this.mynahUIProps.onCustomFormAction) {
64+
assert.fail('onCustomFormAction must be defined to use it in the tests')
65+
}
66+
67+
this.mynahUIProps.onCustomFormAction(this.tabID, action)
68+
}
69+
6270
clickFileActionButton(filePath: string, actionName: string) {
6371
if (!this.mynahUIProps.onFileActionClick) {
6472
assert.fail('onFileActionClick must be defined to use it in the tests')
@@ -173,7 +181,9 @@ export class Messenger {
173181

174182
// Do another check just in case the waitUntil time'd out
175183
if (!event()) {
176-
assert.fail(`Event has not finished loading in: ${this.waitTimeoutInMs} ms`)
184+
assert.fail(
185+
`Event has not finished loading in: ${waitOverrides ? waitOverrides.waitTimeoutInMs : this.waitTimeoutInMs} ms`
186+
)
177187
}
178188
}
179189

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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 { JDKVersion } from 'aws-core-vscode/codewhisperer'
11+
import { GumbyController, TabsStorage } from 'aws-core-vscode/amazonqGumby'
12+
13+
describe('Amazon Q Code Transformation', function () {
14+
let framework: qTestingFramework
15+
let tab: Messenger
16+
17+
beforeEach(() => {
18+
framework = new qTestingFramework('gumby', true, [])
19+
tab = framework.createTab()
20+
})
21+
22+
afterEach(() => {
23+
framework.removeTab(tab.tabID)
24+
framework.dispose()
25+
sinon.restore()
26+
})
27+
28+
describe('Quick action availability', () => {
29+
it('Shows /transform when QCT is enabled', async () => {
30+
const command = tab.findCommand('/transform')
31+
if (!command) {
32+
assert.fail('Could not find command')
33+
}
34+
35+
if (command.length > 1) {
36+
assert.fail('Found too many commands with the name /transform')
37+
}
38+
})
39+
40+
it('Does NOT show /transform when QCT is NOT enabled', () => {
41+
framework.dispose()
42+
framework = new qTestingFramework('gumby', false, [])
43+
const tab = framework.createTab()
44+
const command = tab.findCommand('/transform')
45+
if (command.length > 0) {
46+
assert.fail('Found command when it should not have been found')
47+
}
48+
})
49+
})
50+
51+
describe('Starting a transformation from chat', () => {
52+
it('Can click through all user input forms', async () => {
53+
tab.addChatMessage({ command: '/transform' })
54+
sinon
55+
.stub(GumbyController.prototype, 'validateLanguageUpgradeProjects' as keyof GumbyController)
56+
.resolves([
57+
{
58+
name: 'qct-sample-java-8-app-main',
59+
path: '/Users/alias/Desktop/qct-sample-java-8-app-main',
60+
JDKVersion: JDKVersion.JDK8,
61+
},
62+
])
63+
64+
// wait for /transform to respond with some intro messages and the first user input form
65+
await tab.waitForEvent(() => tab.getChatItems().length > 3, {
66+
waitTimeoutInMs: 5000,
67+
waitIntervalInMs: 1000,
68+
})
69+
const projectForm = tab.getChatItems().pop()
70+
assert.strictEqual(projectForm?.formItems?.[0]?.id ?? undefined, 'GumbyTransformLanguageUpgradeProjectForm')
71+
72+
const projectFormItemValues = {
73+
GumbyTransformLanguageUpgradeProjectForm: '/Users/alias/Desktop/qct-sample-java-8-app-main',
74+
GumbyTransformJdkFromForm: '8',
75+
GumbyTransformJdkToForm: '17',
76+
}
77+
const projectFormValues: Record<string, string> = { ...projectFormItemValues }
78+
// TODO: instead of stubbing, can we create a tab in qTestingFramework with tabType passed in?
79+
// Mynah-UI updates tab type like this: this.tabsStorage.updateTabTypeFromUnknown(affectedTabId, 'gumby')
80+
sinon
81+
.stub(TabsStorage.prototype, 'getTab')
82+
.returns({ id: tab.tabID, status: 'free', type: 'gumby', isSelected: true })
83+
tab.clickCustomFormButton({
84+
id: 'gumbyLanguageUpgradeTransformFormConfirm',
85+
text: 'Confirm',
86+
formItemValues: projectFormValues,
87+
})
88+
89+
// 3 additional chat messages (including message with 2nd form) get sent after 1st form submitted; wait for all of them
90+
await tab.waitForEvent(() => tab.getChatItems().length > 6, {
91+
waitTimeoutInMs: 5000,
92+
waitIntervalInMs: 1000,
93+
})
94+
const skipTestsForm = tab.getChatItems().pop()
95+
assert.strictEqual(skipTestsForm?.formItems?.[0]?.id ?? undefined, 'GumbyTransformSkipTestsForm')
96+
97+
const skipTestsFormItemValues = {
98+
GumbyTransformSkipTestsForm: 'Run unit tests',
99+
}
100+
const skipTestsFormValues: Record<string, string> = { ...skipTestsFormItemValues }
101+
tab.clickCustomFormButton({
102+
id: 'gumbyTransformSkipTestsFormConfirm',
103+
text: 'Confirm',
104+
formItemValues: skipTestsFormValues,
105+
})
106+
107+
// 3 additional chat messages (including message with 3rd form) get sent after 2nd form submitted; wait for all of them
108+
await tab.waitForEvent(() => tab.getChatItems().length > 9, {
109+
waitTimeoutInMs: 5000,
110+
waitIntervalInMs: 1000,
111+
})
112+
const multipleDiffsForm = tab.getChatItems().pop()
113+
assert.strictEqual(
114+
multipleDiffsForm?.formItems?.[0]?.id ?? undefined,
115+
'GumbyTransformOneOrMultipleDiffsForm'
116+
)
117+
118+
const oneOrMultipleDiffsFormItemValues = {
119+
GumbyTransformOneOrMultipleDiffsForm: 'One diff',
120+
}
121+
const oneOrMultipleDiffsFormValues: Record<string, string> = { ...oneOrMultipleDiffsFormItemValues }
122+
tab.clickCustomFormButton({
123+
id: 'gumbyTransformOneOrMultipleDiffsFormConfirm',
124+
text: 'Confirm',
125+
formItemValues: oneOrMultipleDiffsFormValues,
126+
})
127+
128+
// 2 additional chat messages (including message with 4th form) get sent after 3rd form submitted; wait for both of them
129+
await tab.waitForEvent(() => tab.getChatItems().length > 11, {
130+
waitTimeoutInMs: 5000,
131+
waitIntervalInMs: 1000,
132+
})
133+
const jdkPathPrompt = tab.getChatItems().pop()
134+
assert.strictEqual(jdkPathPrompt?.body?.includes('Enter the path to JDK'), true)
135+
136+
// 2 additional chat messages get sent after 4th form submitted; wait for both of them
137+
tab.addChatMessage({ prompt: '/dummy/path/to/jdk8' })
138+
await tab.waitForEvent(() => tab.getChatItems().length > 13, {
139+
waitTimeoutInMs: 5000,
140+
waitIntervalInMs: 1000,
141+
})
142+
const jdkPathResponse = tab.getChatItems().pop()
143+
// this 'Sorry' message is OK - just making sure that the UI components are working correctly
144+
assert.strictEqual(jdkPathResponse?.body?.includes("Sorry, I couldn't locate your Java installation"), true)
145+
})
146+
})
147+
})

0 commit comments

Comments
 (0)