first unit test - back button navigates
This commit is contained in:
parent
a27e5c4c06
commit
662b6944c4
1 changed files with 133 additions and 0 deletions
133
src/layouts/license-plate-lookup/license-plate-lookup.spec.js
Normal file
133
src/layouts/license-plate-lookup/license-plate-lookup.spec.js
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
// Components
|
||||||
|
import licensePlateLookup from "@/layouts/license-plate-lookup/license-plate-lookup.vue";
|
||||||
|
import licensePlateQuestion from "@/layouts/license-plate-lookup/license-plate-question/license-plate-question.vue";
|
||||||
|
|
||||||
|
// Supporting files
|
||||||
|
import { shallowMount } from '@vue/test-utils';
|
||||||
|
import { settleAllPromises } from "@/helpers/layout-helper.js";
|
||||||
|
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||||
|
import baseMixin from "@/mixins/base-mixin.js";
|
||||||
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
|
import { nextTick } from "vue";
|
||||||
|
import { useMainStore } from "@/store";
|
||||||
|
|
||||||
|
// Mock our module for promises.
|
||||||
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||||
|
settleAllPromises: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock fetchCmsContentForPage
|
||||||
|
jest.mock("@/helpers/cms-content-helper", () => ({
|
||||||
|
fetchCmsContentForPage: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock damage helper
|
||||||
|
jest.mock("@/helpers/damage-helper", () => ({
|
||||||
|
isGlassAvailableForCarId: () => {
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
getDamageString: () => {
|
||||||
|
return "damage string";
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("license-plate-lookup.vue", () => {
|
||||||
|
describe("navigation", () => {
|
||||||
|
test("backButtonAction triggers a router.navigate change", async () => {
|
||||||
|
//Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
licensePlateLookup.beforeRouteEnter.call(
|
||||||
|
wrapper.vm,
|
||||||
|
{ query: { issPage: "license-plate-lookup" } },
|
||||||
|
undefined,
|
||||||
|
(c) => c(wrapper.vm)
|
||||||
|
);
|
||||||
|
|
||||||
|
wrapper.vm.backButtonAction();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Test - Continue button should call forwardButtonAction when data entered matches data from store
|
||||||
|
|
||||||
|
// TODO: Test - Methods to get values from the store (license plate, registration zip)
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function setupMocks({
|
||||||
|
licensePlateQuestionCmsContent = {},
|
||||||
|
licensePlateQuestionInitialData = {},
|
||||||
|
pageHeaderWidgetHeaderText = {},
|
||||||
|
mountOptionsMockData = {},
|
||||||
|
partsOrQuestions = [],
|
||||||
|
//Values to set in the state store
|
||||||
|
carId = null,
|
||||||
|
registrationZipCode = null,
|
||||||
|
licensePlate = null, //"TESTPLATE",
|
||||||
|
emailAddress = null, //"test@test.com",
|
||||||
|
}) {
|
||||||
|
//Mock api responses
|
||||||
|
const apiResponses = {
|
||||||
|
cmsContent: {
|
||||||
|
SiteSubHeaderWidget: pageHeaderWidgetHeaderText,
|
||||||
|
LicensePlateQuestion: licensePlateQuestionCmsContent,
|
||||||
|
VehicleBannerWidget: {
|
||||||
|
GenericVehicleImage:
|
||||||
|
"https://digitalisscms.dev.safelite.io/images/default-source/default-album/blurred-image.jpg",
|
||||||
|
},
|
||||||
|
SiteHeaderWidget: {
|
||||||
|
LogoImage:
|
||||||
|
"https://digitalisscms.dev.safelite.io/images/default-source/default-album/logos/insuranceLogo.jpg",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
licensePlateQuestionInitialData: licensePlateQuestionInitialData,
|
||||||
|
};
|
||||||
|
|
||||||
|
mountOptionsMockData = {
|
||||||
|
...mountOptionsMockData,
|
||||||
|
router: {
|
||||||
|
navigate: jest.fn(),
|
||||||
|
navigateWithoutSaving: jest.fn(),
|
||||||
|
navigateWithSaving: jest.fn(),
|
||||||
|
},
|
||||||
|
store: {
|
||||||
|
getters: {
|
||||||
|
vehicle: {
|
||||||
|
registration: {
|
||||||
|
licensePlate: licensePlate,
|
||||||
|
zipCode: registrationZipCode,
|
||||||
|
},
|
||||||
|
carId: carId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const apiPromise = Promise.resolve(apiResponses);
|
||||||
|
|
||||||
|
settleAllPromises.mockImplementation(() => apiPromise);
|
||||||
|
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
|
||||||
|
|
||||||
|
//Mock make question methods
|
||||||
|
licensePlateQuestion.methods = {
|
||||||
|
loadInitialData: jest.fn(),
|
||||||
|
initializeComponent: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const mountOptions = getMountOptions(mountOptionsMockData);
|
||||||
|
const wrapper = shallowMount(licensePlateLookup, mountOptions);
|
||||||
|
|
||||||
|
const licensePlateQuestionWrapper = wrapper.findComponent({ name: "licensePlateQuestion" });
|
||||||
|
licensePlateQuestionWrapper.vm.initializeComponent =
|
||||||
|
licensePlateQuestion.methods.initializeComponent;
|
||||||
|
|
||||||
|
wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent;
|
||||||
|
|
||||||
|
return { wrapper, apiPromise };
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue