diff --git a/src/stripeSamples.ts b/src/stripeSamples.ts index 54ba1ce4..41c6eb5a 100644 --- a/src/stripeSamples.ts +++ b/src/stripeSamples.ts @@ -69,7 +69,9 @@ export class StripeSamples { return; } - const clonePath = await this.promptPath(selectedSample); + const cloneSampleAsName = await this.promptSampleName(sampleName); + + const clonePath = await this.promptPath(selectedSample, cloneSampleAsName); if (!clonePath) { return; } @@ -93,9 +95,13 @@ export class StripeSamples { progress.report({increment: 100}); + const sampleIsReady = `Your sample "${cloneSampleAsName}" is all ready to go`; + // eslint-disable-next-line no-nested-ternary const postInstallMessage = !!sampleCreateResponse - ? sampleCreateResponse.getPostInstall() - : 'Your sample is all ready to go, but we could not set the API keys in the .env file. Please set them manually.'; + ? !!sampleCreateResponse.getPostInstall() + ? sampleCreateResponse.getPostInstall() + : `${sampleIsReady}.` + : `${sampleIsReady}, but we could not set the API keys in the .env file. Please set them manually.`; await this.promptOpenFolder(postInstallMessage, clonePath); }, @@ -230,7 +236,7 @@ export class StripeSamples { /** * Ask for where to clone the sample */ - private promptPath = async (sample: SampleQuickPickItem): Promise => { + private promptPath = async (sample: SampleQuickPickItem, cloneSampleAsName: string): Promise => { const cloneDirectoryUri = await window.showOpenDialog({ canSelectFiles: false, canSelectFolders: true, @@ -243,11 +249,23 @@ export class StripeSamples { return; } - const clonePath = path.resolve(cloneDirectoryUri[0].fsPath, sample.sampleData.name); + const clonePath = path.resolve(cloneDirectoryUri[0].fsPath, cloneSampleAsName); return clonePath; }; + /** + * Ask for sample name + */ + private promptSampleName = async (sampleName: string): Promise => { + const inputName = await window.showInputBox({ + value: sampleName, + prompt: 'Enter a sample name', + }); + + return !!inputName ? inputName : sampleName; + }; + /** * Execute the sample creation with the given config at the given path */ @@ -293,7 +311,7 @@ export class StripeSamples { }; const selectedOption = await window.showInformationMessage( - postInstallMessage || 'Your sample is all ready to go.', + postInstallMessage, {modal: true}, ...Object.values(openFolderOptions), ); diff --git a/test/suite/stripeSamples.test.ts b/test/suite/stripeSamples.test.ts index d1f5d685..034c7d7e 100644 --- a/test/suite/stripeSamples.test.ts +++ b/test/suite/stripeSamples.test.ts @@ -82,6 +82,9 @@ suite('StripeSamples', function () { test('prompts for sample config, clones, and opens sample', async () => { sandbox.stub(stripeDaemon, 'setupClient').resolves(daemonClient); const showQuickPickSpy = sandbox.spy(vscode.window, 'showQuickPick'); + const showInputBoxStub = sandbox + .stub(vscode.window, 'showInputBox') + .resolves('sample-name-by-user'); const showOpenDialogStub = sandbox .stub(vscode.window, 'showOpenDialog') .resolves([vscode.Uri.parse('/my/path')]); @@ -95,6 +98,7 @@ suite('StripeSamples', function () { await simulateSelectAll(); assert.strictEqual(showQuickPickSpy.callCount, 4); + assert.strictEqual(showInputBoxStub.callCount, 1); assert.strictEqual(showOpenDialogStub.callCount, 1); assert.strictEqual(showInformationMessageStub.callCount, 1); }); @@ -118,6 +122,7 @@ suite('StripeSamples', function () { ); sandbox.stub(stripeDaemon, 'setupClient').resolves(daemonClient); + sandbox.stub(vscode.window, 'showInputBox').resolves('sample-name-by-user'); sandbox.stub(vscode.window, 'showOpenDialog').resolves([vscode.Uri.parse('/my/path')]); const showInformationMessageStub = sandbox .stub(vscode.window, 'showInformationMessage') @@ -130,7 +135,7 @@ suite('StripeSamples', function () { assert.deepStrictEqual( showInformationMessageStub.args[0][0], - 'Your sample is all ready to go, but we could not set the API keys in the .env file. Please set them manually.', + 'Your sample "sample-name-by-user" is all ready to go, but we could not set the API keys in the .env file. Please set them manually.', ); }); });