81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
import { shallowMount, flushPromises } from "@vue/test-utils";
|
|
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
|
import vehicleYear from "@/layouts/vehicle-year/vehicle-year.vue";
|
|
import { settleAllPromises } from "@/helpers/layout-helper.js";
|
|
import { nextTick } from "vue";
|
|
|
|
// Mock our module for promises.
|
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
|
settleAllPromises: jest.fn(),
|
|
}));
|
|
|
|
describe("vehicle-year.vue", () => {
|
|
test("vehicle-year.vue should render data from CMS", async () => {
|
|
// Arrange
|
|
|
|
// Our mock data for our call to settleAllPromises
|
|
const mockData = {
|
|
getPageContent: {
|
|
PageHeaderWidget: [{ HeaderText: "Select a year to get started" }],
|
|
RadioQuestionWidget: [{ QuestionText: "What year is your vehicle?" }],
|
|
VehicleBannerWidget: [
|
|
{
|
|
GenericVehicleImage:
|
|
"https://digitalconsumercms-dev.safelite.com/images/default-source/default-album/blurred-image.jpg?sfvrsn=a6ce3034_3",
|
|
},
|
|
],
|
|
SiteHeaderWidget: [
|
|
{
|
|
LogoImage:
|
|
"https://digitalconsumercms-dev.safelite.com/images/default-source/default-album/safelite-logo.svg?sfvrsn=45e7ed06_3",
|
|
},
|
|
],
|
|
isCmsContentReady: true,
|
|
},
|
|
getVehicleYear: [2023, 2022, 2021],
|
|
store: {
|
|
commit: jest.fn(),
|
|
year: null,
|
|
},
|
|
router: {
|
|
push: jest.fn(),
|
|
},
|
|
};
|
|
|
|
// our router information needed.
|
|
const to = {
|
|
query: {
|
|
fmgPage: "vehicle-year",
|
|
},
|
|
};
|
|
|
|
const mountOptions = getMountOptions(mockData);
|
|
|
|
// our mock implementation of settleAllPromises
|
|
settleAllPromises.mockImplementation(() => {
|
|
return Promise.resolve(mockData);
|
|
});
|
|
|
|
// Act
|
|
const wrapper = shallowMount(vehicleYear, mountOptions);
|
|
wrapper.vm.$options.watch.selectedYear.call(wrapper.vm);
|
|
|
|
// Call our beforeRouteEnter on the component.
|
|
// This passes (c) => c(wrapper.vm) so that next can be called and our
|
|
// data can be set.
|
|
vehicleYear.beforeRouteEnter.call(wrapper.vm, to, undefined, (c) =>
|
|
c(wrapper.vm)
|
|
);
|
|
|
|
await nextTick(); // Wait for the DOM to update.
|
|
|
|
// Assert
|
|
const header = await wrapper.find(".Header");
|
|
expect(header.attributes("text")).toEqual("Select a year to get started");
|
|
|
|
const yearQuestion = wrapper.findComponent({ name: "year-question" });
|
|
expect(yearQuestion.attributes("questiontext")).toEqual(
|
|
"What year is your vehicle?"
|
|
);
|
|
});
|
|
});
|