|
| 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 | + |
| 13 | +describe('Amazon Q Welcome page', function () { |
| 14 | + let framework: qTestingFramework |
| 15 | + let tab: Messenger |
| 16 | + let store: MynahUIDataModel |
| 17 | + |
| 18 | + const availableCommands = ['/dev', '/test', '/review', '/doc', '/transform'] |
| 19 | + |
| 20 | + beforeEach(() => { |
| 21 | + framework = new qTestingFramework('welcome', true, [], 0) |
| 22 | + tab = framework.getTabs()[0] // use the default tab that gets created |
| 23 | + store = tab.getStore() |
| 24 | + }) |
| 25 | + |
| 26 | + afterEach(() => { |
| 27 | + framework.removeTab(tab.tabID) |
| 28 | + framework.dispose() |
| 29 | + sinon.restore() |
| 30 | + }) |
| 31 | + |
| 32 | + it(`Shows quick actions: ${availableCommands.join(', ')}`, async () => { |
| 33 | + assertQuickActions(tab, availableCommands) |
| 34 | + }) |
| 35 | + |
| 36 | + it('Shows @workspace', async () => { |
| 37 | + assert.deepStrictEqual( |
| 38 | + store.contextCommands |
| 39 | + ?.map((x) => x.commands) |
| 40 | + .flat() |
| 41 | + .map((x) => x.command), |
| 42 | + ['@workspace'] |
| 43 | + ) |
| 44 | + }) |
| 45 | + |
| 46 | + describe('shows 3 times', async () => { |
| 47 | + it('new tabs', () => { |
| 48 | + framework.createTab() |
| 49 | + framework.createTab() |
| 50 | + framework.createTab() |
| 51 | + framework.createTab() |
| 52 | + |
| 53 | + let welcomeCount = 0 |
| 54 | + framework.getTabs().forEach((tab) => { |
| 55 | + if (tab.getStore().tabTitle === 'Welcome to Q') { |
| 56 | + welcomeCount++ |
| 57 | + } |
| 58 | + }) |
| 59 | + // 3 welcome tabs |
| 60 | + assert.deepStrictEqual(welcomeCount, 3) |
| 61 | + |
| 62 | + // 2 normal tabs |
| 63 | + assert.deepStrictEqual(framework.getTabs().length - welcomeCount, 2) |
| 64 | + }) |
| 65 | + |
| 66 | + it('new windows', () => { |
| 67 | + // check the initial window |
| 68 | + assert.deepStrictEqual(store.tabTitle, 'Welcome to Q') |
| 69 | + framework.dispose() |
| 70 | + |
| 71 | + // check when theres already been two welcome tabs shown |
| 72 | + framework = new qTestingFramework('welcome', true, [], 2) |
| 73 | + const secondStore = framework.getTabs()[0].getStore() |
| 74 | + assert.deepStrictEqual(secondStore.tabTitle, 'Welcome to Q') |
| 75 | + framework.dispose() |
| 76 | + |
| 77 | + // check when theres already been three welcome tabs shown |
| 78 | + framework = new qTestingFramework('welcome', true, [], 3) |
| 79 | + const thirdStore = framework.getTabs()[0].getStore() |
| 80 | + assert.deepStrictEqual(thirdStore.tabTitle, 'Chat') |
| 81 | + framework.dispose() |
| 82 | + }) |
| 83 | + }) |
| 84 | + |
| 85 | + describe('Welcome actions', () => { |
| 86 | + it('explore', () => { |
| 87 | + tab.clickInBodyButton('explore') |
| 88 | + |
| 89 | + // explore opens in a new tab |
| 90 | + const exploreTabStore = framework.findTab('Explore')?.getStore() |
| 91 | + assert.strictEqual(exploreTabStore?.tabTitle, 'Explore') |
| 92 | + }) |
| 93 | + |
| 94 | + it('quick-start', async () => { |
| 95 | + tab.clickInBodyButton('quick-start') |
| 96 | + |
| 97 | + // clicking quick start opens in the current tab and changes the compact mode |
| 98 | + assert.deepStrictEqual(tab.getStore().compactMode, false) |
| 99 | + }) |
| 100 | + }) |
| 101 | +}) |
0 commit comments