diff --git a/frontend/jest.config.js b/frontend/jest.config.js index 30f21213..12d1d63c 100644 --- a/frontend/jest.config.js +++ b/frontend/jest.config.js @@ -35,7 +35,7 @@ module.exports = { ], coverageThreshold: { "global": { - "branches": 86, + "branches": 87, "functions": 98, "lines": 95, "statements": 95 diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 5c727032..f05ca900 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -161,21 +161,23 @@ export default { } }, methods: { - async updateQuestionsFromIndex(questionIndex) { + async updateQuestionsFromIndex(changedQuestionIndex) { const questions = _.get(this, "currentPrompt.questions", []); - const relevantQuestionsToUpdate = _.slice(questions, questionIndex) + const relevantQuestionsToUpdate = _.slice(questions, changedQuestionIndex) let showBusy = true const that = this + let questionIndex = changedQuestionIndex - 1; const finished = relevantQuestionsToUpdate.reduce((p, question) => { - return p.then(() => that.updateQuestion(question)) + questionIndex++; + return p.then(() => that.updateQuestion(question, questionIndex, changedQuestionIndex)) }, Promise.resolve()); setTimeout(() => { if (showBusy) { that.showBusyIndicator = true } - }, 500) + }, 1000) await finished showBusy = false @@ -186,7 +188,7 @@ export default { _.isEmpty(this.prompts) || (this.currentPrompt.status === PENDING && !this.isDone); }, - async updateQuestion(question) { + async updateQuestion(question, questionIndex, changedQuestionIndex) { const newAnswers = this.currentPrompt.answers try { if (question.when === FUNCTION) { @@ -215,6 +217,9 @@ export default { question.answer = question.default; } } + if (question.type === "password" && questionIndex !== changedQuestionIndex) { + question.answer = undefined; + } if (question._message === FUNCTION) { question.message = await this.rpc.invoke("evaluateMethod", [ [newAnswers], diff --git a/frontend/src/components/QuestionTypes/QuestionInput.vue b/frontend/src/components/QuestionTypes/QuestionInput.vue index 66bbd548..6e5412a3 100644 --- a/frontend/src/components/QuestionTypes/QuestionInput.vue +++ b/frontend/src/components/QuestionTypes/QuestionInput.vue @@ -36,6 +36,13 @@ export default { return type === "input" ? "text" : type; } }, + watch: { + "currentQuestion.answer": { + handler(currentAnswer) { + this.text = currentAnswer; + } + } + }, methods: { onChange() { const currentValue = _.isEmpty(this.text) ? _.get(this.currentQuestion, "default") : this.text; diff --git a/frontend/tests/App.spec.js b/frontend/tests/App.spec.js index 1b5ba97e..4553e5ff 100644 --- a/frontend/tests/App.spec.js +++ b/frontend/tests/App.spec.js @@ -153,7 +153,7 @@ describe('App.vue', () => { } wrapper.vm.prompts = [{ questions: [{ - name: 'validateQ', validate: '__Function', answer: 'validateAnswer', isWhen: true, doNotShow: false + name: 'validateQ', validate: '__Function', answer: 'validateAnswer', isWhen: true }], answers: {} }] @@ -175,7 +175,7 @@ describe('App.vue', () => { } wrapper.vm.prompts = [{ questions: [{ - name: 'validateQ', validate: '__Function', answer: 'validateAnswer', isWhen: true, doNotShow: false + name: 'validateQ', validate: '__Function', answer: 'validateAnswer', isWhen: true }], answers: {} }] @@ -197,7 +197,7 @@ describe('App.vue', () => { } wrapper.vm.prompts = [{ questions: [{ - name: 'validateQ', validate: '__Function', answer: 'validateAnswer', isWhen: true, doNotShow: false + name: 'validateQ', validate: '__Function', answer: 'validateAnswer', isWhen: true }], answers: {} }] @@ -212,6 +212,26 @@ describe('App.vue', () => { invokeSpy.mockRestore(); }) + + test('invoke for question that comes before question of type password', async () => { + wrapper.vm.rpc = { + invoke: jest.fn().mockResolvedValue() + } + wrapper.vm.prompts = [{ + questions: [{ + name: 'serviceQ', validate: '__Function', answer: 'serviceAnswer', isWhen: true + }, { + name: 'passwordQ', validate: '__Function', answer: "somePassword", isWhen: true, type: "password" + }], + answers: {} + }] + wrapper.vm.generatorName = "testGen"; + wrapper.vm.promptIndex = 0; + + await wrapper.vm.updateQuestionsFromIndex(0) + + expect(wrapper.vm.prompts[0].questions[1].answer).toBeUndefined() + }) }) describe('setQuestionProps - method', () => { diff --git a/frontend/tests/components/QuestionTypes/QuestionInput.spec.js b/frontend/tests/components/QuestionTypes/QuestionInput.spec.js index d03520aa..eb3fbbf4 100644 --- a/frontend/tests/components/QuestionTypes/QuestionInput.spec.js +++ b/frontend/tests/components/QuestionTypes/QuestionInput.spec.js @@ -35,6 +35,34 @@ describe('QuestionInput.vue', () => { }) }) + describe('currentQuestion.answe - watch', () => { + test('current answer is undefined', () => { + wrapper = initComponent(QuestionInput, { + currentQuestion: { + type: 'input', default: 'testDefault', answer: 'testAnswer' + }, + updateQuestionsFromIndex: () => {} + }) + + wrapper.vm.$data.text = '' + wrapper.vm.$options.watch["currentQuestion.answer"].handler.call(wrapper.vm, undefined) + expect(wrapper.vm.$data.text).toBeUndefined() + }) + + test('current answer is defined', () => { + wrapper = initComponent(QuestionInput, { + currentQuestion: { + type: 'input', default: 'testDefault', answer: 'testAnswer' + }, + updateQuestionsFromIndex: () => {} + }) + + wrapper.vm.$data.text = '' + wrapper.vm.$options.watch["currentQuestion.answer"].handler.call(wrapper.vm, "test") + expect(wrapper.vm.$data.text).toBe("test") + }) + }) + describe('text - method', () => { test('text size is 0', async () => { wrapper = initComponent(QuestionInput, {