CSR-702 Add vehicle-questions-mixin tests
This commit is contained in:
parent
7e5fb4c906
commit
18524de9a6
3 changed files with 163 additions and 3 deletions
|
|
@ -88,7 +88,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectedModel: [],
|
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) {
|
if (Array.isArray(p.partQuestions) && p.partQuestions.length > 0) {
|
||||||
return {
|
return {
|
||||||
glassName: p.glassName,
|
glassName: p.glassName,
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ import { getCustomTransformValue } from "@/constants/dynamictext-mapper";
|
||||||
import { defineRule } from "vee-validate";
|
import { defineRule } from "vee-validate";
|
||||||
import { required } from "@/helpers/validation-rules";
|
import { required } from "@/helpers/validation-rules";
|
||||||
import { errorMessages } from "@/constants/error-messages";
|
import { errorMessages } from "@/constants/error-messages";
|
||||||
import store from "@/store";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "glass-part-question",
|
name: "glass-part-question",
|
||||||
|
|
@ -153,7 +152,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
PartDataFromApi() {
|
PartDataFromApi() {
|
||||||
return store.getters.pageData(this.$route.query.fmgPage) ?? {};
|
return this.$store.getters.pageData(this.$route.query.fmgPage) ?? {};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
||||||
|
|
@ -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: '<div></div>',
|
||||||
|
mixins: [vehicleQuestionsMixin, baseMixin.baseMixin]
|
||||||
|
};
|
||||||
|
|
||||||
|
const wrapper = shallowMount(mockVehicleQuestionComponent, mocks);
|
||||||
|
|
||||||
|
return { wrapper };
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue