DigitalConsumer.FixMyGlass/src/helpers/damage-helper.spec.js
2022-11-03 08:22:15 -04:00

99 lines
2.9 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 = [
{ glassLocation: "Windshield", glassName: "windshield" },
{ glassLocation: "Passenger", glassName: "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 = [
{ glassLocation: "Windshield", glassName: "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 = [
{ glassLocation: "Passenger", glassName: "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 = [{ glassLocation: "Rear", glassName: "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 = [
{ glassLocation: "Windshield", glassName: "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 = [
{ glassLocation: "Windshield", glassName: "sideWindow" },
];
const isGlassAvailable = await isGlassAvailableForCarId();
// Assert
expect(isGlassAvailable).toEqual(false);
});
});