Skip to content

Commit

Permalink
add all files needed for UI test
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hasani committed Dec 8, 2024
1 parent ec64432 commit ff72ea1
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/amazonq/test/e2e/amazonq/framework/messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export class Messenger {
this.mynahUIProps.onFollowUpClicked(this.tabID, lastChatItem?.messageId ?? '', option[0])
}

clickCustomFormButton(action: { id: string; text?: string; formItemValues?: Record<string, string> }) {
if (!this.mynahUIProps.onCustomFormAction) {
assert.fail('onCustomFormAction must be defined to use it in the tests')
}

this.mynahUIProps.onCustomFormAction(this.tabID, action)
}

clickFileActionButton(filePath: string, actionName: string) {
if (!this.mynahUIProps.onFileActionClick) {
assert.fail('onFileActionClick must be defined to use it in the tests')
Expand Down Expand Up @@ -173,7 +181,9 @@ export class Messenger {

// Do another check just in case the waitUntil time'd out
if (!event()) {
assert.fail(`Event has not finished loading in: ${this.waitTimeoutInMs} ms`)
assert.fail(
`Event has not finished loading in: ${waitOverrides ? waitOverrides.waitTimeoutInMs : this.waitTimeoutInMs} ms`
)
}
}

Expand Down
147 changes: 147 additions & 0 deletions packages/amazonq/test/e2e/amazonq/transformByQ.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import assert from 'assert'
import { qTestingFramework } from './framework/framework'
import sinon from 'sinon'
import { Messenger } from './framework/messenger'
import { JDKVersion } from 'aws-core-vscode/codewhisperer'
import { GumbyController, TabsStorage } from 'aws-core-vscode/amazonqGumby'

describe('Amazon Q Code Transformation', function () {
let framework: qTestingFramework
let tab: Messenger

beforeEach(() => {
framework = new qTestingFramework('gumby', true, [])
tab = framework.createTab()
})

afterEach(() => {
framework.removeTab(tab.tabID)
framework.dispose()
sinon.restore()
})

describe('Quick action availability', () => {
it('Shows /transform when QCT is enabled', async () => {
const command = tab.findCommand('/transform')
if (!command) {
assert.fail('Could not find command')
}

if (command.length > 1) {
assert.fail('Found too many commands with the name /transform')
}
})

it('Does NOT show /transform when QCT is NOT enabled', () => {
framework.dispose()
framework = new qTestingFramework('gumby', false, [])
const tab = framework.createTab()
const command = tab.findCommand('/transform')
if (command.length > 0) {
assert.fail('Found command when it should not have been found')
}
})
})

describe('Starting a transformation from chat', () => {
it('Can click through all user input forms', async () => {
tab.addChatMessage({ command: '/transform' })
sinon
.stub(GumbyController.prototype, 'validateLanguageUpgradeProjects' as keyof GumbyController)
.resolves([
{
name: 'qct-sample-java-8-app-main',
path: '/Users/alias/Desktop/qct-sample-java-8-app-main',
JDKVersion: JDKVersion.JDK8,
},
])

// wait for /transform to respond with some intro messages and the first user input form
await tab.waitForEvent(() => tab.getChatItems().length > 3, {
waitTimeoutInMs: 5000,
waitIntervalInMs: 1000,
})
const projectForm = tab.getChatItems().pop()
assert.strictEqual(projectForm?.formItems?.[0]?.id ?? undefined, 'GumbyTransformLanguageUpgradeProjectForm')

const projectFormItemValues = {
GumbyTransformLanguageUpgradeProjectForm: '/Users/alias/Desktop/qct-sample-java-8-app-main',
GumbyTransformJdkFromForm: '8',
GumbyTransformJdkToForm: '17',
}
const projectFormValues: Record<string, string> = { ...projectFormItemValues }
// TODO: instead of stubbing, can we create a tab in qTestingFramework with tabType passed in?
// Mynah-UI updates tab type like this: this.tabsStorage.updateTabTypeFromUnknown(affectedTabId, 'gumby')
sinon
.stub(TabsStorage.prototype, 'getTab')
.returns({ id: tab.tabID, status: 'free', type: 'gumby', isSelected: true })
tab.clickCustomFormButton({
id: 'gumbyLanguageUpgradeTransformFormConfirm',
text: 'Confirm',
formItemValues: projectFormValues,
})

// 3 additional chat messages (including message with 2nd form) get sent after 1st form submitted; wait for all of them
await tab.waitForEvent(() => tab.getChatItems().length > 6, {
waitTimeoutInMs: 5000,
waitIntervalInMs: 1000,
})
const skipTestsForm = tab.getChatItems().pop()
assert.strictEqual(skipTestsForm?.formItems?.[0]?.id ?? undefined, 'GumbyTransformSkipTestsForm')

const skipTestsFormItemValues = {
GumbyTransformSkipTestsForm: 'Run unit tests',
}
const skipTestsFormValues: Record<string, string> = { ...skipTestsFormItemValues }
tab.clickCustomFormButton({
id: 'gumbyTransformSkipTestsFormConfirm',
text: 'Confirm',
formItemValues: skipTestsFormValues,
})

// 3 additional chat messages (including message with 3rd form) get sent after 2nd form submitted; wait for all of them
await tab.waitForEvent(() => tab.getChatItems().length > 9, {
waitTimeoutInMs: 5000,
waitIntervalInMs: 1000,
})
const multipleDiffsForm = tab.getChatItems().pop()
assert.strictEqual(
multipleDiffsForm?.formItems?.[0]?.id ?? undefined,
'GumbyTransformOneOrMultipleDiffsForm'
)

const oneOrMultipleDiffsFormItemValues = {
GumbyTransformOneOrMultipleDiffsForm: 'One diff',
}
const oneOrMultipleDiffsFormValues: Record<string, string> = { ...oneOrMultipleDiffsFormItemValues }
tab.clickCustomFormButton({
id: 'gumbyTransformOneOrMultipleDiffsFormConfirm',
text: 'Confirm',
formItemValues: oneOrMultipleDiffsFormValues,
})

// 2 additional chat messages (including message with 4th form) get sent after 3rd form submitted; wait for both of them
await tab.waitForEvent(() => tab.getChatItems().length > 11, {
waitTimeoutInMs: 5000,
waitIntervalInMs: 1000,
})
const jdkPathPrompt = tab.getChatItems().pop()
assert.strictEqual(jdkPathPrompt?.body?.includes('Enter the path to JDK'), true)

// 2 additional chat messages get sent after 4th form submitted; wait for both of them
tab.addChatMessage({ prompt: '/dummy/path/to/jdk8' })
await tab.waitForEvent(() => tab.getChatItems().length > 13, {
waitTimeoutInMs: 5000,
waitIntervalInMs: 1000,
})
const jdkPathResponse = tab.getChatItems().pop()
// this 'Sorry' message is OK - just making sure that the UI components are working correctly
assert.strictEqual(jdkPathResponse?.body?.includes("Sorry, I couldn't locate your Java installation"), true)
})
})
})

0 comments on commit ff72ea1

Please sign in to comment.