DigitalConsumer.FixMyGlass/src/layouts/confirmation/confirmation.spec.js
hiteshkumar87 eecfa64fe9 formatting code
formatting code
2023-10-04 16:56:30 +05:30

133 lines
3.5 KiB
JavaScript

// Components
import confirmation from "@/layouts/confirmation/confirmation.vue";
// Supporting Files
import { shallowMount } from "@vue/test-utils";
import { nextTick } from "vue";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import store from "@/store";
import router from "@/router";
// Mock our module for promises.
jest.mock("@/helpers/layout-helper.js", () => ({
settleAllPromises: jest.fn(),
}));
beforeEach(() => {
jest.restoreAllMocks();
jest.clearAllMocks();
store.getters = {
order: {
schedule: {
date: "2019-01-01",
startTime: "09:00",
endTime: "10:00",
routeCode: "000",
},
lineItems: {
glassParts: [
{
partNumber: "ABC123",
},
],
supportingItems: [],
},
serviceLocation: {
address: "",
address2: null,
city: "",
state: "AZ",
appointmentType: "Inshop",
zipCode: "12345",
zipCodeCtu: "01234",
provider: {
providerNumber: "123",
address: {
streetAddress: "test1",
city: "test",
state: "AZ",
zipCode: "12345",
zipCodeCtu: "01234",
},
},
},
damage: {
isRepair: false,
},
referralNumber: "1234567",
vehicle: {
year: "2004",
make: "Ford",
model: "F Series F250",
},
customer: {
emailAddress: "test@test.com",
},
},
payment: {
isInsurance: true,
},
lineItems: {
glassParts: [],
supportingItems: [],
},
};
});
afterEach(() => {
store.getters = {};
jest.restoreAllMocks();
jest.clearAllMocks();
});
describe("confirmation.vue", () => {
const realLocation = window.location;
beforeAll(() => {
delete window.location;
window.location = { ...realLocation, assign: jest.fn() };
});
afterAll(() => {
window.location = realLocation;
});
test("arePagePrerequisitesValid should be true ", async () => {
//Arrange
const { wrapper } = setupMocks({});
//Act
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
await nextTick();
//Assert
expect(arePagePrerequisitesValid).toBe(true);
});
test("'Back to safelite.com' button should take user back to safelite.com", async () => {
//Arrange
const { wrapper } = setupMocks({});
//Act
await wrapper.vm.forwardButtonAction();
//Assert
expect(window.location.assign).toHaveBeenCalled();
});
});
const wordingText = "wording Text";
function setupMocks({ customMountOptions }) {
const mountOptions = getMountOptions({
...customMountOptions,
});
mountOptions.mixins = [
{
methods: {
getCmsContent: jest.fn().mockImplementation(() => {
return wordingText;
}),
},
},
];
const wrapper = shallowMount(confirmation, mountOptions);
return { wrapper };
}