Update existing unit tests
This commit is contained in:
parent
2f1eae02b1
commit
6f9519ec1b
1 changed files with 216 additions and 26 deletions
|
|
@ -1,19 +1,210 @@
|
|||
import { shallowMount } from "@vue/test-utils";
|
||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||
import damageReview from "@/layouts/review/review-sections/damage-review/damage-review";
|
||||
|
||||
jest.mock("@/helpers/cms-content-helper", () => ({
|
||||
fetchCmsContentForPage: () => Promise.resolve("content"),
|
||||
}));
|
||||
import damageReview from "@/layouts/review/review-sections/damage-review/damage-review";
|
||||
import { damageLocationsSelected as glassConstants } from "@/constants/damage-locations-selected";
|
||||
|
||||
const testConstants = {
|
||||
cmsConstants: {
|
||||
widgetNames: {
|
||||
header: "DamageReviewWidget",
|
||||
locations: "DamageLocationsWidget",
|
||||
driverDamages: "DriverDamagesWidget",
|
||||
passengerDamages: "PassengerDamagesWidget",
|
||||
},
|
||||
header: {
|
||||
text: "Damage",
|
||||
},
|
||||
damageLocations: {
|
||||
windshield: glassConstants.WINDSHIELD,
|
||||
driver: glassConstants.DRIVER,
|
||||
passenger: glassConstants.PASSENGER,
|
||||
rear: glassConstants.REAR,
|
||||
},
|
||||
damageNames: {
|
||||
vent: glassConstants.VENT,
|
||||
front: glassConstants.FRONT,
|
||||
back: glassConstants.BACK,
|
||||
quarter: glassConstants.QUARTER,
|
||||
side: glassConstants.SIDEDOOR,
|
||||
},
|
||||
locationCopy: {
|
||||
windshield: "Windshield copy",
|
||||
driver: "Driver copy",
|
||||
passenger: "Passenger copy",
|
||||
rear: "Rear copy",
|
||||
},
|
||||
damageCopy: {
|
||||
vent: "Vent copy",
|
||||
front: "Front copy",
|
||||
back: "Back copy",
|
||||
quarter: "Quarter copy",
|
||||
side: "Side copy",
|
||||
},
|
||||
imageId: "00000000-0000-0000-0000-000000000000",
|
||||
},
|
||||
makeBulletedList: (items) => {
|
||||
let list = "<ul>";
|
||||
items.forEach((item) => {
|
||||
list += `<li>${item}</li>`;
|
||||
});
|
||||
list += "</ul>";
|
||||
|
||||
return list;
|
||||
},
|
||||
glassItems: {
|
||||
windshield: {
|
||||
glassLocation: glassConstants.WINDSHIELD,
|
||||
glassName: glassConstants.SINGLE,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let cmsContent;
|
||||
|
||||
describe("Damage Review Block", () => {
|
||||
beforeEach(() => {
|
||||
cmsContent = {
|
||||
DamageReviewWidget: {
|
||||
Text: testConstants.cmsConstants.header.text,
|
||||
},
|
||||
DamageLocationsWidget: {
|
||||
Answers: [
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageLocations.windshield,
|
||||
Text: testConstants.cmsConstants.locationCopy.windshield,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageLocations.driver,
|
||||
Text: testConstants.cmsConstants.locationCopy.driver,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: testConstants.cmsConstants.widgetNames.driverDamages,
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageLocations.passenger,
|
||||
Text: testConstants.cmsConstants.locationCopy.passenger,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: testConstants.cmsConstants.widgetNames.passengerDamages,
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageLocations.rear,
|
||||
Text: testConstants.cmsConstants.locationCopy.rear,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
],
|
||||
},
|
||||
DriverDamagesWidget: {
|
||||
Answers: [
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.vent,
|
||||
Text: testConstants.cmsConstants.damageCopy.vent,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.front,
|
||||
Text: testConstants.cmsConstants.damageCopy.front,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.back,
|
||||
Text: testConstants.cmsConstants.damageCopy.back,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.quarter,
|
||||
Text: testConstants.cmsConstants.damageCopy.quarter,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.side,
|
||||
Text: testConstants.cmsConstants.damageCopy.side,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
],
|
||||
},
|
||||
PassengerDamagesWidget: {
|
||||
Answers: [
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.vent,
|
||||
Text: testConstants.cmsConstants.damageCopy.vent,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.front,
|
||||
Text: testConstants.cmsConstants.damageCopy.front,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.back,
|
||||
Text: testConstants.cmsConstants.damageCopy.back,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.quarter,
|
||||
Text: testConstants.cmsConstants.damageCopy.quarter,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
{
|
||||
Name: testConstants.cmsConstants.damageNames.side,
|
||||
Text: testConstants.cmsConstants.damageCopy.side,
|
||||
SubText: "",
|
||||
ImageId: testConstants.cmsConstants.imageId,
|
||||
Image: "",
|
||||
SubWidgetName: "",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe("Correctly assembles damage info into a display string", () => {
|
||||
test("Basic Replace", async () => {
|
||||
test("Shows windshield copy when windshield damage is included", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({
|
||||
propsData: {
|
||||
cmsWidgetName: testConstants.cmsConstants.widgetNames.header,
|
||||
damageLocationsWidgetName: testConstants.cmsConstants.widgetNames.locations,
|
||||
damage: {
|
||||
isRepair: false,
|
||||
glassToReplace: [testConstants.glassItems.windshield],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
@ -22,16 +213,21 @@ describe("Damage Review Block", () => {
|
|||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.displayContent).toStrictEqual(["Windshield crack"]);
|
||||
expect(wrapper.vm.displayContent).toStrictEqual([
|
||||
testConstants.cmsConstants.locationCopy.windshield,
|
||||
]);
|
||||
});
|
||||
|
||||
test("Basic Repair", async () => {
|
||||
test("Windshield copy is shown when order is a repair", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({
|
||||
propsData: {
|
||||
cmsWidgetName: testConstants.cmsConstants.widgetNames.header,
|
||||
damageLocationsWidgetName: testConstants.cmsConstants.widgetNames.locations,
|
||||
damage: {
|
||||
isRepair: true,
|
||||
numberOfChips: 2,
|
||||
glassToReplace: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
@ -40,25 +236,9 @@ describe("Damage Review Block", () => {
|
|||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.displayContent).toStrictEqual(["Windshield repair - 2 chips"]);
|
||||
});
|
||||
|
||||
test("Basic Repair - no s with 1 chip", async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({
|
||||
propsData: {
|
||||
damage: {
|
||||
isRepair: true,
|
||||
numberOfChips: 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Act
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.displayContent).toStrictEqual(["Windshield repair - 1 chip"]);
|
||||
expect(wrapper.vm.displayContent).toStrictEqual([
|
||||
testConstants.cmsConstants.locationCopy.windshield,
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -66,6 +246,16 @@ describe("Damage Review Block", () => {
|
|||
function setupMocks(customMountOptions) {
|
||||
const mountOptions = getMountOptions(customMountOptions);
|
||||
|
||||
const mockMixin = {
|
||||
methods: {
|
||||
getCmsContent: jest.fn((widgetName, cmsFieldName) => {
|
||||
return cmsContent?.[widgetName]?.[cmsFieldName] ?? "";
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
mountOptions.global.mixins = [mockMixin];
|
||||
|
||||
const wrapper = shallowMount(damageReview, mountOptions);
|
||||
wrapper.vm.setCmsContent = jest.fn();
|
||||
return { wrapper };
|
||||
|
|
|
|||
Loading…
Reference in a new issue