diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index ff5f494c1..6f18408b7 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -88,7 +88,7 @@ export default { data() { return { selectedModel: [], - partsQuestionsData: store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions.filter((p) => { + partsQuestionsData: this.$store.getters.pageData(fmgPageValues.PART_QUESTIONS)?.partsOrQuestions.filter((p) => { if (Array.isArray(p.partQuestions) && p.partQuestions.length > 0) { return { glassName: p.glassName, diff --git a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue index b46a2f9bc..608cf55cb 100644 --- a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue +++ b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue @@ -48,7 +48,6 @@ import { getCustomTransformValue } from "@/constants/dynamictext-mapper"; import { defineRule } from "vee-validate"; import { required } from "@/helpers/validation-rules"; import { errorMessages } from "@/constants/error-messages"; -import store from "@/store"; export default { name: "glass-part-question", @@ -153,7 +152,7 @@ export default { }, PartDataFromApi() { - return store.getters.pageData(this.$route.query.fmgPage) ?? {}; + return this.$store.getters.pageData(this.$route.query.fmgPage) ?? {}; }, }, methods: { diff --git a/src/mixins/vehicle-questions-mixin.spec.js b/src/mixins/vehicle-questions-mixin.spec.js index e69de29bb..01d41b9c8 100644 --- a/src/mixins/vehicle-questions-mixin.spec.js +++ b/src/mixins/vehicle-questions-mixin.spec.js @@ -0,0 +1,161 @@ +import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; +import { shallowMount } from "@vue/test-utils"; +import { setupMocksForJsFiles, getMountOptions } from "@/helpers/unit-test-helper.js"; + +describe("vehicle-questions-mixin", () => { + 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); + }); + }); +}); + +function setupMocks({}) { + const baseMixin = setupMocksForJsFiles({}); + + const mocks = getMountOptions({ + router: { + navigate: jest.fn() + }, + }); + + const mockVehicleQuestionComponent = { + template: '
', + mixins: [vehicleQuestionsMixin, baseMixin.baseMixin] + }; + + const wrapper = shallowMount(mockVehicleQuestionComponent, mocks); + + return { wrapper }; +} \ No newline at end of file