From 23d0d0979068078490a49ce0ffb4cf9c5f667e10 Mon Sep 17 00:00:00 2001 From: Tomer Epstein <57438361+tomer-epstein@users.noreply.github.com> Date: Wed, 25 Mar 2020 17:49:08 +0200 Subject: [PATCH] =?UTF-8?q?showInformationMessage=20-=20show=20'Add=20to?= =?UTF-8?q?=20Workspace'=20button=20only=20if=20works=E2=80=A6=20(#203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * showInformationMessage - show 'Add to Workspace' button only if workspace is open * showInformationMessage - show 'Add to Workspace' button only if workspace is open * version: 0.0.65 --- backend/package.json | 2 +- backend/src/vscode-youi-events.ts | 2 +- backend/tests/vscode-youi-events.spec.ts | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/package.json b/backend/package.json index 484be07e..de687421 100644 --- a/backend/package.json +++ b/backend/package.json @@ -5,7 +5,7 @@ "license": "Apache 2.0", "description": "Provide rich user experience for Yeoman generators using VSCode extension or the browser", "repository": "https://github.com/SAP/yeoman-ui", - "version": "0.0.64", + "version": "0.0.65", "engines": { "vscode": "^1.39.2" }, diff --git a/backend/src/vscode-youi-events.ts b/backend/src/vscode-youi-events.ts index a01f071c..0e9814d0 100644 --- a/backend/src/vscode-youi-events.ts +++ b/backend/src/vscode-youi-events.ts @@ -52,7 +52,7 @@ export class VSCodeYouiEvents implements YouiEvents { VSCodeYouiEvents.installing = false; if (success) { const OpenWorkspace = 'Open in New Workspace'; - const AddToWorkspace = 'Add to Workspace'; + const AddToWorkspace = (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length) ? 'Add to Workspace' : undefined; vscode.window.showInformationMessage('The project has been successfully generated.\nWhat would you like to do with it?', AddToWorkspace, OpenWorkspace).then(selection => { if (selection === OpenWorkspace) { this.executeCommand("vscode.openFolder", targetPath); diff --git a/backend/tests/vscode-youi-events.spec.ts b/backend/tests/vscode-youi-events.spec.ts index 56e50550..8f900571 100644 --- a/backend/tests/vscode-youi-events.spec.ts +++ b/backend/tests/vscode-youi-events.spec.ts @@ -41,13 +41,24 @@ describe('vscode-youi-events unit test', () => { }); describe("doGeneratorDone", () => { - it("on success", () => { + it("on success workspace is open", () => { eventsMock.expects("doClose"); _.set(vscode, "window.showInformationMessage", () => {return Promise.resolve("");}); + _.set(vscode, "workspace.workspaceFolders", []); + _.set(vscode, "workspace.workspaceFolders.length", 1); windowMock.expects("showInformationMessage").withExactArgs('The project has been successfully generated.\nWhat would you like to do with it?', 'Add to Workspace', 'Open in New Workspace').resolves(); events.doGeneratorDone(true, "success message", "testDestinationRoot"); }); + it("on success workspace is closed", () => { + eventsMock.expects("doClose"); + _.set(vscode, "window.showInformationMessage", () => {return Promise.resolve("");}); + _.set(vscode, "workspace.workspaceFolders", undefined); + _.set(vscode, "workspace.workspaceFolders.length", 0); + windowMock.expects("showInformationMessage").withExactArgs('The project has been successfully generated.\nWhat would you like to do with it?', undefined, 'Open in New Workspace').resolves(); + events.doGeneratorDone(true, "success message", "testDestinationRoot"); + }); + it("on failure", () => { eventsMock.expects("doClose"); _.set(vscode, "window.showErrorMessage", () => {return Promise.resolve("");});