-
Notifications
You must be signed in to change notification settings - Fork 751
test(amazonq): E2E test for /doc #6215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /*! | ||
| * 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 { registerAuthHook, using } from 'aws-core-vscode/test' | ||
| import { loginToIdC } from './utils/setup' | ||
| import { Messenger } from './framework/messenger' | ||
| import { FollowUpTypes } from 'aws-core-vscode/amazonq' | ||
| import { i18n } from 'aws-core-vscode/shared' | ||
| import { docGenerationProgressMessage, DocGenerationStep, Mode } from 'aws-core-vscode/amazonqDoc' | ||
|
|
||
| describe('Amazon Q Doc', async function () { | ||
| let framework: qTestingFramework | ||
| let tab: Messenger | ||
|
|
||
| before(async function () { | ||
| /** | ||
| * The tests are getting throttled, only run them on stable for now | ||
| * | ||
| * TODO: Re-enable for all versions once the backend can handle them | ||
| */ | ||
| const testVersion = process.env['VSCODE_TEST_VERSION'] | ||
| if (testVersion && testVersion !== 'stable') { | ||
| this.skip() | ||
| } | ||
|
|
||
| await using(registerAuthHook('amazonq-test-account'), async () => { | ||
| await loginToIdC() | ||
| }) | ||
| }) | ||
|
|
||
| beforeEach(() => { | ||
| registerAuthHook('amazonq-test-account') | ||
| framework = new qTestingFramework('doc', true, []) | ||
| tab = framework.createTab() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| framework.removeTab(tab.tabID) | ||
| framework.dispose() | ||
| sinon.restore() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is sinon needed in e2e tests? if this is part of the |
||
| }) | ||
|
|
||
| describe('Quick action availability', () => { | ||
| it('Shows /doc when doc generation is enabled', async () => { | ||
| const command = tab.findCommand('/doc') | ||
| if (!command.length) { | ||
| assert.fail('Could not find command') | ||
| } | ||
|
|
||
| if (command.length > 1) { | ||
| assert.fail('Found too many commands with the name /doc') | ||
| } | ||
| }) | ||
|
|
||
| it('Does NOT show /doc when doc generation is NOT enabled', () => { | ||
| // The beforeEach registers a framework which accepts requests. If we don't dispose before building a new one we have duplicate messages | ||
| framework.dispose() | ||
| framework = new qTestingFramework('doc', false, []) | ||
| const tab = framework.createTab() | ||
| const command = tab.findCommand('/doc') | ||
| if (command.length > 0) { | ||
| assert.fail('Found command when it should not have been found') | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| describe('/doc entry', () => { | ||
| beforeEach(async function () { | ||
| tab.addChatMessage({ command: '/doc' }) | ||
| await tab.waitForChatFinishesLoading() | ||
| }) | ||
|
|
||
| it('Checks for initial follow ups', async () => { | ||
| await tab.waitForButtons([FollowUpTypes.CreateDocumentation, FollowUpTypes.UpdateDocumentation]) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Creates a README', () => { | ||
| beforeEach(async function () { | ||
| tab.addChatMessage({ command: '/doc' }) | ||
| await tab.waitForChatFinishesLoading() | ||
| }) | ||
|
|
||
| it('Creates a README for root folder', async () => { | ||
| await tab.waitForButtons([FollowUpTypes.CreateDocumentation]) | ||
|
|
||
| tab.clickButton(FollowUpTypes.CreateDocumentation) | ||
|
|
||
| await tab.waitForText(i18n('AWS.amazonq.doc.answer.createReadme')) | ||
|
|
||
| await tab.waitForButtons([FollowUpTypes.ProceedFolderSelection]) | ||
|
|
||
| tab.clickButton(FollowUpTypes.ProceedFolderSelection) | ||
|
|
||
| await tab.waitForText(docGenerationProgressMessage(DocGenerationStep.SUMMARIZING_FILES, Mode.CREATE)) | ||
|
|
||
| await tab.waitForText( | ||
| `${i18n('AWS.amazonq.doc.answer.readmeCreated')} ${i18n('AWS.amazonq.doc.answer.codeResult')}` | ||
| ) | ||
|
|
||
| await tab.waitForButtons([ | ||
| FollowUpTypes.AcceptChanges, | ||
| FollowUpTypes.MakeChanges, | ||
| FollowUpTypes.RejectChanges, | ||
| ]) | ||
| }) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ export class Messenger { | |
|
|
||
| const lastChatItem = this.getChatItems().pop() | ||
| const option = lastChatItem?.followUp?.options?.filter((option) => option.type === type) | ||
| if (!option || option.length > 1) { | ||
| if (!option?.length || option.length > 1) { | ||
| assert.fail('Could not find follow up option') | ||
| } | ||
|
|
||
|
|
@@ -153,17 +153,24 @@ export class Messenger { | |
| return this.getActionsByFilePath(filePath).some((action) => action.name === actionName) | ||
| } | ||
|
|
||
| async waitForText(text: string, waitOverrides?: MessengerOptions) { | ||
| await this.waitForEvent(() => { | ||
| console.log(this.getChatItems()) | ||
|
||
| return this.getChatItems().some((chatItem) => chatItem.body === text) | ||
| }, waitOverrides) | ||
| } | ||
|
|
||
| async waitForButtons(buttons: FollowUpTypes[]) { | ||
| return this.waitForEvent(() => { | ||
| return buttons.every((value) => this.hasButton(value)) | ||
| }) | ||
| } | ||
|
|
||
| async waitForChatFinishesLoading() { | ||
| return this.waitForEvent(() => this.getStore().loadingChat === false || this.hasButton(FollowUpTypes.Retry)) | ||
| } | ||
|
|
||
| async waitForEvent( | ||
| event: () => boolean, | ||
| waitOverrides?: { | ||
| waitIntervalInMs: number | ||
| waitTimeoutInMs: number | ||
| } | ||
| ) { | ||
| async waitForEvent(event: () => boolean, waitOverrides?: MessengerOptions) { | ||
| /** | ||
| * Wait until the chat has finished loading. This happens when a backend request | ||
| * has finished and responded in the chat | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.