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 { shallowMount } from "@vue/test-utils";
|
||||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
import { useMainStore } from "@/store";
|
import { useMainStore } from "@/store";
|
||||||
|
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
||||||
|
|
||||||
jest.mock("@/helpers/damage-helper", () => ({
|
jest.mock("@/helpers/damage-helper", () => ({
|
||||||
isGlassAvailableForCarId: jest.fn().mockImplementation(() => true),
|
isGlassAvailableForCarId: jest.fn().mockImplementation(() => true),
|
||||||
getDamageString: jest.fn(),
|
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.
|
// Mock our module for promises.
|
||||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||||
settleAllPromises: jest.fn(),
|
settleAllPromises: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("address-vehicles.vue", () => {
|
describe("address-vehicles.vue", () => {
|
||||||
test("Should navigate to CLICKED_BACK if backButtonAction is run", async () => {
|
test("Should navigate to CLICKED_BACK if backButtonAction is run", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const mockSelectedVehicleVin = "TESTVIN";
|
|
||||||
const { wrapper } = setupMocks({});
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
await wrapper.setData({
|
|
||||||
selectedVehicle: {
|
|
||||||
vin: mockSelectedVehicleVin
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await wrapper.vm.backButtonAction();
|
await wrapper.vm.backButtonAction();
|
||||||
|
|
||||||
|
|
@ -51,29 +55,37 @@ describe("address-vehicles.vue", () => {
|
||||||
// Assert
|
// Assert
|
||||||
expect(arePagePrerequisitesValid).toBe(true);
|
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({
|
function setupMocks({
|
||||||
lookupVinResponse,
|
//partsOrQuestions = [],
|
||||||
partsOrQuestions = [],
|
|
||||||
carId = "C0000",
|
carId = "C0000",
|
||||||
route = null,
|
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({
|
const mountOptions = getMountOptions({
|
||||||
route: route ? route : undefined,
|
route: route ? route : undefined,
|
||||||
router: {
|
router: {
|
||||||
|
|
@ -84,54 +96,30 @@ function setupMocks({
|
||||||
vehicle: {
|
vehicle: {
|
||||||
carId: carId,
|
carId: carId,
|
||||||
category: "SUV",
|
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",
|
make: "Hyundai",
|
||||||
model: "Santa Fe",
|
model: "Santa Fe",
|
||||||
style: "4 door utility",
|
style: "4 door utility",
|
||||||
imageUrl:
|
year: 2020,
|
||||||
"https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg",
|
},
|
||||||
imageVifNumber: "13769",
|
|
||||||
imageVifColor: "white",
|
|
||||||
},
|
|
||||||
vin: "5NMS3CADXLH233004",
|
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 = {
|
const apiResponses = {
|
||||||
vinLookup: {
|
cmsContent: {
|
||||||
carId: carId,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
settleAllPromises.mockImplementation(() => apiResponses);
|
settleAllPromises.mockImplementation(() => apiResponses);
|
||||||
|
fetchCmsContentForPage.mockImplementation(() => Promise.resolve());
|
||||||
|
|
||||||
|
|
||||||
//Mock props
|
//Mock props
|
||||||
const mockMixin = {
|
const mockMixin = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue