CSR-78 jest test coverage
This commit is contained in:
parent
4132ac93b7
commit
6328bbf5fe
5 changed files with 128 additions and 26 deletions
|
|
@ -1,9 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="current_car_info-text">
|
<div class="current_car_info-text">
|
||||||
<div
|
<div class="d-flex align-items-center justify-content-center container-fluid overflow-hidden">
|
||||||
class="d-flex align-items-center justify-content-center container-fluid overflow-hidden"
|
<h5 class="text-center fw-normal mb-0" :class="hasSubText ? 'dark-header' : 'light-header'">
|
||||||
>
|
|
||||||
<h5 class="text-center fw-normal mb-0">
|
|
||||||
<span>
|
<span>
|
||||||
{{ text }}
|
{{ text }}
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -14,9 +12,7 @@
|
||||||
/>
|
/>
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div class="d-flex align-items-center justify-content-center container-fluid overflow-hidden">
|
||||||
class="d-flex align-items-center justify-content-center container-fluid overflow-hidden"
|
|
||||||
>
|
|
||||||
<p class="text-center small fw-normal mb-0">
|
<p class="text-center small fw-normal mb-0">
|
||||||
<span>
|
<span>
|
||||||
{{ subText }}
|
{{ subText }}
|
||||||
|
|
@ -40,6 +36,7 @@ export default {
|
||||||
props: {
|
props: {
|
||||||
hasBackButton: Boolean,
|
hasBackButton: Boolean,
|
||||||
backButtonAccessibleText: String,
|
backButtonAccessibleText: String,
|
||||||
|
hasSubText: Boolean
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
buttonBack,
|
buttonBack,
|
||||||
|
|
@ -58,11 +55,22 @@ export default {
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
h5 {
|
h5 {
|
||||||
color: $gray-550;
|
|
||||||
line-height: 32px;
|
line-height: 32px;
|
||||||
|
|
||||||
button {
|
button {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dark-header {
|
||||||
|
color: $black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.light-header {
|
||||||
|
color: $gray-550;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.small {
|
||||||
|
color: $gray-550
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,120 @@
|
||||||
import { shallowMount } from "@vue/test-utils";
|
import { shallowMount } from "@vue/test-utils";
|
||||||
import vehicleBanner from "./vehicle-banner";
|
import vehicleBanner from "./vehicle-banner";
|
||||||
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||||
|
import store from "@/store";
|
||||||
|
import { vehicleCategories } from "@/constants/vehicle-categories.js";
|
||||||
|
|
||||||
|
jest.mock(
|
||||||
|
"@/store",
|
||||||
|
() => {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
{ virtual: true }
|
||||||
|
);
|
||||||
|
|
||||||
describe("vehicleBanner", () => {
|
describe("vehicleBanner", () => {
|
||||||
test("renders the blurrycar image", async () => {
|
test("renders the blurrycar image", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
const { wrapper, cmsContent } = setupMocks({ displayGenericVehicleImageProp: true, imageUrlValue: "NULL" });
|
||||||
|
|
||||||
// Act
|
//Act
|
||||||
const wrapper = shallowMount(vehicleBanner);
|
|
||||||
await wrapper.setData({
|
|
||||||
vehicleImageSrc: "image_url",
|
|
||||||
});
|
|
||||||
wrapper.vm.initializeComponent(cmsContent);
|
wrapper.vm.initializeComponent(cmsContent);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.find("img").attributes("class")).toContain("blurrycar");
|
expect(wrapper.vm.vehicleImageToDisplay).toEqual( "image_url");
|
||||||
|
expect(wrapper.find("img").attributes("class")).toContain("vehicle-image");
|
||||||
wrapper.unmount();
|
wrapper.unmount();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//Mock CMS content
|
describe("vehicleBanner", () => {
|
||||||
const cmsContent = {
|
test("renders expected vehicle image", async () => {
|
||||||
GenericVehicleImage: "image_url",
|
// Arrange
|
||||||
};
|
const { wrapper, cmsContent } = setupMocks({ displayGenericVehicleImageProp: false, imageUrlValue: "url_to_vehicle_image" });
|
||||||
|
|
||||||
|
//Act
|
||||||
|
wrapper.vm.initializeComponent(cmsContent);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.vehicleImageToDisplay).toEqual( "url_to_vehicle_image");
|
||||||
|
expect(wrapper.find("img").attributes("class")).toContain("vehicle-image");
|
||||||
|
wrapper.unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("vehicleBanner", () => {
|
||||||
|
test("should render car icon when imageUrl is null and category is default", async () => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper, cmsContent } = setupMocks({ displayGenericVehicleImageProp: false, imageUrlValue: "NULL" });
|
||||||
|
|
||||||
|
//Act
|
||||||
|
wrapper.vm.initializeComponent(cmsContent);
|
||||||
|
var iconUrl = wrapper.vm.vehicleImageToDisplay;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(iconUrl).toEqual( "car_icon_url");
|
||||||
|
wrapper.unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const params = [["CAR", "car_icon_url"],
|
||||||
|
["TRUCK", "truck_icon_url"],
|
||||||
|
["VAN", "van_icon_url"],
|
||||||
|
["COMMERCIAL VAN", "commercial_van_icon_url"],
|
||||||
|
["SUV", "suv_icon_url"],
|
||||||
|
["OTHER", "car_icon_url"]];
|
||||||
|
|
||||||
|
describe("vehicleBanner", () => {
|
||||||
|
test.each(params)("renders an icon instead of an image for %s and %s", async (category, expectedIcon) => {
|
||||||
|
// Arrange
|
||||||
|
const { wrapper, cmsContent } = setupMocks({ displayGenericVehicleImageProp: false, imageUrlValue: expectedIcon, categoryValue: category });
|
||||||
|
|
||||||
|
//Act
|
||||||
|
wrapper.vm.initializeComponent(cmsContent);
|
||||||
|
var vehicleIcon = wrapper.vm.getUnmatchedVehicleIcon();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.carUnmatchedVehicleIcon).toEqual(cmsContent.CarUnmatchedVehicleIcon);
|
||||||
|
expect(wrapper.vm.truckUnmatchedVehicleIcon).toEqual(cmsContent.TruckUnmatchedVehicleIcon);
|
||||||
|
expect(wrapper.vm.vanUnmatchedVehicleIcon).toEqual(cmsContent.VanUnmatchedVehicleIcon);
|
||||||
|
expect(wrapper.vm.commercialUnmatchedVehicleIcon).toEqual(cmsContent.CommercialVanUnmatchedVehicleIcon);
|
||||||
|
expect(wrapper.vm.suvUnmatchedVehicleIcon).toEqual(cmsContent.SuvUnmatchedVehicleIcon);
|
||||||
|
|
||||||
|
expect(store.getters.vehicle.category).toEqual(category);
|
||||||
|
expect(wrapper.vm.vehicleImageToDisplay).toEqual(vehicleIcon);
|
||||||
|
expect(wrapper.find("img").attributes("class")).toContain("vehicle-image");
|
||||||
|
wrapper.unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function setupMocks({
|
||||||
|
displayGenericVehicleImageProp,
|
||||||
|
imageUrlValue,
|
||||||
|
categoryValue = "CAR"
|
||||||
|
}) {
|
||||||
|
//Mock store
|
||||||
|
store.dispatch = jest.fn(() => dataFromStoreApi);
|
||||||
|
store.getters = { vehicle: { category: categoryValue, imageUrl: imageUrlValue } };
|
||||||
|
const mountOptions = getMountOptions({
|
||||||
|
store: {
|
||||||
|
dispatch: store.dispatch,
|
||||||
|
getters: store.getters,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
//Mock props
|
||||||
|
mountOptions.propsData = { displayGenericVehicleImage: displayGenericVehicleImageProp };
|
||||||
|
|
||||||
|
const wrapper = shallowMount(vehicleBanner, mountOptions);
|
||||||
|
|
||||||
|
//Mock CMS content
|
||||||
|
const cmsContent = {
|
||||||
|
GenericVehicleImage: "image_url",
|
||||||
|
CarUnmatchedVehicleIcon: "car_icon_url",
|
||||||
|
TruckUnmatchedVehicleIcon: "truck_icon_url",
|
||||||
|
VanUnmatchedVehicleIcon: "van_icon_url",
|
||||||
|
CommercialVanUnmatchedVehicleIcon: "commercial_van_icon_url",
|
||||||
|
SuvUnmatchedVehicleIcon: "suv_icon_url",
|
||||||
|
};
|
||||||
|
return { wrapper, cmsContent };
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="vehicle_banner mb-3 text-center">
|
<div class="vehicle_banner mb-3 text-center">
|
||||||
<img
|
<img
|
||||||
class="vehicle-image img-fluid blurrycar"
|
class="vehicle-image img-fluid"
|
||||||
:src="vehicleImageToDisplay"
|
:src="vehicleImageToDisplay"
|
||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
|
|
@ -50,7 +50,7 @@ export default {
|
||||||
this.commercialUnmatchedVehicleIcon = cmsContent.CommercialVanUnmatchedVehicleIcon;
|
this.commercialUnmatchedVehicleIcon = cmsContent.CommercialVanUnmatchedVehicleIcon;
|
||||||
this.suvUnmatchedVehicleIcon = cmsContent.SuvUnmatchedVehicleIcon;
|
this.suvUnmatchedVehicleIcon = cmsContent.SuvUnmatchedVehicleIcon;
|
||||||
},
|
},
|
||||||
getUnmatchedVehicleIcon: function(){
|
getUnmatchedVehicleIcon(){
|
||||||
switch(this.$store.getters.vehicle.category){
|
switch(this.$store.getters.vehicle.category){
|
||||||
case this.vehicleCategories.CAR:
|
case this.vehicleCategories.CAR:
|
||||||
return this.carUnmatchedVehicleIcon;
|
return this.carUnmatchedVehicleIcon;
|
||||||
|
|
@ -58,8 +58,6 @@ export default {
|
||||||
return this.suvUnmatchedVehicleIcon;
|
return this.suvUnmatchedVehicleIcon;
|
||||||
case this.vehicleCategories.TRUCK:
|
case this.vehicleCategories.TRUCK:
|
||||||
return this.truckUnmatchedVehicleIcon;
|
return this.truckUnmatchedVehicleIcon;
|
||||||
case this.vehicleCategories.PICKUP:
|
|
||||||
return this.truckUnmatchedVehicleIcon;
|
|
||||||
case this.vehicleCategories.VAN:
|
case this.vehicleCategories.VAN:
|
||||||
return this.vanUnmatchedVehicleIcon;
|
return this.vanUnmatchedVehicleIcon;
|
||||||
case this.vehicleCategories.COMMERCIALVAN:
|
case this.vehicleCategories.COMMERCIALVAN:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { storeActions } from "@/constants/store-actions";
|
import { storeActions } from "@/constants/store-actions";
|
||||||
import { storeMutations } from "@/constants/store-mutations.js";
|
import { storeMutations } from "@/constants/store-mutations.js";
|
||||||
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios.js";
|
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios.js";
|
||||||
|
import { vehicleCategories } from "@/constants/vehicle-categories.js";
|
||||||
|
|
||||||
export function getMountOptions(mockData) {
|
export function getMountOptions(mockData) {
|
||||||
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
||||||
|
|
@ -23,6 +24,7 @@ export function getMountOptions(mockData) {
|
||||||
mocks.storeActions = storeActions;
|
mocks.storeActions = storeActions;
|
||||||
mocks.storeMutations = storeMutations;
|
mocks.storeMutations = storeMutations;
|
||||||
mocks.navigationScenarios = navigationScenarios;
|
mocks.navigationScenarios = navigationScenarios;
|
||||||
|
mocks.vehicleCategories = vehicleCategories;
|
||||||
|
|
||||||
// Mock $store and $router when accessing this.$store/$router
|
// Mock $store and $router when accessing this.$store/$router
|
||||||
mocks.$store = mockData.store;
|
mocks.$store = mockData.store;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
<div class="container-fluid shadow rounded-3 p-0 position-relative">
|
<div class="container-fluid shadow rounded-3 p-0 position-relative">
|
||||||
<funnelHeader ref="funnelHeader" />
|
<funnelHeader ref="funnelHeader" />
|
||||||
<vehicleBanner ref="vehicleBanner" :displayGenericVehicleImage=false />
|
<vehicleBanner ref="vehicleBanner" :displayGenericVehicleImage=false />
|
||||||
<funnelSubHeader
|
<funnelSubHeader ref="funnelSubHeader" :hasSubText=true />
|
||||||
ref="funnelSubHeader"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue