DigitalConsumer.FixMyGlass/src/helpers/damage-helper.spec.js

91 lines
2.6 KiB
JavaScript

import {getDamageString, isGlassAvailableForCarId} from "./damage-helper";
import store from "@/store";
// Mock basemixin.
jest.mock("@/mixins/base-mixin.js", () => ({
methods: {
dispatchStoreAction: jest.fn().mockImplementation(() => { return {
data: {
windshieldOptions: {availableReplacementOptions: ["windshield"]}
}
} }),
},
}));
describe("damage-helper.js", () => {
it("Should return match when multiple selected damage options are in the store", () => {
// Arrange / Act
store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}, {location: "Passenger", name: "sideWindow"}];
const damage = getDamageString();
// Assert
expect(damage).toEqual("match");
});
});
describe("damage-helper.js", () => {
it("Should return windshield when Windshield is the only selected damage option in the store", () => {
// Arrange / Act
store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}];
const damage = getDamageString();
// Assert
expect(damage).toEqual("windshield");
});
});
describe("damage-helper.js", () => {
it("Should return side window when Driver or Passenger is the only selected damage option in the store", () => {
// Arrange / Act
store.getters.damage.glassToReplace = [{location: "Passenger", name: "sideWindow"}];
const damage = getDamageString();
// Assert
expect(damage).toEqual("side window");
});
});
describe("damage-helper.js", () => {
it("Should return rear window when Rear is the only selected damage option in the store", () => {
// Arrange / Act
store.getters.damage.glassToReplace = [{location: "Rear", name: "rear"}];
const damage = getDamageString();
// Assert
expect(damage).toEqual("rear window");
});
});
describe("damage-helper.js", () => {
it("Should return true if no mismatches between each array exist", async () => {
// Arrange
store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}];
// Act
const isGlassAvailable = await isGlassAvailableForCarId();
// Assert
expect(isGlassAvailable).toEqual(true);
});
});
describe("damage-helper.js", () => {
it("Should return false if any mismatches between each array exist", async () => {
// Arrange
store.getters.damage.glassToReplace = [{location: "Windshield", name: "sideWindow"}];
const isGlassAvailable = await isGlassAvailableForCarId();
// Assert
expect(isGlassAvailable).toEqual(false);
});
});