Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class YeomanUI {
this.rpc.registerMethod({ func: this.exploreGenerators, thisArg: this });
this.rpc.registerMethod({ func: this.logError, thisArg: this });
this.rpc.registerMethod({ func: this.back, thisArg: this });
this.rpc.registerMethod({ func: this.fromWizard, thisArg: this });
this.rpc.registerMethod({ func: this.executeCommand, thisArg: this });
this.rpc.registerMethod({ func: this.getState, thisArg: this });

Expand Down Expand Up @@ -392,6 +393,11 @@ export class YeomanUI {
return this.runGenerator(this.generatorName);
}

private fromWizard(): boolean {
if (this.uiOptions.generator) return false;
return true;
}

private executeCommand(id: string, ...args: any[]): void {
void this.youiEvents.executeCommand(id, args);
}
Expand Down
28 changes: 28 additions & 0 deletions packages/backend/test/yeomanui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,34 @@ describe("yeomanui unit test", () => {
expect(res.message).to.be.equal(errorInfo);
});

describe("fromWizard", () => {
it("from fiori generator", () => {
const yeomanUiInstance: YeomanUI = new YeomanUI(
rpc,
youiEvents,
outputChannel,
testLogger,
{ generator: "fiori" },
flowPromise.state,
);
const res = yeomanUiInstance["fromWizard"]();
expect(res).to.be.false;
});

it("from application wizard", () => {
const yeomanUiInstance: YeomanUI = new YeomanUI(
rpc,
youiEvents,
outputChannel,
testLogger,
{ generator: undefined },
flowPromise.state,
);
const res = yeomanUiInstance["fromWizard"]();
expect(res).to.be.true;
});
});

describe("answersUtils", () => {
it("setDefaults", () => {
const questions = [{ name: "q1", default: "a" }, { name: "q2", default: () => "b" }, { name: "q3" }];
Expand Down
10 changes: 7 additions & 3 deletions packages/frontend/src/youi/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,24 @@ export default {
back() {
return this.gotoStep(1); // go 1 step back
},
gotoStep(numOfSteps) {
async gotoStep(numOfSteps) {
// go numOfSteps step back
try {
this.toShowPromptMessage = false;
this.isReplaying = true;
this.numOfSteps = numOfSteps;
const answers = this.currentPrompt.answers;
if (this.promptIndex - numOfSteps > 0) {
let fromWizard = true;
const targetStep = this.promptIndex - numOfSteps;
if (targetStep === 0) {
fromWizard = await this.rpc.invoke("fromWizard");
}
if ((fromWizard && targetStep > 0) || (!fromWizard && targetStep === 0)) {
return this.rpc.invoke("back", [
answers !== undefined ? JSON.parse(JSON.stringify(answers)) : answers,
numOfSteps,
]);
}

return this.reload();
} catch (error) {
this.rpc.invoke("logError", [error]);
Expand Down
28 changes: 17 additions & 11 deletions packages/frontend/test/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,12 @@ describe("App.vue", () => {
});

describe("back - method", () => {
test("promptIndex is 0 (Select Generator)", () => {
test("promptIndex is 0 (Select Generator)", async () => {
wrapper = initComponent(App, {}, true);
wrapper.vm.rpc = {
invoke: jest.fn(),
invoke: jest.fn().mockImplementation(async () => {
return true;
}),
registerMethod: jest.fn(),
};
const invokeSpy = jest.spyOn(wrapper.vm.rpc, "invoke");
Expand All @@ -734,7 +736,7 @@ describe("App.vue", () => {
wrapper.vm.promptIndex = 1;
wrapper.vm.prompts = [{}, {}];

wrapper.vm.back();
await wrapper.vm.back();

expect(wrapper.vm.promptIndex).toBe(0);
expect(wrapper.vm.prompts.length).toBe(0);
Expand Down Expand Up @@ -780,23 +782,24 @@ describe("App.vue", () => {
});

describe("gotoStep - method", () => {
test("promptIndex is 1, goto 1 step back -> (Select Generator)", () => {
test("promptIndex is 1, goto 1 step back -> (Select Generator)", async () => {
wrapper = initComponent(App, {}, true);
wrapper.vm.rpc = {
invoke: jest.fn(),
invoke: jest.fn().mockImplementation(async () => {
return true;
}),
registerMethod: jest.fn(),
};
const invokeSpy = jest.spyOn(wrapper.vm.rpc, "invoke");

wrapper.vm.resolve = undefined;
wrapper.vm.promptIndex = 1;
wrapper.vm.prompts = [{}, {}];

wrapper.vm.gotoStep(1);

await wrapper.vm.gotoStep(1);
expect(wrapper.vm.promptIndex).toBe(0);
expect(wrapper.vm.prompts.length).toBe(0);
expect(wrapper.vm.isReplaying).toBe(false);
expect(invokeSpy).toHaveBeenCalledWith("fromWizard");
expect(invokeSpy).toHaveBeenCalledWith("getState");
});

Expand All @@ -823,7 +826,9 @@ describe("App.vue", () => {
test("promptIndex is 3, goto 3, exception thrown", async () => {
wrapper = initComponent(App, {}, true);
wrapper.vm.rpc = {
invoke: jest.fn(),
invoke: jest.fn().mockImplementation(async () => {
return true;
}),
registerMethod: jest.fn(),
};
const err = new Error("error");
Expand All @@ -833,8 +838,9 @@ describe("App.vue", () => {
wrapper.vm.reject = jest.fn();
wrapper.vm.promptIndex = 3;
wrapper.vm.prompts = [{}, {}, {}, { questions: [] }];
wrapper.vm.gotoStep(3);

await wrapper.vm.gotoStep(3);
expect(wrapper.vm.rpc.invoke).toHaveBeenCalledTimes(2);
expect(wrapper.vm.rpc.invoke).toHaveBeenCalledWith("fromWizard");
expect(wrapper.vm.rpc.invoke).toHaveBeenCalledWith("logError", [err]);
expect(wrapper.vm.reject).toHaveBeenCalledWith(err);
});
Expand Down