DigitalConsumer.FixMyGlass/src/mixins/vehicle-questions-mixin.spec.js

161 lines
No EOL
4.8 KiB
JavaScript

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 };
}