unit tests, work in progress
This commit is contained in:
parent
349e006b6b
commit
fb8e4db6a9
1 changed files with 49 additions and 61 deletions
|
|
@ -3,29 +3,33 @@ import { settleAllPromises } from "@/helpers/layout-helper.js";
|
|||
import { shallowMount } from "@vue/test-utils";
|
||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||
import { useMainStore } from "@/store";
|
||||
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||
|
||||
jest.mock("@/helpers/damage-helper", () => ({
|
||||
isGlassAvailableForCarId: jest.fn().mockImplementation(() => true),
|
||||
getDamageString: jest.fn(),
|
||||
}));
|
||||
|
||||
|
||||
// Mock fetchCmsContentForPage
|
||||
jest.mock("@/helpers/cms-content-helper", () => ({
|
||||
fetchCmsContentForPage: jest.fn(),
|
||||
doesCopyContainRouterLink: jest.fn(),
|
||||
splitCopyOnCMSPlaceHolder: jest.fn().mockImplementation(() => "test"),
|
||||
getRouterLinkRouteFromCopy: jest.fn(),
|
||||
getRouterLinkDisplayTextFromCopy: jest.fn(),
|
||||
splitCMSCopyOnParagraphTag: jest.fn(),
|
||||
}));
|
||||
|
||||
// Mock our module for promises.
|
||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||
settleAllPromises: jest.fn(),
|
||||
}));
|
||||
|
||||
|
||||
describe("address-vehicles.vue", () => {
|
||||
test("Should navigate to CLICKED_BACK if backButtonAction is run", async () => {
|
||||
// Arrange
|
||||
const mockSelectedVehicleVin = "TESTVIN";
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
await wrapper.setData({
|
||||
selectedVehicle: {
|
||||
vin: mockSelectedVehicleVin
|
||||
},
|
||||
});
|
||||
|
||||
// Act
|
||||
await wrapper.vm.backButtonAction();
|
||||
|
||||
|
|
@ -51,29 +55,37 @@ describe("address-vehicles.vue", () => {
|
|||
// Assert
|
||||
expect(arePagePrerequisitesValid).toBe(true);
|
||||
});
|
||||
|
||||
// test("Should return false for valid page requisites if carId is missing", async () => {
|
||||
// // Arrange
|
||||
// const { wrapper } = setupMocks({});
|
||||
|
||||
// // Act
|
||||
// store.commit(storeMutations.UPDATE_CAR_ID, null);
|
||||
// const result = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
// //Assert
|
||||
// expect(result).toBe(false);
|
||||
|
||||
// wrapper.unmount();
|
||||
// });
|
||||
});
|
||||
|
||||
function setupMocks({
|
||||
lookupVinResponse,
|
||||
partsOrQuestions = [],
|
||||
//partsOrQuestions = [],
|
||||
carId = "C0000",
|
||||
route = null,
|
||||
})
|
||||
{
|
||||
useMainStore().applicationUser = {
|
||||
pageData: {
|
||||
"address-vehicles":
|
||||
[
|
||||
{ vehicle: {
|
||||
carId: "CARID",
|
||||
category: "SUV",
|
||||
imageUrl:
|
||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||
imageVifColor: "white",
|
||||
imageVifNumber: "13769",
|
||||
make: "Hyundai",
|
||||
model: "Santa Fe",
|
||||
style: "4 door utility",
|
||||
year: 2020,
|
||||
|
||||
},
|
||||
vin: "TESTVIN123412341234"
|
||||
},
|
||||
],
|
||||
}
|
||||
};
|
||||
|
||||
const mountOptions = getMountOptions({
|
||||
route: route ? route : undefined,
|
||||
router: {
|
||||
|
|
@ -84,54 +96,30 @@ function setupMocks({
|
|||
vehicle: {
|
||||
carId: carId,
|
||||
category: "SUV",
|
||||
year: 2020,
|
||||
imageUrl:
|
||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||
imageVifColor: "white",
|
||||
imageVifNumber: "13769",
|
||||
make: "Hyundai",
|
||||
model: "Santa Fe",
|
||||
style: "4 door utility",
|
||||
imageUrl:
|
||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
||||
imageVifNumber: "13769",
|
||||
imageVifColor: "white",
|
||||
},
|
||||
year: 2020,
|
||||
},
|
||||
vin: "5NMS3CADXLH233004",
|
||||
},
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
useMainStore().lookupVehicleByVin = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: lookupVinResponse
|
||||
? lookupVinResponse
|
||||
: {
|
||||
carId: "CARID",
|
||||
category: "TESTCAR",
|
||||
year: "0000",
|
||||
make: "TestMake",
|
||||
model: "TestModel",
|
||||
style: "TestStyle",
|
||||
imageUrl: "url",
|
||||
imageVifNumber: "00000",
|
||||
imageVifColor: "color"
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
partsOrQuestions: partsOrQuestions,
|
||||
},
|
||||
})
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
const apiResponses = {
|
||||
vinLookup: {
|
||||
carId: carId,
|
||||
cmsContent: {
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
settleAllPromises.mockImplementation(() => apiResponses);
|
||||
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
|
||||
|
||||
|
||||
//Mock props
|
||||
const mockMixin = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue