Skip to content

Commit

Permalink
refractor prompters and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vicheey committed Nov 14, 2024
1 parent 46b966c commit b2a3891
Show file tree
Hide file tree
Showing 25 changed files with 162 additions and 136 deletions.
16 changes: 10 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CloudFormationTemplateRegistry } from '../../../shared/fs/templateRegis
import { syncMementoRootKey } from '../../../shared/sam/sync'

import { createExitPrompter } from '../../../shared/ui/common/exitPrompter'
import { createTemplatePrompter, TemplateItem } from '../../../shared/ui/common/samTemplate'
import { createTemplatePrompter, TemplateItem } from '../../../shared/ui/sam/samTemplate'
import { Wizard } from '../../../shared/wizards/wizard'

export interface OpenTemplateParams {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/sam/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import * as vscode from 'vscode'
import { TemplateItem, createTemplatePrompter } from '../ui/common/samTemplate'
import { TemplateItem, createTemplatePrompter } from '../ui/sam/samTemplate'
import { ChildProcess } from '../utilities/processUtils'
import { addTelemetryEnvVar } from './cli/samCliInvokerUtils'
import { Wizard } from '../wizards/wizard'
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/shared/sam/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { CancellationError } from '../utilities/timeoutUtils'
import { Wizard } from '../wizards/wizard'
import { addTelemetryEnvVar } from './cli/samCliInvokerUtils'
import { validateSamDeployConfig, SamConfig, writeSamconfigGlobal } from './config'
import { BucketSource, createBucketSourcePrompter, createBucketPrompter } from '../ui/common/bucket'
import { createStackPrompter } from '../ui/common/stack'
import { TemplateItem, createTemplatePrompter } from '../ui/common/samTemplate'
import { BucketSource, createBucketSourcePrompter, createBucketPrompter } from '../ui/sam/bucket'
import { createStackPrompter } from '../ui/sam/stack'
import { TemplateItem, createTemplatePrompter } from '../ui/sam/samTemplate'
import { getProjectRoot, getRecentResponse, getSamCliPathAndVersion, getSource, updateRecentResponse } from './utils'
import { createDeployParamsSourcePrompter, ParamsSource } from '../ui/common/paramsSource'
import { createDeployParamsSourcePrompter, ParamsSource } from '../ui/sam/paramsSource'
import { runInTerminal } from './processTerminal'

export interface DeployParams {
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/shared/sam/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ import {
getSource,
updateRecentResponse,
} from './utils'
import { TemplateItem, createTemplatePrompter } from '../ui/common/samTemplate'
import { createStackPrompter } from '../ui/common/stack'
import { ParamsSource, createSyncParamsSourcePrompter } from '../ui/common/paramsSource'
import { createEcrPrompter } from '../ui/common/ecr'
import { BucketSource, createBucketPrompter } from '../ui/common/bucket'
import { TemplateItem, createTemplatePrompter } from '../ui/sam/samTemplate'
import { createStackPrompter } from '../ui/sam/stack'
import { ParamsSource, createSyncParamsSourcePrompter } from '../ui/sam/paramsSource'
import { createEcrPrompter } from '../ui/sam/ecr'
import { BucketSource, createBucketPrompter } from '../ui/sam/bucket'
import { runInTerminal } from './processTerminal'

export interface SyncParams {
Expand All @@ -67,8 +67,6 @@ export interface SyncParams {
readonly syncFlags?: string
}

export const prefixNewBucketName = (name: string) => `newbucket:${name}`
export const prefixNewRepoName = (name: string) => `newrepo:${name}`
export const syncMementoRootKey = 'samcli.sync.params'

// TODO: hook this up so it prompts the user when more than 1 environment is present in `samconfig.toml`
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/sam/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as path from 'path'
import { AWSTreeNodeBase } from '../treeview/nodes/awsTreeNodeBase'
import { TreeNode, isTreeNode } from '../treeview/resourceTreeDataProvider'
import * as CloudFormation from '../cloudformation/cloudformation'
import { TemplateItem } from '../ui/common/samTemplate'
import { TemplateItem } from '../ui/sam/samTemplate'
import { RuntimeFamily, getFamily } from '../../lambda/models/samLambdaRuntime'
import { SamCliSettings } from './cli/samCliSettings'
import { ToolkitError } from '../errors'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { DefaultS3Client } from '../../clients/s3Client'
import { samDeployUrl, samSyncUrl } from '../../constants'
import { createCommonButtons } from '../buttons'
import { createQuickPick, DataQuickPickItem } from '../pickerPrompter'
import { SyncParams, prefixNewBucketName } from '../../sam/sync'
import type { SyncParams } from '../../sam/sync'
import * as nls from 'vscode-nls'
import { getRecentResponse } from '../../sam/utils'

const localize = nls.loadMessageBundle()
export const prefixNewBucketName = (name: string) => `newbucket:${name}`

export enum BucketSource {
SamCliManaged,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { DefaultEcrClient } from '../../clients/ecrClient'
import { samSyncUrl } from '../../constants'
import { createCommonButtons } from '../buttons'
import { createQuickPick } from '../pickerPrompter'
import { prefixNewRepoName } from '../../sam/sync'

import * as nls from 'vscode-nls'
import { getRecentResponse } from '../../sam/utils'

export const localize = nls.loadMessageBundle()
export const prefixNewRepoName = (name: string) => `newrepo:${name}`

export function createEcrPrompter(client: DefaultEcrClient, mementoRootKey: string) {
const recentEcrRepo = getRecentResponse(mementoRootKey, client.regionCode, 'ecrRepoUri')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function createDeployParamsSourcePrompter(existValidSamconfig: boolean |
const items = loadParamsSourcePrompterItems(existValidSamconfig)

return createQuickPick(items, {
title: 'Specify parameters for deploy',
title: 'Specify parameter source for deploy',
placeholder: 'Press enter to proceed with highlighted option',
buttons: createCommonButtons(samDeployUrl),
})
Expand All @@ -48,7 +48,7 @@ export function createSyncParamsSourcePrompter(existValidSamconfig: boolean | un
const items = loadParamsSourcePrompterItems(existValidSamconfig)

return createQuickPick(items, {
title: 'Specify parameters for sync',
title: 'Specify parameter source for sync',
placeholder: 'Press enter to proceed with highlighted option',
buttons: createCommonButtons(samSyncUrl),
})
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('DeployTypeWizard', function () {
.handleInputBox('Specify SAM parameter value for DestinationBucketName', (inputBox) => {
inputBox.acceptValue('my-destination-bucket-name')
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for deploy', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()
assert.strictEqual(quickPick.items[2].label, 'Use default values from samconfig')
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('DeployTypeWizard', function () {
assert.strictEqual(picker.items.length, 2)
picker.acceptItem(picker.items[0])
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for sync', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()
assert.strictEqual(quickPick.items[2].label, 'Use default values from samconfig')
Expand Down
32 changes: 17 additions & 15 deletions packages/core/src/test/shared/sam/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getProjectRootUri } from '../../../shared/sam/utils'
import sinon from 'sinon'
import { createMultiPick, DataQuickPickItem } from '../../../shared/ui/pickerPrompter'
import * as config from '../../../shared/sam/config'
import { getTestWindow } from '../vscode/window'
import { PrompterTester } from '../wizards/prompterTester'

describe('BuildWizard', async function () {
const createTester = async (params?: Partial<BuildParams>, arg?: TreeNode | undefined) =>
Expand Down Expand Up @@ -135,20 +135,22 @@ describe('getBuildFlags', () => {
})

it('should return flags from buildFlagsPrompter when paramsSource is Specify', async () => {
getTestWindow().onDidShowQuickPick(async (picker) => {
await picker.untilReady()
assert.strictEqual(picker.items.length, 9)
assert.strictEqual(picker.title, 'Select build flags')
assert.deepStrictEqual(picker.items, quickPickItems)
const betaFeatures = picker.items[0]
const buildInSource = picker.items[1]
const cached = picker.items[2]
assert.strictEqual(betaFeatures.data, '--beta-features')
assert.strictEqual(buildInSource.data, '--build-in-source')
assert.strictEqual(cached.data, '--cached')
const acceptedItems = [betaFeatures, buildInSource, cached]
picker.acceptItems(...acceptedItems)
})
PrompterTester.init()
.handleQuickPick('Select build flags', async (picker) => {
await picker.untilReady()
assert.strictEqual(picker.items.length, 9)
assert.strictEqual(picker.title, 'Select build flags')
assert.deepStrictEqual(picker.items, quickPickItems)
const betaFeatures = picker.items[0]
const buildInSource = picker.items[1]
const cached = picker.items[2]
assert.strictEqual(betaFeatures.data, '--beta-features')
assert.strictEqual(buildInSource.data, '--build-in-source')
assert.strictEqual(cached.data, '--cached')
const acceptedItems = [betaFeatures, buildInSource, cached]
picker.acceptItems(...acceptedItems)
})
.build()

const flags = await createMultiPick(quickPickItems, {
title: 'Select build flags',
Expand Down
24 changes: 12 additions & 12 deletions packages/core/src/test/shared/sam/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import { UserAgent as __UserAgent } from '@smithy/types'

import { SamAppLocation } from '../../../awsService/appBuilder/explorer/samProject'
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
import { TemplateItem } from '../../../shared/ui/common/samTemplate'
import { ParamsSource } from '../../../shared/ui/common/paramsSource'
import { BucketSource } from '../../../shared/ui/common/bucket'
import { TemplateItem } from '../../../shared/ui/sam/samTemplate'
import { ParamsSource } from '../../../shared/ui/sam/paramsSource'
import { BucketSource } from '../../../shared/ui/sam/bucket'

describe('DeployWizard', async function () {
let sandbox: sinon.SinonSandbox
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('DeployWizard', async function () {
.handleInputBox('Specify SAM parameter value for DestinationBucketName', (inputBox) => {
inputBox.acceptValue('my-destination-bucket-name')
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for deploy', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()

Expand Down Expand Up @@ -166,7 +166,7 @@ describe('DeployWizard', async function () {
.handleInputBox('Specify SAM parameter value for DestinationBucketName', (inputBox) => {
inputBox.acceptValue('my-destination-bucket-name')
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for deploy', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()

Expand Down Expand Up @@ -224,15 +224,15 @@ describe('DeployWizard', async function () {
// provide testWindow so that we can call other api
const testWindow = getTestWindow()

PrompterTester.init(testWindow)
PrompterTester.init({ testWindow })
.handleQuickPick('Select a SAM/CloudFormation Template', async (quickPick) => {
// Need sometime to wait for the template to search for template file
await quickPick.untilReady()
assert.strictEqual(quickPick.items.length, 1)
assert.strictEqual(quickPick.items[0].label, templateFile.fsPath)
quickPick.acceptItem(quickPick.items[0])
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for deploy', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()

Expand Down Expand Up @@ -306,7 +306,7 @@ describe('DeployWizard', async function () {
assert.strictEqual(quickPick.items[0].label, templateFile.fsPath)
quickPick.acceptItem(quickPick.items[0])
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for deploy', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()

Expand Down Expand Up @@ -367,7 +367,7 @@ describe('DeployWizard', async function () {
.handleInputBox('Specify SAM parameter value for DestinationBucketName', (inputBox) => {
inputBox.acceptValue('my-destination-bucket-name')
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for deploy', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()

Expand Down Expand Up @@ -438,7 +438,7 @@ describe('DeployWizard', async function () {
.handleInputBox('Specify SAM parameter value for DestinationBucketName', (inputBox) => {
inputBox.acceptValue('my-destination-bucket-name')
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for deploy', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()

Expand Down Expand Up @@ -495,7 +495,7 @@ describe('DeployWizard', async function () {
assert.strictEqual(quickPick.items[0].label, templateFile.fsPath)
quickPick.acceptItem(quickPick.items[0])
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for deploy', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()
assert.strictEqual(quickPick.items.length, 2)
Expand Down Expand Up @@ -579,7 +579,7 @@ describe('DeployWizard', async function () {
assert.strictEqual(quickPick.items[0].label, templateFile.fsPath)
quickPick.acceptItem(quickPick.items[0])
})
.handleQuickPick('Specify parameters for deploy', async (quickPick) => {
.handleQuickPick('Specify parameter source for deploy', async (quickPick) => {
// Need time to check samconfig.toml file and generate options
await quickPick.untilReady()
assert.strictEqual(quickPick.items.length, 3)
Expand Down
Loading

0 comments on commit b2a3891

Please sign in to comment.