|
| 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 { webviewConstants } 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[] = ['/dev', '/test', '/review', '/doc', '/transform'] |
| 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 | + // jscpd:ignore-start |
| 34 | + beforeEach(() => { |
| 35 | + // Make sure you're logged in before every test |
| 36 | + registerAuthHook('amazonq-test-account') |
| 37 | + framework = new qTestingFramework('cwc', true, []) |
| 38 | + tab = framework.createTab() |
| 39 | + store = tab.getStore() |
| 40 | + }) |
| 41 | + |
| 42 | + afterEach(() => { |
| 43 | + framework.removeTab(tab.tabID) |
| 44 | + framework.dispose() |
| 45 | + sinon.restore() |
| 46 | + }) |
| 47 | + |
| 48 | + it(`Shows quick actions: ${availableCommands.join(', ')}`, async () => { |
| 49 | + assertQuickActions(tab, availableCommands) |
| 50 | + }) |
| 51 | + |
| 52 | + it('Shows @workspace', () => { |
| 53 | + assertContextCommands(tab, ['@workspace']) |
| 54 | + }) |
| 55 | + |
| 56 | + // jscpd:ignore-end |
| 57 | + |
| 58 | + it('Shows title', () => { |
| 59 | + assert.deepStrictEqual(store.tabTitle, 'Chat') |
| 60 | + }) |
| 61 | + |
| 62 | + it('Shows placeholder', () => { |
| 63 | + assert.deepStrictEqual(store.promptInputPlaceholder, 'Ask a question or enter "/" for quick actions') |
| 64 | + }) |
| 65 | + |
| 66 | + it('Sends message', async () => { |
| 67 | + tab.addChatMessage({ |
| 68 | + prompt: 'What is a lambda', |
| 69 | + }) |
| 70 | + await tab.waitForChatFinishesLoading() |
| 71 | + const chatItems = tab.getChatItems() |
| 72 | + // the last item should be an answer |
| 73 | + assert.deepStrictEqual(chatItems[4].type, 'answer') |
| 74 | + }) |
| 75 | + |
| 76 | + describe('Clicks examples', () => { |
| 77 | + it('Click help', async () => { |
| 78 | + tab.clickButton('help') |
| 79 | + await tab.waitForText(webviewConstants.helpMessage) |
| 80 | + const chatItems = tab.getChatItems() |
| 81 | + assert.deepStrictEqual(chatItems[4].type, 'answer') |
| 82 | + assert.deepStrictEqual(chatItems[4].body, webviewConstants.helpMessage) |
| 83 | + }) |
| 84 | + }) |
| 85 | +}) |
0 commit comments