From 920d1a4b37bdf01e680b4126d02f7ab5cd7a5bac Mon Sep 17 00:00:00 2001 From: Minojhini Valaiyapathi Date: Thu, 30 Jul 2026 07:15:23 -0400 Subject: [PATCH] CASH-3054 - inconsistent fade transition Part Question --- .../question-chain/question-chain.spec.js | 78 +++++++++++++++++-- .../question-chain/question-chain.vue | 19 +++-- 2 files changed, 87 insertions(+), 10 deletions(-) diff --git a/src/digital-components/question-chain/question-chain.spec.js b/src/digital-components/question-chain/question-chain.spec.js index d0e54a895..2bddbb2be 100644 --- a/src/digital-components/question-chain/question-chain.spec.js +++ b/src/digital-components/question-chain/question-chain.spec.js @@ -324,18 +324,65 @@ describe("Question Chain component", () => { }); }); - test("should trigger scroll to .current-question if returnedAnswer is a nextQuestion (not a final answer)", async () => { + test("should defer scroll until after the next question fade enters", async () => { //Arrange - const { wrapper } = setupMocks({}); + const { wrapper } = setupMocks({ + questionDataProp: [ + { + questionSequence: 1, + questionText: "Question 1?", + answers: [ + { + answerResult: "", + answerText: "Yes", + nextQuestionSequence: 3, + }, + { + answerResult: "DB10840", + answerText: "No", + nextQuestionSequence: null, + }, + ], + }, + { + questionSequence: 3, + questionText: "Question 3?", + answers: [ + { + answerResult: "DB09410", + answerText: "Yes", + nextQuestionSequence: null, + }, + ], + }, + ], + }); + await nextTick(); const testReturnedAnswer = "1|nextQuestion|3|No"; + const scrollSpy = jest.spyOn(wrapper.vm, "scrollCurrentQuestionIntoView"); //Act wrapper.vm.getQuestionChainAnswerIfComplete(testReturnedAnswer); + const nextQuestion = wrapper.vm.questions.find((q) => q.questionSequence === 3); - await nextTick(); + //Assert — advancing via nextQuestion no longer scrolls immediately + expect(scrollSpy).not.toHaveBeenCalled(); + expect(wrapper.vm.currentQuestionNum).toBe(3); + expect(wrapper.vm.isCurrentQuestion(nextQuestion)).toBe(true); - //Assert - expect(Element.prototype.scrollIntoView).toHaveBeenCalled(); + wrapper.vm.onQuestionEnter(nextQuestion); + + expect(scrollSpy).toHaveBeenCalledTimes(1); + }); + + test("should not scroll onQuestionEnter for a non-current question", () => { + const { wrapper } = setupMocks({}); + const scrollSpy = jest.spyOn(wrapper.vm, "scrollCurrentQuestionIntoView"); + const answeredQuestion = wrapper.vm.questions[0]; + + wrapper.vm.onQuestionEnter(answeredQuestion); + + expect(scrollSpy).not.toHaveBeenCalled(); }); test("should return answer object if returnedAnswer is a final matching answer", async () => { @@ -528,6 +575,27 @@ describe("Question Chain component", () => { expect(wrapper.vm.currentQuestionNum).toBe(2); expect(wrapper.vm.isQuestionVisible(wrapper.vm.questions[1])).toBe(true); }); + + test("should show only Q1 and Q2 after Cherokee Q1 Yes then Q2 No", async () => { + const { wrapper } = setupMocks({ + questionDataProp: getCherokeeWindshieldQuestions(), + }); + await nextTick(); + + wrapper.vm.handleAnswer(wrapper.vm.questions[0], "1|nextQuestion|2|Yes"); + wrapper.vm.handleAnswer(wrapper.vm.questions[1], "2|answer|DW02264|No"); + + const visibleQuestions = wrapper.vm.questions.filter((question) => + wrapper.vm.isQuestionVisible(question) + ); + + expect(wrapper.vm.currentQuestionNum).toBe(0); + expect(visibleQuestions).toHaveLength(2); + expect(visibleQuestions.map((question) => question.questionSequence)).toEqual([1, 2]); + expect(wrapper.vm.isCurrentQuestion(wrapper.vm.questions[0])).toBe(false); + expect(wrapper.vm.isCurrentQuestion(wrapper.vm.questions[1])).toBe(false); + expect(wrapper.vm.isQuestionVisible(wrapper.vm.questions[2])).toBe(false); + }); }); }); diff --git a/src/digital-components/question-chain/question-chain.vue b/src/digital-components/question-chain/question-chain.vue index 467e9619e..248ef2204 100644 --- a/src/digital-components/question-chain/question-chain.vue +++ b/src/digital-components/question-chain/question-chain.vue @@ -1,10 +1,16 @@