import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
import { shallowMount } from "@vue/test-utils";
import { setupMocksForJsFiles, getMountOptions } from "@/helpers/unit-test-helper.js";
import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
import { storeMutations } from "@/constants/store-mutations";
import store from "@/store";
import { storeActions } from "@/constants/store-actions";
import { navigationScenarios } from "../router/router-constants/navigation-scenarios";
import { getters } from "@/store";

jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({
    navigateToHeritageFunnel: jest.fn(),
}));

describe("vehicle-questions-mixin", () => {
    afterEach(() => {
        jest.clearAllMocks();
    });

    describe("hasPartQuestions", () => {
        test("has no part questions => return false", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasPartQuestions = wrapper.vm.hasPartQuestions([
                {
                    partQuestions: [],
                },
            ]);

            // Assert
            expect(hasPartQuestions).toBe(false);
        });

        test("has undefined part questions => return false", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasPartQuestions = wrapper.vm.hasPartQuestions([]);

            // Assert
            expect(hasPartQuestions).toBe(false);
        });

        test("has part questions => return true", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasPartQuestions = wrapper.vm.hasPartQuestions([
                {
                    partQuestions: [
                        {
                            testProperty: "some value",
                        },
                    ],
                },
            ]);

            // Assert
            expect(hasPartQuestions).toBe(true);
        });
    });

    describe("hasGlassLocationWithMultipleParts", () => {
        test("has one part for one glass location => return false", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasGlassLocationWithMultipleParts = wrapper.vm.hasGlassLocationWithMultipleParts([
                {
                    glassName: "Something",
                    glassLocation: "somewhere",
                    parts: [
                        {
                            partNumber: "1234567",
                        },
                    ],
                },
            ]);

            // Assert
            expect(hasGlassLocationWithMultipleParts).toBe(false);
        });

        test("has one part for every glass location => return false", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasGlassLocationWithMultipleParts = wrapper.vm.hasGlassLocationWithMultipleParts([
                {
                    glassName: "Something",
                    glassLocation: "somewhere",
                    parts: [
                        {
                            partNumber: "1234567",
                        },
                    ],
                },
                {
                    glassName: "Another glass",
                    glassLocation: "somewhere else",
                    parts: [
                        {
                            partNumber: "1234568",
                        },
                    ],
                },
                {
                    glassName: "Special glass",
                    glassLocation: "Another where",
                    parts: [
                        {
                            partNumber: "1234569",
                        },
                    ],
                },
            ]);

            // Assert
            expect(hasGlassLocationWithMultipleParts).toBe(false);
        });

        test("has multiple parts for one glass location => return true", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasGlassLocationWithMultipleParts = wrapper.vm.hasGlassLocationWithMultipleParts([
                {
                    glassName: "Something",
                    glassLocation: "somewhere",
                    parts: [
                        {
                            partNumber: "1234567",
                        },
                    ],
                },
                {
                    glassName: "Another glass",
                    glassLocation: "somewhere else",
                    parts: [
                        {
                            partNumber: "1234568",
                        },
                    ],
                },
                {
                    glassName: "Special glass",
                    glassLocation: "Another where",
                    parts: [
                        {
                            partNumber: "1234569",
                        },
                        {
                            partNumber: "1234560",
                        },
                    ],
                },
            ]);

            // Assert
            expect(hasGlassLocationWithMultipleParts).toBe(true);
        });
    });

    describe("hasChildPartQuestions", () => {
        test("has no child part questions => return false", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasChildPartQuestions = wrapper.vm.hasChildPartQuestions([
                {
                    parts: [
                        {
                            childPartQuestions: [],
                        },
                    ],
                },
            ]);

            // Assert
            expect(hasChildPartQuestions).toBe(false);
        });

        test("has undefined child part questions => return false", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasChildPartQuestions = wrapper.vm.hasChildPartQuestions([]);

            // Assert
            expect(hasChildPartQuestions).toBe(false);
        });

        test("has child part questions => return true", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasChildPartQuestions = wrapper.vm.hasChildPartQuestions([
                {
                    parts: [
                        {
                            childPartQuestions: [
                                {
                                    questionSequence: 1,
                                    questionText:
                                        "Does the rubber seal around your windshield have a chrome strip running through it?",
                                    answers: [
                                        {
                                            answerResult: "WKT D1106 C",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "WKT D1106 B",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                            ],
                        },
                    ],
                },
            ]);

            // Assert
            expect(hasChildPartQuestions).toBe(true);
        });
    });

    describe("hasCapabilityQuestions", () => {
        test("has no capability questions => return false", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasCapabilityQuestions = wrapper.vm.hasCapabilityQuestions([
                {
                    parts: [
                        {
                            requiresCapabilityQuestions: false,
                        },
                    ],
                },
            ]);

            // Assert
            expect(hasCapabilityQuestions).toBe(false);
        });

        test("has undefined capability questions => return false", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasCapabilityQuestions = wrapper.vm.hasCapabilityQuestions([]);

            // Assert
            expect(hasCapabilityQuestions).toBe(false);
        });

        test("has capability questions => return true", () => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const hasCapabilityQuestions = wrapper.vm.hasCapabilityQuestions([
                {
                    parts: [
                        {
                            requiresCapabilityQuestions: true,
                        },
                    ],
                },
            ]);

            // Assert
            expect(hasCapabilityQuestions).toBe(true);
        });
    });

    describe("currentPageComesBeforePage", () => {
        const testCases = [
            [fmgPageValues.PART_QUESTIONS, fmgPageValues.VEHICLE_PARTS, true],
            [fmgPageValues.VEHICLE_PARTS, fmgPageValues.VEHICLE_PARTS, false],
            [fmgPageValues.QUOTE, fmgPageValues.VEHICLE_PARTS, false],
            [fmgPageValues.QUOTE, fmgPageValues.QUOTE, false],
            [fmgPageValues.VEHICLE_PARTS, fmgPageValues.PART_QUESTIONS, false],
            [fmgPageValues.PART_QUESTIONS, fmgPageValues.CAPABILITY_QUESTIONS, true],
            [fmgPageValues.MOLDING_QUESTIONS, fmgPageValues.CAPABILITY_QUESTIONS, true],
        ];
        test.each(testCases)(
            "%s comes before %s is %s",
            (currentPage, nextPage, expectedResult) => {
                // Arrange
                const { wrapper } = setupMocks({});

                // Act
                const result = wrapper.vm.currentPageComesBeforePage(currentPage, nextPage);

                // Assert
                expect(result).toEqual(expectedResult);
            }
        );
    });

    describe("currentPageComesAfterPage", () => {
        const testCases = [
            [fmgPageValues.PART_QUESTIONS, fmgPageValues.VEHICLE_PARTS, false],
            [fmgPageValues.VEHICLE_PARTS, fmgPageValues.VEHICLE_PARTS, false],
            [fmgPageValues.QUOTE, fmgPageValues.VEHICLE_PARTS, true],
            [fmgPageValues.QUOTE, fmgPageValues.QUOTE, false],
            [fmgPageValues.VEHICLE_PARTS, fmgPageValues.PART_QUESTIONS, true],
            [fmgPageValues.PART_QUESTIONS, fmgPageValues.CAPABILITY_QUESTIONS, false],
            [fmgPageValues.MOLDING_QUESTIONS, fmgPageValues.CAPABILITY_QUESTIONS, false],
        ];
        test.each(testCases)("%s comes after %s is %s", (currentPage, nextPage, expectedResult) => {
            // Arrange
            const { wrapper } = setupMocks({});

            // Act
            const result = wrapper.vm.currentPageComesAfterPage(currentPage, nextPage);

            // Assert
            expect(result).toEqual(expectedResult);
        });
    });

    describe("setupInitialData", () => {
        describe("if no alreadyAnsweredQuestions", () => {
            test("should return glass with answerData of null", async () => {
                // Arrange
                const glass = {
                    glassName: "Single",
                    glassLocation: "Windshield",
                };
                const i = 0;
                const { wrapper } = setupMocks({});

                // Act
                const returnedGlass = await wrapper.vm.setupInitialData(glass, i);

                // Assert
                expect(returnedGlass).toMatchObject({ answerData: null });
            });
        });

        describe("if alreadyAnsweredQuestions", () => {
            test("should return glass with answerResult within answerData", async () => {
                // Arrange
                const glass = {
                    glassName: "Single",
                    glassLocation: "Windshield",
                    questions: [
                        {
                            questionSequence: 1,
                            questionText:
                                "Does the rubber seal around your windshield have a chrome strip running through it?",
                            answers: [
                                {
                                    answerResult: "WKT D1106 C",
                                    answerText: "Yes",
                                    nextQuestionSequence: null,
                                },
                                {
                                    answerResult: "WKT D1106 B",
                                    answerText: "No",
                                    nextQuestionSequence: null,
                                },
                            ],
                        },
                    ],
                };
                const i = 0;
                const alreadyAnsweredQuestions = [
                    {
                        glassLocation: "Windshield",
                        glassName: "Single",
                        partNum: "WKT D1106 C",
                        answeredQuestions: [
                            {
                                questionText:
                                    "Does the rubber seal around your windshield have a chrome strip running through it?",
                                selectedAnswerText: "Yes",
                                questionNum: 1,
                            },
                        ],
                    },
                ];
                const { wrapper } = setupMocks({});

                // Act
                const returnedGlass = await wrapper.vm.setupInitialData(
                    glass,
                    i,
                    alreadyAnsweredQuestions
                );

                // Assert
                expect(returnedGlass.answerData).toMatchObject({ answerResult: "WKT D1106 C" });
            });
        });
    });

    describe("calculateQuestionIndex", () => {
        describe("if currentGlassIndex is zero...", () => {
            test("should return index of first glass piece with questions", () => {
                // Arrange
                const questionsData = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                    },
                    {
                        glassName: "Front",
                        glassLocation: "Driver",
                        questions: ["example question"],
                    },
                ];
                const glassIndex = 0;
                const { wrapper } = setupMocks({});

                // Act
                const returnedIndex = wrapper.vm.calculateQuestionIndex(glassIndex, questionsData);

                // Assert
                expect(returnedIndex).toBe(1);
            });
        });
        describe("if currentGlassIndex is NOT zero...", () => {
            test("should return currentGlassIndex value", () => {
                // Arrange
                const questionsData = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                    },
                    {
                        glassName: "Front",
                        glassLocation: "Driver",
                        questions: ["example question"],
                    },
                ];
                const glassIndex = 1;
                const { wrapper } = setupMocks({});

                // Act
                const returnedIndex = wrapper.vm.calculateQuestionIndex(glassIndex, questionsData);

                // Assert
                expect(returnedIndex).toBe(1);
            });
        });
    });

    describe("handleCompletedQuestionChainAnswers", () => {
        describe("selectedAnswers", () => {
            test("should be cleared to be empty", () => {
                // Arrange
                const answer = {
                    answerResult: "DD11132",
                    answeredQuestions: [
                        {
                            questionText: "Test duplicate question 1?",
                            selectedAnswer: "1|nextQuestion|3|Yes",
                            selectedAnswerText: "Yes",
                            questionNum: 1,
                        },
                    ],
                    index: 0,
                };
                const { wrapper } = setupMocks({});

                wrapper.vm.selectedAnswers = { test: "mockSelectedAnswers" };
                wrapper.vm.questionsData = [
                    {
                        glassLocation: "Windshield",
                        glassName: "Single",
                        questions: [],
                        answerData: "testAnswerData1",
                    },
                ];

                // Act
                wrapper.vm.handleCompletedQuestionChainAnswers(answer, "", wrapper.vm);

                // Assert
                expect(wrapper.vm.selectedAnswers).toMatchObject({});
            });
        });

        describe("questions in glass parts that are after the answered glass", () => {
            test("should have answerData cleared", () => {
                // Arrange
                const answer = {
                    answerResult: "DD11132",
                    answeredQuestions: [
                        {
                            questionText: "Test duplicate question 1?",
                            selectedAnswer: "1|nextQuestion|3|Yes",
                            selectedAnswerText: "Yes",
                            questionNum: 1,
                        },
                    ],
                    index: 0,
                };
                const { wrapper } = setupMocks({});

                wrapper.vm.questionsData = [
                    {
                        glassLocation: "Windshield",
                        glassName: "Single",
                        questions: [],
                        answerData: "testAnswerData1",
                    },
                    {
                        glassLocation: "Driver",
                        glassName: "Front",
                        questions: [],
                        answerData: "testAnswerData2",
                    },
                ];

                // Act
                wrapper.vm.handleCompletedQuestionChainAnswers(answer, "", wrapper.vm);

                // Assert
                expect(wrapper.vm.questionsData[1].answerData).toEqual(null);
            });
            test("should have isSuppressedPart cleared", () => {
                // Arrange
                const answer = {
                    answerResult: "DD11132",
                    answeredQuestions: [
                        {
                            questionText: "Test duplicate question 1?",
                            selectedAnswer: "1|nextQuestion|3|Yes",
                            selectedAnswerText: "Yes",
                            questionNum: 1,
                        },
                    ],
                    index: 0,
                };
                const { wrapper } = setupMocks({});

                wrapper.vm.questionsData = [
                    {
                        glassLocation: "Windshield",
                        glassName: "Single",
                        questions: [],
                        answerData: "testAnswerData1",
                    },
                    {
                        glassLocation: "Driver",
                        glassName: "Front",
                        questions: [],
                        answerData: "testAnswerData2",
                        isSuppressedPart: true,
                    },
                ];

                // Act
                wrapper.vm.handleCompletedQuestionChainAnswers(answer, "", wrapper.vm);

                // Assert
                expect(wrapper.vm.questionsData[1].isSuppressedPart).toEqual(null);
            });
            test("should set answerSelected for each glass part question to null ", () => {
                // Arrange
                const answer = {
                    answerResult: "DD11132",
                    answeredQuestions: [
                        {
                            questionText: "Test duplicate question 1?",
                            selectedAnswer: "1|nextQuestion|3|Yes",
                            selectedAnswerText: "Yes",
                            questionNum: 1,
                        },
                    ],
                    index: 0,
                };
                const { wrapper } = setupMocks({});

                wrapper.vm.questionsData = [
                    {
                        glassLocation: "Windshield",
                        glassName: "Single",
                        questions: [],
                        answerData: "testAnswerData1",
                    },
                    {
                        glassLocation: "Driver",
                        glassName: "Front",
                        questions: [
                            {
                                questionSequence: 1,
                                questionText:
                                    "Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?",
                                answers: [
                                    {
                                        answerResult: "",
                                        answerText: "Yes",
                                        nextQuestionSequence: 2,
                                    },
                                    {
                                        answerResult: "",
                                        answerText: "No",
                                        nextQuestionSequence: 3,
                                    },
                                ],
                                answerSelected: "456",
                            },
                            {
                                questionSequence: 2,
                                questionText:
                                    "Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?",
                                answers: [
                                    {
                                        answerResult: "FW04848",
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                    },
                                    {
                                        answerResult: "FW04846",
                                        answerText: "No",
                                        nextQuestionSequence: null,
                                    },
                                ],
                                answerSelected: "789",
                            },
                        ],
                        answerData: "testAnswerData2",
                    },
                ];

                // Act
                wrapper.vm.handleCompletedQuestionChainAnswers(answer, "", wrapper.vm);

                // Assert
                expect(wrapper.vm.questionsData[1].questions[0].answerSelected).toEqual(null);
                expect(wrapper.vm.questionsData[1].questions[1].answerSelected).toEqual(null);
            });
        });

        describe("if there is a duplicate question", () => {
            test("then the glass piece's key should be updated", () => {
                // Arrange
                const answerNo = {
                    answerResult: "456",
                    answeredQuestions: [
                        {
                            questionText: "Test duplicate question 1?",
                            selectedAnswer: "1|nextQuestion|3|No",
                            selectedAnswerText: "No",
                            questionNum: 1,
                        },
                    ],
                    index: 0,
                };
                const { wrapper } = setupMocks({});

                wrapper.vm.questionsData = [
                    {
                        glassLocation: "Windshield",
                        glassName: "Single",
                        key: "testkey1",
                        questions: [
                            {
                                questionSequence: 1,
                                questionText: "Test duplicate question 1?",
                                answers: [
                                    {
                                        answerResult: "123",
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                    },
                                    {
                                        answerResult: "456",
                                        answerText: "No",
                                        nextQuestionSequence: null,
                                    },
                                ],
                            },
                        ],
                    },
                    {
                        glassLocation: "Driver",
                        glassName: "Front",
                        key: "testkey2",
                        questions: [
                            {
                                questionSequence: 1,
                                questionText: "Test duplicate question 1?",
                                answers: [
                                    {
                                        answerResult: "123",
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                    },
                                    {
                                        answerResult: "234",
                                        answerText: "No",
                                        nextQuestionSequence: null,
                                    },
                                ],
                            },
                        ],
                    },
                ];

                // Act
                wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
                const glassWithDuplicate = wrapper.vm.questionsData[1];

                // Assert
                expect(glassWithDuplicate.key).not.toBe("testkey2");
            });

            test("then that question should be supressed", () => {
                // Arrange
                const answerNo = {
                    answerResult: "456",
                    answeredQuestions: [
                        {
                            questionText: "Test duplicate question 1?",
                            selectedAnswer: "1|nextQuestion|3|No",
                            selectedAnswerText: "No",
                            questionNum: 1,
                        },
                    ],
                    index: 0,
                };
                const { wrapper } = setupMocks({});

                wrapper.vm.questionsData = [
                    {
                        glassLocation: "Windshield",
                        glassName: "Single",
                        questions: [
                            {
                                questionSequence: 1,
                                questionText: "Test duplicate question 1?",
                                answers: [
                                    {
                                        answerResult: "123",
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                    },
                                    {
                                        answerResult: "456",
                                        answerText: "No",
                                        nextQuestionSequence: null,
                                    },
                                ],
                            },
                        ],
                    },
                    {
                        glassLocation: "Driver",
                        glassName: "Front",
                        questions: [
                            {
                                questionSequence: 1,
                                questionText: "Test duplicate question 1?",
                                answers: [
                                    {
                                        answerResult: "123",
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                    },
                                    {
                                        answerResult: "234",
                                        answerText: "No",
                                        nextQuestionSequence: null,
                                    },
                                ],
                            },
                        ],
                    },
                ];

                // Act
                wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
                const duplicateQuestion = wrapper.vm.questionsData[1].questions[0];

                // Assert
                expect(duplicateQuestion.suppressThisQuestion).toBeTruthy();
            });

            describe("and the duplicate has a nextQuestionSequence value", () => {
                test("then the question set as nextQuestionSequence should not be suppressed", () => {
                    // Arrange
                    const answerNo = {
                        answerResult: "456",
                        answeredQuestions: [
                            {
                                questionText: "Test duplicate question 1?",
                                selectedAnswer: "1|nextQuestion|3|No",
                                selectedAnswerText: "No",
                                questionNum: 1,
                            },
                        ],
                        index: 0,
                    };
                    const { wrapper } = setupMocks({});

                    wrapper.vm.questionsData = [
                        {
                            glassLocation: "Windshield",
                            glassName: "Single",
                            questions: [
                                {
                                    questionSequence: 1,
                                    questionText: "Test duplicate question 1?",
                                    answers: [
                                        {
                                            answerResult: "123",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "456",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            glassLocation: "Driver",
                            glassName: "Front",
                            questions: [
                                {
                                    questionSequence: 1,
                                    questionText: "ZZZTest duplicate question 1?",
                                    answers: [
                                        {
                                            answerResult: "",
                                            answerText: "Yes",
                                            nextQuestionSequence: 2,
                                        },
                                        {
                                            answerResult: "",
                                            answerText: "No",
                                            nextQuestionSequence: 3,
                                        },
                                    ],
                                },
                                {
                                    questionSequence: 2,
                                    questionText: "Test question 2?",
                                    answers: [
                                        {
                                            answerResult: "123",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "234",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                                {
                                    questionSequence: 3,
                                    questionText: "Test question 3?",
                                    answers: [
                                        {
                                            answerResult: "345",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "456",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                    suppressThisQuestion: true,
                                },
                            ],
                        },
                    ];

                    // Act
                    wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
                    const nextQuestionAfterDuplicate = wrapper.vm.questionsData[1].questions[2];

                    // Assert
                    expect(nextQuestionAfterDuplicate.suppressThisQuestion).not.toBeTruthy();
                });

                test("then the nextQuestionSequence should be updated and the original value saved", () => {
                    // Arrange
                    const answerNo = {
                        answerResult: "456",
                        answeredQuestions: [
                            {
                                questionText: "Test question 3?",
                                selectedAnswer: "1|nextQuestion|3|No",
                                selectedAnswerText: "No",
                                questionNum: 1,
                            },
                        ],
                        index: 0,
                    };
                    const { wrapper } = setupMocks({});

                    wrapper.vm.questionsData = [
                        {
                            glassLocation: "Windshield",
                            glassName: "Single",
                            questions: [
                                {
                                    questionSequence: 1,
                                    questionText: "Test question 3?",
                                    answers: [
                                        {
                                            answerResult: "123",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "456",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            glassLocation: "Driver",
                            glassName: "Front",
                            questions: [
                                {
                                    questionSequence: 1,
                                    questionText: "Test question 1?",
                                    answers: [
                                        {
                                            answerResult: "",
                                            answerText: "Yes",
                                            nextQuestionSequence: 2,
                                        },
                                        {
                                            answerResult: "",
                                            answerText: "No",
                                            nextQuestionSequence: 3,
                                        },
                                    ],
                                },
                                {
                                    questionSequence: 2,
                                    questionText: "Test question 2?",
                                    answers: [
                                        {
                                            answerResult: "123",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "234",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                                {
                                    questionSequence: 3,
                                    questionText: "Test question 3?",
                                    answers: [
                                        {
                                            answerResult: "",
                                            answerText: "Yes",
                                            nextQuestionSequence: 4,
                                        },
                                        {
                                            answerResult: "",
                                            answerText: "No",
                                            nextQuestionSequence: 5,
                                        },
                                    ],
                                },
                                {
                                    questionSequence: 4,
                                    questionText: "Test question 4?",
                                    answers: [
                                        {
                                            answerResult: "567",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "678",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                                {
                                    questionSequence: 5,
                                    questionText: "Test question 5?",
                                    answers: [
                                        {
                                            answerResult: "789",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "890",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                            ],
                        },
                    ];

                    // Act
                    wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);
                    const duplicatedQuestion = wrapper.vm.questionsData[1].questions[2];
                    const duplicatedQuestionAnswer = duplicatedQuestion.answers.filter((a) => {
                        return a.selected;
                    });
                    const answerToTest = wrapper.vm.questionsData[1].questions[0].answers.filter(
                        (a) => {
                            return a.originalNextQuestionSequence;
                        }
                    );

                    // Assert
                    expect(answerToTest[0].originalNextQuestionSequence).toEqual(
                        duplicatedQuestion.questionSequence
                    );
                    expect(answerToTest[0].nextQuestionSequence).toEqual(
                        duplicatedQuestionAnswer[0].nextQuestionSequence
                    );
                });

                describe("and the duplicate was the first question for that part", () => {
                    test("then any questions up to the nextQuestionSequence value should be marked as suppressed", () => {
                        // Arrange
                        const answerNo = {
                            answerResult: "456",
                            answeredQuestions: [
                                {
                                    questionText: "Test duplicate question 1?",
                                    selectedAnswer: "1|nextQuestion|3|No",
                                    selectedAnswerText: "No",
                                    questionNum: 1,
                                },
                            ],
                            index: 0,
                        };
                        const { wrapper } = setupMocks({});

                        wrapper.vm.questionsData = [
                            {
                                glassLocation: "Windshield",
                                glassName: "Single",
                                questions: [
                                    {
                                        questionSequence: 1,
                                        questionText: "Test duplicate question 1?",
                                        answers: [
                                            {
                                                answerResult: "123",
                                                answerText: "Yes",
                                                nextQuestionSequence: null,
                                            },
                                            {
                                                answerResult: "456",
                                                answerText: "No",
                                                nextQuestionSequence: null,
                                            },
                                        ],
                                    },
                                ],
                            },
                            {
                                glassLocation: "Driver",
                                glassName: "Front",
                                questions: [
                                    {
                                        questionSequence: 1,
                                        questionText: "Test duplicate question 1?",
                                        answers: [
                                            {
                                                answerResult: "",
                                                answerText: "Yes",
                                                nextQuestionSequence: 2,
                                            },
                                            {
                                                answerResult: "",
                                                answerText: "No",
                                                nextQuestionSequence: 3,
                                            },
                                        ],
                                    },
                                    {
                                        questionSequence: 2,
                                        questionText: "Test question 2?",
                                        answers: [
                                            {
                                                answerResult: "123",
                                                answerText: "Yes",
                                                nextQuestionSequence: null,
                                            },
                                            {
                                                answerResult: "234",
                                                answerText: "No",
                                                nextQuestionSequence: null,
                                            },
                                        ],
                                    },
                                    {
                                        questionSequence: 3,
                                        questionText: "Test question 3?",
                                        answers: [
                                            {
                                                answerResult: "345",
                                                answerText: "Yes",
                                                nextQuestionSequence: null,
                                            },
                                            {
                                                answerResult: "456",
                                                answerText: "No",
                                                nextQuestionSequence: null,
                                            },
                                        ],
                                    },
                                ],
                            },
                        ];

                        // Act
                        wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);

                        // Assert
                        expect(
                            wrapper.vm.questionsData[1].questions[0].suppressThisQuestion
                        ).toBeTruthy();
                        expect(
                            wrapper.vm.questionsData[1].questions[1].suppressThisQuestion
                        ).toBeTruthy();
                        expect(
                            wrapper.vm.questionsData[1].questions[2].suppressThisQuestion
                        ).toBeFalsy();
                    });
                });
            });

            describe("and the duplicate has an answerResult", () => {
                test("then any questions in the same glass piece that lead to the duplicate should be modified to just provide the duplicate's answerResult", async () => {
                    // Arrange
                    const answerNo = {
                        answerResult: "456",
                        answeredQuestions: [
                            {
                                questionText: "Test question 3?",
                                selectedAnswer: "1|nextQuestion|3|No",
                                selectedAnswerText: "No",
                                questionNum: 1,
                            },
                        ],
                        index: 0,
                    };
                    const { wrapper } = setupMocks({});

                    wrapper.vm.questionsData = [
                        {
                            glassLocation: "Windshield",
                            glassName: "Single",
                            questions: [
                                {
                                    questionSequence: 1,
                                    questionText: "Test question 3?",
                                    answers: [
                                        {
                                            answerResult: "123",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "456",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            glassLocation: "Driver",
                            glassName: "Front",
                            questions: [
                                {
                                    questionSequence: 1,
                                    questionText: "Test question 1?",
                                    answers: [
                                        {
                                            answerResult: "",
                                            answerText: "Yes",
                                            nextQuestionSequence: 2,
                                        },
                                        {
                                            answerResult: "",
                                            answerText: "No",
                                            nextQuestionSequence: 3,
                                        },
                                    ],
                                },
                                {
                                    questionSequence: 2,
                                    questionText: "Test question 2?",
                                    answers: [
                                        {
                                            answerResult: "123",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "234",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                                {
                                    questionSequence: 3,
                                    questionText: "Test question 3?",
                                    answers: [
                                        {
                                            answerResult: "345",
                                            answerText: "Yes",
                                            nextQuestionSequence: null,
                                        },
                                        {
                                            answerResult: "456",
                                            answerText: "No",
                                            nextQuestionSequence: null,
                                        },
                                    ],
                                },
                            ],
                        },
                    ];

                    // Act
                    await wrapper.vm.handleCompletedQuestionChainAnswers(answerNo, "", wrapper.vm);

                    const questionsToTest = wrapper.vm.questionsData[1].questions;
                    const answerLeadingToDuplicate = questionsToTest[0].answers[1];
                    const duplicateQuestion = questionsToTest[2];
                    const answerInDuplicateQuestion = duplicateQuestion.answers.filter((a) => {
                        return a.selected;
                    });

                    // Assert
                    expect(answerLeadingToDuplicate.answerResult).toEqual(
                        answerInDuplicateQuestion[0].answerResult
                    );
                    expect(answerLeadingToDuplicate.originalAnswerResult).toBeFalsy();
                    expect(answerLeadingToDuplicate.nextQuestionSequence).toEqual(null);
                    expect(answerLeadingToDuplicate.originalNextQuestionSequence).toEqual(
                        duplicateQuestion.questionSequence
                    );
                });
            });
        });
    });

    describe("navigateForward", () => {
        describe("should go to parts-questions", () => {
            test("single glass location has part question => go to parts-questions", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                        parts: null,
                        partQuestions: [
                            {
                                questionSequence: 1,
                                questionText:
                                    "Is there a line running across the bottom, driver's side then up the center of the Windshield?",
                                answers: [
                                    {
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01144",
                                    },
                                    {
                                        answerText: "No",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01143",
                                    },
                                ],
                            },
                        ],
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_PART_QUESTIONS,
                    wrapper.vm.$route,
                    {},
                    {},
                    { partsOrQuestions }
                );
            });

            test("multiple glass locations have part questions => go to parts-questions", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                        parts: null,
                        partQuestions: [
                            {
                                questionSequence: 1,
                                questionText:
                                    "Is there a line running across the bottom, driver's side then up the center of the Windshield?",
                                answers: [
                                    {
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01144",
                                    },
                                    {
                                        answerText: "No",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01143",
                                    },
                                ],
                            },
                        ],
                    },
                    {
                        glassName: "Front",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DD08158GTYN",
                                description: "driver side, front",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Quarter",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DQ08162GTYN",
                                description: "driver side, 1 hole",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "SideDoor",
                        glassLocation: "Driver",
                        parts: null,
                        partQuestions: [
                            {
                                questionSequence: 2,
                                questionText: "Is this a super awesome question?",
                                answers: [
                                    {
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01144000",
                                    },
                                    {
                                        answerText: "Super yes",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01143001",
                                    },
                                ],
                            },
                        ],
                    },
                    {
                        glassName: "Stationary",
                        glassLocation: "Rear",
                        parts: [
                            {
                                partNumber: "DB08165GTNN",
                                description: "heated glass, stationary",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_PART_QUESTIONS,
                    wrapper.vm.$route,
                    {},
                    {},
                    { partsOrQuestions }
                );
            });

            test("multiple glass locations selected, one has part question => go to parts-questions", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                        parts: null,
                        partQuestions: [
                            {
                                questionSequence: 1,
                                questionText:
                                    "Is there a line running across the bottom, driver's side then up the center of the Windshield?",
                                answers: [
                                    {
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01144",
                                    },
                                    {
                                        answerText: "No",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01143",
                                    },
                                ],
                            },
                        ],
                    },
                    {
                        glassName: "Front",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DD08158GTYN",
                                description: "driver side, front",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Quarter",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DQ08162GTYN",
                                description: "driver side, 1 hole",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "SideDoor",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DD08160GTYN",
                                description: "driver side, body side, 1 hole",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Stationary",
                        glassLocation: "Rear",
                        parts: [
                            {
                                partNumber: "DB08165GTNN",
                                description: "heated glass, stationary",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_PART_QUESTIONS,
                    wrapper.vm.$route,
                    {},
                    {},
                    { partsOrQuestions }
                );
            });

            test("a selected glass location has part questions and multiple parts => go to parts-questions", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                        parts: null,
                        partQuestions: [
                            {
                                questionSequence: 1,
                                questionText:
                                    "Is there a line running across the bottom, driver's side then up the center of the Windshield?",
                                answers: [
                                    {
                                        answerText: "Yes",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01144",
                                    },
                                    {
                                        answerText: "No",
                                        nextQuestionSequence: null,
                                        answerResult: "DW01143",
                                    },
                                ],
                            },
                        ],
                    },
                    {
                        glassName: "Front",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DD08158GTYN",
                                description: "driver side, front",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Quarter",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DQ08162GTYN",
                                description: "driver side, 1 hole",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DQ08162YPYN",
                                description: "driver side, 1 hole",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "SideDoor",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DD08160GTYN",
                                description: "driver side, body side, 1 hole",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DD08160YPYN",
                                description: "driver side, body side, 1 hole",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Stationary",
                        glassLocation: "Rear",
                        parts: [
                            {
                                partNumber: "DB08165GTNN",
                                description: "heated glass, stationary",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DB08165YPNN",
                                description: "heated glass, stationary",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DB08166GTNN",
                                description: "stationary",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DB08167GTNN",
                                description: "heated glass, movable, 8 hole",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DB08167YPNN",
                                description: "heated glass, movable, 8 hole",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_PART_QUESTIONS,
                    wrapper.vm.$route,
                    {},
                    {},
                    { partsOrQuestions }
                );
            });
        });

        describe("should go to vehicle-parts", () => {
            test("single glass location has multiple parts => go to vehicle-parts", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Stationary",
                        glassLocation: "Rear",
                        parts: [
                            {
                                partNumber: "FB25724GTYN",
                                description: "heated glass, solar, antenna",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "FB25759GTYN",
                                description: "heated glass, solar, antenna, w/diversity antenna",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_MULTIPLE_PARTS_TO_CHOOSE,
                    wrapper.vm.$route,
                    {},
                    {},
                    { partsOrQuestions }
                );
            });

            test("multiple glass locations selected, one of them has multiple parts => go to vehicle parts", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                        parts: [
                            {
                                partNumber: "FW03647GTNN",
                                description: "solar, 3rd visor band",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: [
                                    {
                                        partNumber: "MWF03647",
                                        partType: "MOULDING",
                                        description: "Upper ",
                                    },
                                ],
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Back",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "FD25747GTYN",
                                description: "solar, driver side, rear, ex models and above",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Front",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "FD25719GTYN",
                                description: "solar, driver side, front, ex models and above",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Vent",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "FV25749GTNN",
                                description: "solar, driver side, rear",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Stationary",
                        glassLocation: "Rear",
                        parts: [
                            {
                                partNumber: "FB25724GTYN",
                                description: "heated glass, solar, antenna",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "FB25759GTYN",
                                description: "heated glass, solar, antenna, w/diversity antenna",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_MULTIPLE_PARTS_TO_CHOOSE,
                    wrapper.vm.$route,
                    {},
                    {},
                    { partsOrQuestions }
                );
            });

            test("multiple glass locations selected, multiple have multiple parts => go to vehicle-parts", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                        parts: [
                            {
                                partNumber: "DW02101GTYN",
                                description: "solar",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Back",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DD12202GTYN",
                                description: "solar, driver side, rear",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DD12202YPYN",
                                description: "solar, driver side, rear",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Front",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DD12198GTYN",
                                description: "solar, driver side, front",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DD12200GTYN",
                                description: "solar, driver side, front, laminated, soundproofing",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Quarter",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "DQ12204GTYNOEM",
                                description: "solar, driver side, encap",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DQ12204YPYNOEM",
                                description: "solar, driver side, encap",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DQ12205GTYNOEM",
                                description: "solar, antenna, driver side, encap",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DQ12205YPYNOEM",
                                description: "solar, antenna, driver side, encap",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DQ12207GTYN",
                                description: "solar, driver side, encap, chrome molding",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DQ12207YPYNOEM",
                                description: "solar, driver side, encap, chrome molding",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DQ12208GTYNOEM",
                                description: "solar, antenna, driver side, encap, chrome molding",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DQ12208YPYNOEM",
                                description: "solar, antenna, driver side, encap, chrome molding",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Stationary",
                        glassLocation: "Rear",
                        parts: [
                            {
                                partNumber: "DB12209GTYN",
                                description: "heated glass, solar, 1 hole",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                            {
                                partNumber: "DB12209YPYN",
                                description: "heated glass, solar, 1 hole",
                                color: "Gray Tint Privacy",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_MULTIPLE_PARTS_TO_CHOOSE,
                    wrapper.vm.$route,
                    {},
                    {},
                    { partsOrQuestions }
                );
            });
        });

        describe("should go to molding-questions", () => {
            test("single glass location has child part questions => go to molding-questions", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Stationary",
                        glassLocation: "Rear",
                        parts: [
                            {
                                partNumber: "FB25724GTYN",
                                description: "heated glass, solar, antenna",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                                childPartQuestions: [
                                    {
                                        questionSequence: 1,
                                        questionText:
                                            "Does the rubber seal around your windshield have a chrome strip running through it?",
                                        answers: [
                                            {
                                                answerResult: "WKT D1106 C",
                                                answerText: "Yes",
                                                nextQuestionSequence: null,
                                            },
                                            {
                                                answerResult: "WKT D1106 B",
                                                answerText: "No",
                                                nextQuestionSequence: null,
                                            },
                                        ],
                                    },
                                ],
                            },
                        ],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_MOLDING_QUESTIONS,
                    wrapper.vm.$route,
                    {},
                    {},
                    { partsOrQuestions }
                );
            });
        });

        describe("should go to capability-questions", () => {
            test("single glass location has no child part questions but requiresCapabilityQuestions is true => go to capability-questions", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                        parts: [
                            {
                                partNumber: "FB25724GTYN",
                                description: "heated glass, solar, antenna",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: true,
                                childParts: null,
                                childPartQuestions: null,
                            },
                        ],
                        capabilityQuestions: [],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_CAPABILITY_QUESTIONS,
                    wrapper.vm.$route,
                    {},
                    {},
                    { partsOrQuestions }
                );
            });
        });

        // TODO KO UNSKIP FOR QUOTE MVP
        describe.skip("should go to quote page", () => {
            test("single glass location selected, has no part questions and has one part => go to heritage funnel", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                        parts: [
                            {
                                partNumber: "FW04186GTYN",
                                description: "solar, soundproofing, lane keep assist",
                                color: "Green Tint",
                                requiresRecalibration: true,
                                requiresCapabilityQuestions: false,
                                childParts: [
                                    {
                                        partNumber: "GGG 3563 KIT",
                                        partType: "MOULDING",
                                        description: "Kit, Top & Sides ",
                                    },
                                ],
                            },
                        ],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_NO_MORE_QUESTIONS,
                    { query: { fmgPage: "vin-lookup" } }
                );
                expect(wrapper.vm.$router.navigateWithoutSaving).not.toHaveBeenCalled();
            });

            test("multiple glass locations selected, each has one part and no part questions => go to heritage funnel", async () => {
                // Arrange
                const partsOrQuestions = [
                    {
                        glassName: "Single",
                        glassLocation: "Windshield",
                        parts: [
                            {
                                partNumber: "FW04186GTYN",
                                description: "solar, soundproofing, lane keep assist",
                                color: "Green Tint",
                                requiresRecalibration: true,
                                requiresCapabilityQuestions: false,
                                childParts: [
                                    {
                                        partNumber: "GGG 3563 KIT",
                                        partType: "MOULDING",
                                        description: "Kit, Top & Sides ",
                                    },
                                ],
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Back",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "FD25457GTYN",
                                description: "solar, driver side, rear",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: false,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Front",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "FD27090GTYN",
                                description: "solar, driver side, front",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: false,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Vent",
                        glassLocation: "Driver",
                        parts: [
                            {
                                partNumber: "FV25459GTNN",
                                description: "solar, driver side, rear",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: false,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                    {
                        glassName: "Stationary",
                        glassLocation: "Rear",
                        parts: [
                            {
                                partNumber: "FB25460GTYN",
                                description: "heated glass, solar",
                                color: "Green Tint",
                                requiresRecalibration: false,
                                requiresCapabilityQuestions: false,
                                childParts: null,
                            },
                        ],
                        partQuestions: null,
                    },
                ];

                const { wrapper } = setupMocks({
                    partsOrQuestions: partsOrQuestions,
                });

                wrapper.vm.$store.commit = jest.fn();

                const collectedGlassParts = wrapper.vm.reducedGlassPartsArray(partsOrQuestions);

                // Act
                await wrapper.vm.navigateForward(partsOrQuestions);

                // Assert
                expect(wrapper.vm.$store.commit).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith(
                    storeActions.SAVE_GLASS_PARTS,
                    collectedGlassParts
                );

                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_NO_MORE_QUESTIONS,
                    { query: { fmgPage: "vin-lookup" } }
                );

                expect(wrapper.vm.$router.navigateWithoutSaving).not.toHaveBeenCalled();
            });
        });
    });

    describe("navigateBack", () => {
        // TODO KO
        test.todo(
            "current page is quote, there are no questions, and we don't have their vin => go to estimate"
        );

        test("current page is quote, there are no questions, and we have their vin => go to vin-lookup", async () => {
            // Arrange
            const { wrapper } = setupMocks({ fmgPage: fmgPageValues.QUOTE, hasVin: true });

            // Act
            store.dispatch = jest.fn(() => {});
            await wrapper.vm.navigateBack();

            // Assert
            expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(
                navigationScenarios.CLICKED_BACK_WITH_VIN_AND_NO_MORE_QUESTIONS,
                { query: { fmgPage: fmgPageValues.QUOTE } }
            );
        });

        test("current page is quote and there are capability questions => go to capability questions", async () => {
            // Arrange
            const { wrapper } = setupMocks({ fmgPage: fmgPageValues.QUOTE });
            wrapper.vm.hasCapabilityQuestions = jest.fn().mockReturnValue(true);

            // Act
            store.dispatch = jest.fn(() => {});
            await wrapper.vm.navigateBack();

            // Assert
            expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(
                navigationScenarios.CLICKED_BACK_WITH_CAPABILITY_QUESTIONS,
                { query: { fmgPage: fmgPageValues.QUOTE } }
            );
        });

        test("current page is quote and there are part questions and molding questions => go to molding questions", async () => {
            // Arrange
            const { wrapper } = setupMocks({ fmgPage: fmgPageValues.QUOTE });
            wrapper.vm.hasPartQuestions = jest.fn().mockReturnValue(true);
            wrapper.vm.hasChildPartQuestions = jest.fn().mockReturnValue(true);

            // Act
            await wrapper.vm.navigateBack();

            // Assert
            expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(
                navigationScenarios.CLICKED_BACK_WITH_MOLDING_QUESTIONS,
                { query: { fmgPage: fmgPageValues.QUOTE } }
            );
        });

        test("current page is molding questions and there are part questions, multiple parts to choose, and capability questions => go to vehicle-parts", async () => {
            // Arrange
            const { wrapper } = setupMocks({ fmgPage: fmgPageValues.MOLDING_QUESTIONS });
            wrapper.vm.hasPartQuestions = jest.fn().mockReturnValue(true);
            wrapper.vm.hasGlassLocationWithMultipleParts = jest.fn().mockReturnValue(true);
            wrapper.vm.hasChildPartQuestions = jest.fn().mockReturnValue(true);
            wrapper.vm.hasCapabilityQuestions = jest.fn().mockReturnValue(true);

            // Act
            store.dispatch = jest.fn(() => {});
            await wrapper.vm.navigateBack();

            // Assert
            expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(
                navigationScenarios.CLICKED_BACK_WITH_MULTIPLE_PARTS_TO_CHOOSE,
                { query: { fmgPage: fmgPageValues.MOLDING_QUESTIONS } }
            );
        });

        test("current page is molding questions and there are part questions and capability questions => go to part-questions", async () => {
            // Arrange
            const { wrapper } = setupMocks({ fmgPage: fmgPageValues.MOLDING_QUESTIONS });
            wrapper.vm.hasPartQuestions = jest.fn().mockReturnValue(true);
            wrapper.vm.hasGlassLocationWithMultipleParts = jest.fn().mockReturnValue(false);
            wrapper.vm.hasChildPartQuestions = jest.fn().mockReturnValue(true);
            wrapper.vm.hasCapabilityQuestions = jest.fn().mockReturnValue(true);

            // Act
            store.dispatch = jest.fn(() => {});
            await wrapper.vm.navigateBack();

            // Assert
            expect(wrapper.vm.$router.navigateWithoutSaving).toHaveBeenCalledWith(
                navigationScenarios.CLICKED_BACK_WITH_PART_QUESTIONS,
                { query: { fmgPage: fmgPageValues.MOLDING_QUESTIONS } }
            );
        });
    });
});

function setupMocks({ fmgPage = fmgPageValues.VIN_LOOKUP, hasVin, carId }) {
    const baseMixin = setupMocksForJsFiles({
        actionList: [
            {
                actionName: storeActions.GET_CAPABILITY_QUESTIONS,
                data: [
                    {
                        answers: [
                            {
                                answerResult1: "testing",
                            },
                        ],
                    },
                ],
            },
        ],
    });

    const mocks = getMountOptions({
        router: {
            navigate: jest.fn(),
            navigateWithSaving: jest.fn(),
            navigateWithoutSaving: jest.fn(),
        },
        store: {
            commit: jest.fn(),
            dispatch: jest.fn(),
            getters: {
                ...getters,
                vehicle: {
                    vin: hasVin ? "VIN" : undefined,
                    carId: carId,
                },
            },
        },
        route: {
            query: {
                fmgPage,
            },
        },
    });

    // store.dispatch = jest.fn();

    const mockVehicleQuestionComponent = {
        template: "<div />",
        mixins: [vehicleQuestionsMixin, baseMixin.baseMixin],
    };

    const wrapper = shallowMount(mockVehicleQuestionComponent, mocks);

    return { wrapper };
}
