unit tests
This commit is contained in:
parent
78fa90a6cf
commit
4d9d1623bf
2 changed files with 51 additions and 48 deletions
|
|
@ -7,22 +7,23 @@ import { useMainStore } from "@/store";
|
|||
jest.mock("@/helpers/damage-helper", () => ({
|
||||
isGlassAvailableForCarId: jest.fn().mockImplementation(() => true),
|
||||
getDamageString: jest.fn(),
|
||||
}));
|
||||
}));
|
||||
|
||||
// Mock our module for promises.
|
||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||
// Mock our module for promises.
|
||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||
settleAllPromises: jest.fn(),
|
||||
}));
|
||||
}));
|
||||
|
||||
// Mock fetchCmsContentForPage
|
||||
jest.mock("@/helpers/cms-content-helper", () => ({
|
||||
// Mock fetchCmsContentForPage
|
||||
jest.mock("@/helpers/cms-content-helper", () => ({
|
||||
fetchCmsContentForPage: jest.fn(),
|
||||
}));
|
||||
}));
|
||||
|
||||
describe("addressVehicles.vue", () => {
|
||||
test("Should navigate to CLICKED_BACK if backButtonAction is run", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
wrapper.vm.$router.navigate = jest.fn();
|
||||
|
||||
// Act
|
||||
|
|
@ -37,30 +38,24 @@ describe("addressVehicles.vue", () => {
|
|||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test("Should return true for valid page requisites if carId exists", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
useMainStore().order.vehicle.carId = "CR00000395";
|
||||
|
||||
// Act
|
||||
addressVehicles.beforeRouteEnter.call(
|
||||
wrapper.vm,
|
||||
{ query: { issPage: "address-vehicles" } },
|
||||
undefined,
|
||||
(c) => c(wrapper.vm)
|
||||
);
|
||||
|
||||
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
|
||||
// test("Should return true for valid page requisites if carId / zipCode / emailAddress / pageData exists", async () => {
|
||||
// // Arrange
|
||||
// const { wrapper } = setupMocks({});
|
||||
// useMainStore().order.vehicle.carId = "CR00000395";
|
||||
// useMainStore().order.serviceLocation.zipCode = "43210";
|
||||
// useMainStore().order.customer.emailAddress = "testemail@email.com";
|
||||
|
||||
// // Act
|
||||
// addressVehicles.beforeRouteEnter.call(
|
||||
// wrapper.vm,
|
||||
// { query: { issPage: "address-vehicles" } },
|
||||
// undefined,
|
||||
// (c) => c(wrapper.vm)
|
||||
// );
|
||||
|
||||
// let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
// // Assert
|
||||
// expect(arePagePrerequisitesValid).toBe(true);
|
||||
// });
|
||||
// Assert
|
||||
expect(arePagePrerequisitesValid).toBe(true);
|
||||
});
|
||||
|
||||
// test("Should return false for valid page requisites if carId is missing", async () => {
|
||||
// // Arrange
|
||||
|
|
@ -77,6 +72,26 @@ describe("addressVehicles.vue", () => {
|
|||
// });
|
||||
});
|
||||
|
||||
//Mock props
|
||||
const mockMixin = {
|
||||
methods: {
|
||||
getCmsContent: jest.fn((contentName) => {
|
||||
if (contentName === "FoundMultipleVehicles") {
|
||||
return "FoundMultipleVehiclesTestReturn";
|
||||
}
|
||||
if (contentName === "ProvideVinAlert") {
|
||||
return "ProvideVinAlertTestReturn";
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
},
|
||||
computed: {
|
||||
dynamicStrings() {
|
||||
return { ROUTER_LINK: "routerLink:" };
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function setupMocks({
|
||||
// isZipValid = true,
|
||||
// isZipServiceable = true,
|
||||
|
|
@ -88,8 +103,6 @@ function setupMocks({
|
|||
vinLookupResponseError = null,
|
||||
route = null,
|
||||
carId = "C0000",
|
||||
zipCode = "12345",
|
||||
emailAddress = "test@test.com"
|
||||
}) {
|
||||
// useMainStore().validateZip = jest.fn().mockImplementation(() => {
|
||||
// return Promise.resolve({
|
||||
|
|
@ -132,19 +145,9 @@ function setupMocks({
|
|||
vehicle: {
|
||||
carId: carId,
|
||||
},
|
||||
serviceLocation: {
|
||||
zipCode: zipCode,
|
||||
},
|
||||
customer: {
|
||||
emailAddress: emailAddress,
|
||||
}
|
||||
},
|
||||
applicationUser: {
|
||||
pageData: "address-vehicles",
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
mixins: [mockMixin],
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -112,6 +112,11 @@ export default {
|
|||
props: {
|
||||
validationRules: String,
|
||||
},
|
||||
setup() {
|
||||
const mainStore = useMainStore();
|
||||
|
||||
return { mainStore };
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
selectedVehicleVin: "",
|
||||
|
|
@ -167,13 +172,8 @@ export default {
|
|||
getRouterLinkRouteFromCopy,
|
||||
getRouterLinkDisplayTextFromCopy,
|
||||
arePagePrerequisitesValid() {
|
||||
if (
|
||||
useMainStore().order.vehicle.carId &&
|
||||
useMainStore().order.serviceLocation.zipCode &&
|
||||
useMainStore().order.customer.emailAddress &&
|
||||
useMainStore().getters.pageData(issPageValues.ADDRESS_VEHICLES)
|
||||
) {
|
||||
return true;
|
||||
if (this.mainStore.order.vehicle.carId) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue