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", () => {
|
describe("license-plate-lookup.vue", () => {
|
||||||
test("Make set, arePagePrerequisitesValid should be true ", () => {
|
test("Vehicle make set, arePagePrerequisitesValid should be true", () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
useMainStore().order.vehicle.carId = "CR00000395";
|
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({
|
function setupMocks({
|
||||||
licensePlateQuestionCmsContent = {},
|
licensePlateQuestionCmsContent = {},
|
||||||
licensePlateQuestionInitialData = {},
|
licensePlateQuestionInitialData = {},
|
||||||
|
|
@ -60,9 +97,8 @@ function setupMocks({
|
||||||
mountOptionsMockData = {},
|
mountOptionsMockData = {},
|
||||||
//Values to set in the state store
|
//Values to set in the state store
|
||||||
carId = null,
|
carId = null,
|
||||||
registrationZipCode = null,
|
registrationZipCode = null, //"55555",
|
||||||
licensePlate = null, //"TESTPLATE",
|
licensePlate = null, //"TESTPLATE",
|
||||||
|
|
||||||
}) {
|
}) {
|
||||||
//Mock api responses
|
//Mock api responses
|
||||||
const apiResponses = {
|
const apiResponses = {
|
||||||
|
|
@ -103,7 +139,7 @@ function setupMocks({
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const apiPromise = Promise.resolve(apiResponses);
|
const apiPromise = Promise.resolve(apiResponses);
|
||||||
|
|
||||||
settleAllPromises.mockImplementation(() => apiPromise);
|
settleAllPromises.mockImplementation(() => apiPromise);
|
||||||
|
|
@ -116,13 +152,19 @@ function setupMocks({
|
||||||
};
|
};
|
||||||
|
|
||||||
const mountOptions = getMountOptions(mountOptionsMockData);
|
const mountOptions = getMountOptions(mountOptionsMockData);
|
||||||
|
|
||||||
const wrapper = shallowMount(licensePlateLookup, mountOptions);
|
const wrapper = shallowMount(licensePlateLookup, mountOptions);
|
||||||
|
|
||||||
const licensePlateQuestionWrapper = wrapper.findComponent({ name: "licensePlateQuestion" });
|
const licensePlateQuestionWrapper = wrapper.findComponent({ name: "licensePlateQuestion" });
|
||||||
licensePlateQuestionWrapper.vm.initializeComponent =
|
licensePlateQuestionWrapper.vm.initializeComponent =
|
||||||
licensePlateQuestion.methods.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 };
|
return { wrapper, apiPromise };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// npm run test:unit src/layouts/license-plate-lookup/license-plate-lookup.spec.js
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<Form @submit="onSubmit" @invalid-submit="onInvalidSubmit">
|
<Form
|
||||||
|
@submit="onSubmit"
|
||||||
|
@invalid-submit="onInvalidSubmit"
|
||||||
|
v-slot="{ meta }">
|
||||||
<div class="page-container-grouped-styles overflow-auto">
|
<div class="page-container-grouped-styles overflow-auto">
|
||||||
<siteHeader cms-widget-name="SiteHeaderWidget" />
|
<siteHeader cms-widget-name="SiteHeaderWidget" />
|
||||||
<vehicleBanner
|
<vehicleBanner
|
||||||
|
|
@ -16,11 +19,11 @@
|
||||||
v-model="registrationZipCode"
|
v-model="registrationZipCode"
|
||||||
class="mt-4" />
|
class="mt-4" />
|
||||||
<siteFooter
|
<siteFooter
|
||||||
|
:isForwardActionDisabled="!meta.valid"
|
||||||
cms-widget-name="SiteFooterWidget"
|
cms-widget-name="SiteFooterWidget"
|
||||||
@back-clicked="backButtonAction"
|
@back-clicked="backButtonAction"
|
||||||
@forward-clicked="forwardButtonAction"
|
@forward-clicked="forwardButtonAction"
|
||||||
ref="siteFooter"
|
ref="siteFooter" />
|
||||||
:is-forward-action-disabled="isForwardActionDisabled" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</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