unit tests for license-plate-lookup
This commit is contained in:
parent
97412df60b
commit
83df3b71c9
4 changed files with 61 additions and 10 deletions
|
|
@ -32,7 +32,7 @@ jest.mock("@/helpers/damage-helper", () => ({
|
|||
}));
|
||||
|
||||
describe("license-plate-lookup.vue", () => {
|
||||
test("Make set, arePagePrerequisitesValid should be true ", () => {
|
||||
test("Vehicle make set, arePagePrerequisitesValid should be true", () => {
|
||||
//Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
useMainStore().order.vehicle.carId = "CR00000395";
|
||||
|
|
@ -52,6 +52,43 @@ describe("license-plate-lookup.vue", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("navigation", () => {
|
||||
test("BackButtonAction triggers a router.navigate change", async () => {
|
||||
//Arrange
|
||||
const { wrapper, apiPromise } = setupMocks({
|
||||
mountOptionsMockData: {
|
||||
router: {
|
||||
navigate: jest.fn(),
|
||||
},
|
||||
},
|
||||
});
|
||||
//Act
|
||||
licensePlateLookup.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { issPage: "license-plate-lookup" } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
wrapper.vm.backButtonAction();
|
||||
await nextTick();
|
||||
|
||||
//Assert
|
||||
return apiPromise.finally(() => {
|
||||
try {
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||
}
|
||||
catch (e) {
|
||||
throw e
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Create test for navigating forward when user clicks Continue
|
||||
// and information entered is correct (no alerts)
|
||||
// Will be implemented once navigation from page is complete
|
||||
|
||||
});
|
||||
|
||||
function setupMocks({
|
||||
licensePlateQuestionCmsContent = {},
|
||||
licensePlateQuestionInitialData = {},
|
||||
|
|
@ -60,9 +97,8 @@ function setupMocks({
|
|||
mountOptionsMockData = {},
|
||||
//Values to set in the state store
|
||||
carId = null,
|
||||
registrationZipCode = null,
|
||||
registrationZipCode = null, //"55555",
|
||||
licensePlate = null, //"TESTPLATE",
|
||||
|
||||
}) {
|
||||
//Mock api responses
|
||||
const apiResponses = {
|
||||
|
|
@ -103,7 +139,7 @@ function setupMocks({
|
|||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
const apiPromise = Promise.resolve(apiResponses);
|
||||
|
||||
settleAllPromises.mockImplementation(() => apiPromise);
|
||||
|
|
@ -116,13 +152,19 @@ function setupMocks({
|
|||
};
|
||||
|
||||
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;
|
||||
|
||||
wrapper.vm.setCmsContent = jest.fn();
|
||||
wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => "");
|
||||
wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn();
|
||||
|
||||
return { wrapper, apiPromise };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// npm run test:unit src/layouts/license-plate-lookup/license-plate-lookup.spec.js
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
<template>
|
||||
<Form @submit="onSubmit" @invalid-submit="onInvalidSubmit">
|
||||
<Form
|
||||
@submit="onSubmit"
|
||||
@invalid-submit="onInvalidSubmit"
|
||||
v-slot="{ meta }">
|
||||
<div class="page-container-grouped-styles overflow-auto">
|
||||
<siteHeader cms-widget-name="SiteHeaderWidget" />
|
||||
<vehicleBanner
|
||||
|
|
@ -16,11 +19,11 @@
|
|||
v-model="registrationZipCode"
|
||||
class="mt-4" />
|
||||
<siteFooter
|
||||
:isForwardActionDisabled="!meta.valid"
|
||||
cms-widget-name="SiteFooterWidget"
|
||||
@back-clicked="backButtonAction"
|
||||
@forward-clicked="forwardButtonAction"
|
||||
ref="siteFooter"
|
||||
:is-forward-action-disabled="isForwardActionDisabled" />
|
||||
ref="siteFooter" />
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
// TODO: Create test for component emitting value when user clicks Continue
|
||||
// and information entered is correct (no alerts)
|
||||
// Will be implemented once navigation from page is complete
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// TODO: Create test for component emitting value when user clicks Continue
|
||||
// and information entered is correct (no alerts)
|
||||
// Will be implemented once navigation from page is complete
|
||||
Loading…
Reference in a new issue