unit test for military zip alert

This commit is contained in:
Kroell 2023-04-24 13:25:05 -04:00
parent 63418c003b
commit c6967028e3

View file

@ -1,6 +1,34 @@
import { shallowMount } from "@vue/test-utils";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import serviceLocation from "@/layouts/service-location/service-location.vue";
import { getServiceabilityDetails, getZipCodeData } from "@/helpers/service-location-helper";
// Define Mocks
jest.mock("@/helpers/cms-content-helper", () => ({
fetchCmsContentForPage: jest.fn(() => {
return Promise.resolve("content");
}),
}));
const mockGetServiceabilityDetails = (mockServiceZipCode) => {
const serviceabilityDetails = {
isGlassServiceableInshop: true,
isRecalibrationServiceableInshop: true,
isGlassServiceableMobile: true,
isRecalibrationServiceableMobile: true,
};
return Promise.resolve(serviceabilityDetails);
};
jest.mock(
"@/helpers/service-location-helper",
() => ({
getServiceabilityDetails: jest.fn((mockServiceZipCode) => {
return mockGetServiceabilityDetails(mockServiceZipCode);
}),
})
);
const mockMixin = {
methods: {
@ -26,6 +54,14 @@ const mockMixin = {
});
}
if (zip === "45433") {
return Promise.resolve({
containsMilitaryBase: true,
isValid: true,
state: "OH",
});
}
return Promise.resolve({
containsMilitaryBase: false,
isValid: false,
@ -98,6 +134,34 @@ describe("updating service zip", () => {
// Assert
expect(wrapper.vm.selectedAppointmentType).toStrictEqual(null);
});
test("displays military zip message when zip is updated", () => {
// Arrange
const { wrapper } = setupMocks({});
const mobileLocationQuestionsComponent = wrapper.findComponent({
ref: "mobileLocationQuestions",
});
mobileLocationQuestionsComponent.resetComponent = jest.fn();
const serviceZipCodeComponent = wrapper.findComponent({
ref: "serviceZipCodeQuestion",
});
serviceZipCodeComponent.resetMobileFeePart = jest.fn();
expect(wrapper.vm.zipContainsMilitaryBase).toBe(false);
const newServiceZipCodeQuestion = {
zipCode: "45433",
state: "OH",
};
// Act
serviceZipCodeComponent.vm.$emit("updated-contains-military-base", true);
// Assert
expect(wrapper.vm.zipContainsMilitaryBase).toBe(true);
});
});
function setupMocks()