Skip to content

Commit

Permalink
test: indicating generators are being installed in background
Browse files Browse the repository at this point in the history
  • Loading branch information
tomer-epstein committed Feb 24, 2021
1 parent fbf6395 commit 3013278
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 40 deletions.
6 changes: 3 additions & 3 deletions backend/.nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"temp-dir": "./reports/.nyc_output",
"report-dir": "./reports/coverage",
"check-coverage": true,
"branches": 83,
"branches": 85,
"lines": 90,
"functions": 85,
"statements": 89
"functions": 87,
"statements": 90
}
8 changes: 0 additions & 8 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@
"main": "./dist/extension",
"contributes": {
"commands": [
{
"command": "tomer._notifyGeneratorsInstallStart",
"title": "TOMER notify about generator install START"
},
{
"command": "tomer._notifyGeneratorsInstallEnd",
"title": "TOMER notify about generator install END"
},
{
"command": "yeomanUI._notifyGeneratorsChange",
"title": "notify about generator change"
Expand Down
19 changes: 0 additions & 19 deletions backend/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,6 @@ export async function activate(context: vscode.ExtensionContext) {
registerAndSubscribeCommand("yeomanUI.toggleOutput", yeomanUIPanel.toggleOutput.bind(yeomanUIPanel));
registerAndSubscribeCommand("yeomanUI._notifyGeneratorsChange", yeomanUIPanel.notifyGeneratorsChange.bind(yeomanUIPanel));
registerAndSubscribeCommand("runGenerator", yeomanUIPanel.runGenerator.bind(yeomanUIPanel));
registerAndSubscribeCommand("tomer._notifyGeneratorsInstallStart", () => {
return vscode.commands.executeCommand("yeomanUI._notifyGeneratorsChange" , [
{
name: "@sap/generator-mine",
versionRange: "2.0.1"
},
{
name: "generator-java-thing",
versionRange: "*"
},
{
name: "@sap/generator-my-second",
versionRange: "^2.0.1"
}
]);
});
registerAndSubscribeCommand("tomer._notifyGeneratorsInstallEnd", () => {
return vscode.commands.executeCommand("yeomanUI._notifyGeneratorsChange" , []);
});
registerWebviewPanelSerializer(yeomanUIPanel);

// ExploreGensPanel
Expand Down
7 changes: 4 additions & 3 deletions backend/src/panels/YeomanUIPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ export class YeomanUIPanel extends AbstractWebviewPanel {
this.output.show();
}

public notifyGeneratorsChange(args?: []) {
this.installGens = !_.isObject(args) ? undefined : args;
public notifyGeneratorsChange(args?: any[]) {
const yeomanUi = _.get(this, "yeomanui");
this.installGens = !yeomanUi && _.isEmpty(args) ? undefined : args;
if (yeomanUi) {
if (_.isNil(this.installGens)) {
if (this.installGens) {
yeomanUi._notifyGeneratorsChange(YeomanUIPanel.getGensMeta());
} else {
yeomanUi._notifyGeneratorsInstall(this.installGens);
if (_.isEmpty(this.installGens)) {
yeomanUi._notifyGeneratorsChange(YeomanUIPanel.getGensMeta());
this.installGens = undefined;
}
}
Expand Down
5 changes: 3 additions & 2 deletions backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,18 @@ export class YeomanUI {
await this.rpc.invoke("updateGeneratorsPrompt", [generators.questions]);
}

public async _notifyGeneratorsInstall(args: [], force: boolean) {
public async _notifyGeneratorsInstall(args: any[], force: boolean) {
if (!_.isNil(args)) {
const isGeneratorsPrompt: boolean = await this.rpc.invoke("isGeneratorsPrompt");
if (isGeneratorsPrompt || force) {
const message = this.getGeneratorsInstallingMessage(args);
this.youiEvents.getAppWizard().showInformation(message, MessageType.prompt);
}
}
this.uiOptions.installGens = (_.isObject(args) && _.isEmpty(args)) ? undefined : args;
}

private getGeneratorsInstallingMessage(args: []): string {
private getGeneratorsInstallingMessage(args: any[]): string {
if (_.isEmpty(args)) {
return "We have finished installing all generators, enjoy your work!";
}
Expand Down
117 changes: 116 additions & 1 deletion backend/tests/yeomanui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as os from "os";
import messages from "../src/messages";
import Environment = require("yeoman-environment");
import { SWA } from "../src/swa-tracker/swa-tracker-wrapper";
import { AppWizard } from "@sap-devx/yeoman-ui-types";
import { AppWizard, MessageType } from "@sap-devx/yeoman-ui-types";
import { mockVscode } from "./mockUtil";

const config = {
Expand All @@ -38,6 +38,7 @@ mockVscode(testVscode, "src/yeomanui.ts");
describe('yeomanui unit test', () => {
let sandbox: any;
let yeomanEnvMock: any;
let appWizardMock: any;
let fsExtraMock: any;
let datauriMock: any;
let loggerMock: any;
Expand All @@ -49,6 +50,21 @@ describe('yeomanui unit test', () => {

const choiceMessage =
"Some quick example text of the generator description. This is a long text so that the example will look good.";
class TestAppWizard extends AppWizard {
public showError(message: string, type: MessageType): void {
return;
}
public showWarning(message: string, type: MessageType): void {
return;
}
public showInformation(message: string, type: MessageType): void {
return;
}
public showProgress(message?: string): void {
return;
}
}
const appWizard: AppWizard = new TestAppWizard();
class TestEvents implements YouiEvents {
public doGeneratorDone(success: boolean, message: string, selectedWorkspace: string, type: string, targetPath?: string): void {
return;
Expand Down Expand Up @@ -126,6 +142,7 @@ describe('yeomanui unit test', () => {

beforeEach(() => {
yeomanEnvMock = sandbox.mock(yeomanEnv);
appWizardMock = sandbox.mock(appWizard);
fsExtraMock = sandbox.mock(fsextra);
datauriMock = sandbox.mock(datauri);
rpcMock = sandbox.mock(rpc);
Expand All @@ -136,6 +153,7 @@ describe('yeomanui unit test', () => {

afterEach(() => {
yeomanEnvMock.verify();
appWizardMock.verify();
fsExtraMock.verify();
datauriMock.verify();
rpcMock.verify();
Expand Down Expand Up @@ -221,6 +239,13 @@ describe('yeomanui unit test', () => {
});
});

describe("getState", () => {
it("getState", async () => {
const result = await yeomanUi["getState"]();
expect(result.messages).to.be.deep.equal(messages);
});
});

describe("_notifyGeneratorsChange", () => {
it("there are no generators", async () => {
const result = await yeomanUi["getGeneratorsPrompt"]();
Expand All @@ -241,6 +266,96 @@ describe('yeomanui unit test', () => {
});
});

describe("_notifyGeneratorsInstall", () => {
it("args = undefined", async () => {
rpcMock.expects("invoke").withExactArgs("isGeneratorsPrompt").never();
await yeomanUi._notifyGeneratorsInstall(undefined, false);
expect(yeomanUi["uiOptions"].installGens).to.be.undefined;
});
it("args = [], isGeneratorsPrompt = true , force = false", async () => {
const args: any = [];
rpcMock.expects("invoke").withExactArgs("isGeneratorsPrompt").resolves(true);
youiEventsMock.expects("getAppWizard").returns(appWizard);
appWizardMock.expects("showInformation").withExactArgs("We have finished installing all generators, enjoy your work!", MessageType.prompt);
await yeomanUi._notifyGeneratorsInstall(args, false);
expect(yeomanUi["uiOptions"].installGens).to.be.undefined;
});
it("isGeneratorsPrompt = true , force = false", async () => {
const args = [
{
name: "@sap/generator-mine",
versionRange: "2.0.1"
},
{
name: "generator-java-thing",
versionRange: "*"
},
{
name: "@sap/generator-my-second",
versionRange: "^2.0.1"
}
];
rpcMock.expects("invoke").withExactArgs("isGeneratorsPrompt").resolves(true);
youiEventsMock.expects("getAppWizard").returns(appWizard);
appWizardMock.expects("showInformation").withExactArgs("There are some generators that are being installed.", MessageType.prompt);
await yeomanUi._notifyGeneratorsInstall(args, false);
expect(yeomanUi["uiOptions"].installGens).to.be.deep.equal(args);
});
it("isGeneratorsPrompt = false , force = true", async () => {
const args = [
{
name: "@sap/generator-mine",
versionRange: "2.0.1"
},
{
name: "generator-java-thing",
versionRange: "*"
},
{
name: "@sap/generator-my-second",
versionRange: "^2.0.1"
}
];
rpcMock.expects("invoke").withExactArgs("isGeneratorsPrompt").resolves(false);
youiEventsMock.expects("getAppWizard").returns(appWizard);
appWizardMock.expects("showInformation").withExactArgs("There are some generators that are being installed.", MessageType.prompt);
await yeomanUi._notifyGeneratorsInstall(args, true);
expect(yeomanUi["uiOptions"].installGens).to.be.deep.equal(args);
});
it("isGeneratorsPrompt = false , force = false", async () => {
const args = [
{
name: "@sap/generator-mine",
versionRange: "2.0.1"
},
{
name: "generator-java-thing",
versionRange: "*"
},
{
name: "@sap/generator-my-second",
versionRange: "^2.0.1"
}
];
rpcMock.expects("invoke").withExactArgs("isGeneratorsPrompt").resolves(false);
youiEventsMock.expects("getAppWizard").never();
appWizardMock.expects("showInformation").never();
await yeomanUi._notifyGeneratorsInstall(args, false);
expect(yeomanUi["uiOptions"].installGens).to.be.deep.equal(args);
});
});

describe("getGeneratorsInstallingMessage", async () => {
it("args = []", async () => {
const result = await yeomanUi["getGeneratorsInstallingMessage"]([]);
expect(result).to.be.deep.equal("We have finished installing all generators, enjoy your work!");
});
it("args = not empty", async () => {
const result = await yeomanUi["getGeneratorsInstallingMessage"]([{}]);
expect(result).to.be.deep.equal("There are some generators that are being installed.");
});
});

describe("getGeneratorsPrompt", () => {
beforeEach(() => {
yeomanUi["gensMetaPromise"] = Promise.resolve({
Expand Down
6 changes: 3 additions & 3 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ module.exports = {
],
coverageThreshold: {
"global": {
"branches": 92,
"branches": 93,
"functions": 98,
"lines": 95,
"statements": 95
"lines": 96,
"statements": 96
}
}
}
2 changes: 1 addition & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export default {
}
},
async isGeneratorsPrompt() {
isGeneratorsPrompt() {
return (this.promptIndex === 0 && this.selectGeneratorPromptExists());
},
Expand Down
31 changes: 31 additions & 0 deletions frontend/tests/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ describe('App.vue', () => {
})
});

describe('isGeneratorsPrompt - method', () => {
it('promptIndex = 0, selectGeneratorPromptExists = true', () => {
wrapper = initComponent(App, {}, true)
wrapper.vm.promptIndex = 0;
wrapper.vm.selectGeneratorPromptExists = () => true;
const result = wrapper.vm.isGeneratorsPrompt();
expect(result).toBeTruthy();
})
it('promptIndex = 0, selectGeneratorPromptExists = false', () => {
wrapper = initComponent(App, {}, true)
wrapper.vm.promptIndex = 0;
wrapper.vm.selectGeneratorPromptExists = () => false;
const result = wrapper.vm.isGeneratorsPrompt();
expect(result).toBeFalsy();
})
it('promptIndex > 0, selectGeneratorPromptExists = true', () => {
wrapper = initComponent(App, {}, true)
wrapper.vm.promptIndex = 1;
wrapper.vm.selectGeneratorPromptExists = () => true;
const result = wrapper.vm.isGeneratorsPrompt();
expect(result).toBeFalsy();
})
it('promptIndex > 0, selectGeneratorPromptExists = false', () => {
wrapper = initComponent(App, {}, true)
wrapper.vm.promptIndex = 1;
wrapper.vm.selectGeneratorPromptExists = () => false;
const result = wrapper.vm.isGeneratorsPrompt();
expect(result).toBeFalsy();
})
})

describe('isNoGenerators - method', () => {
it('no generators', () => {
wrapper = initComponent(App, {}, true)
Expand Down

0 comments on commit 3013278

Please sign in to comment.