CSR-222: updates to unit tests and helper
This commit is contained in:
parent
42b1bbe031
commit
9c44e35058
3 changed files with 37 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
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";
|
||||||
|
|
||||||
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.
|
||||||
|
|
@ -21,6 +22,7 @@ export function getMountOptions(mockData) {
|
||||||
// Mock const files
|
// Mock const files
|
||||||
mocks.storeActions = storeActions;
|
mocks.storeActions = storeActions;
|
||||||
mocks.storeMutations = storeMutations;
|
mocks.storeMutations = storeMutations;
|
||||||
|
mocks.navigationScenarios = navigationScenarios;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ jest.mock("@/helpers/layout-helper.js", () => ({
|
||||||
describe("vehicle-make.vue", () => {
|
describe("vehicle-make.vue", () => {
|
||||||
test("Make question component is initized with api data", async (done) => {
|
test("Make question component is initized with api data", async (done) => {
|
||||||
|
|
||||||
//Arange
|
//Arrange
|
||||||
const radioQuestionCmsContent = { QuestionText: "What make is your vehicle?" };
|
const radioQuestionCmsContent = { QuestionText: "What make is your vehicle?" };
|
||||||
const makeQuestionInitialData = ["honda", "ford", "dodge"];
|
const makeQuestionInitialData = ["honda", "ford", "dodge"];
|
||||||
const { wrapper, apiPromise } = setupMocks( {
|
const { wrapper, apiPromise } = setupMocks( {
|
||||||
|
|
@ -35,7 +35,7 @@ describe("vehicle-make.vue", () => {
|
||||||
describe("vehicle-make.vue", () => {
|
describe("vehicle-make.vue", () => {
|
||||||
test("Page header is passed data from CMS", async (done) => {
|
test("Page header is passed data from CMS", async (done) => {
|
||||||
|
|
||||||
//Arange
|
//Arrange
|
||||||
const { wrapper, apiPromise } = setupMocks( { pageHeaderWidgetHeaderText: "Select a make to get started" });
|
const { wrapper, apiPromise } = setupMocks( { pageHeaderWidgetHeaderText: "Select a make to get started" });
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
|
@ -50,10 +50,38 @@ describe("vehicle-make.vue", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("vehicle-make.vue", () => {
|
||||||
|
test("BackButtonAction triggers a router.navigate change", async (done) => {
|
||||||
|
|
||||||
|
//Arrange
|
||||||
|
const { wrapper, apiPromise } = setupMocks( {
|
||||||
|
pageHeaderWidgetHeaderText: "Select a make to get started",
|
||||||
|
mountOptionsMockData: {
|
||||||
|
router: {
|
||||||
|
navigate: jest.fn()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const backButtonActionMethod = jest.spyOn(wrapper.vm, "backButtonAction");
|
||||||
|
|
||||||
|
//Act
|
||||||
|
vehicleMake.beforeRouteEnter.call(wrapper.vm, { query: { fmgPage: "vehicle-make" } }, undefined, (c) => c(wrapper.vm));
|
||||||
|
wrapper.vm.backButtonAction();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
apiPromise.finally(() => {
|
||||||
|
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function setupMocks({
|
function setupMocks({
|
||||||
radioQuestionCmsContent = {},
|
radioQuestionCmsContent = {},
|
||||||
makeQuestionInitialData = {},
|
makeQuestionInitialData = {},
|
||||||
pageHeaderWidgetHeaderText = {},
|
pageHeaderWidgetHeaderText = {},
|
||||||
|
mountOptionsMockData = {},
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
//Mock api responses
|
//Mock api responses
|
||||||
|
|
@ -84,7 +112,7 @@ function setupMocks({
|
||||||
loadInitialData: jest.fn(),
|
loadInitialData: jest.fn(),
|
||||||
initializeComponent: jest.fn(),
|
initializeComponent: jest.fn(),
|
||||||
};
|
};
|
||||||
const mountOptions = getMountOptions({ });
|
const mountOptions = getMountOptions(mountOptionsMockData);
|
||||||
const wrapper = shallowMount(vehicleMake, mountOptions);
|
const wrapper = shallowMount(vehicleMake, mountOptions);
|
||||||
const makeQuestionWrapper = wrapper.findComponent({ name: "makeQuestion" });
|
const makeQuestionWrapper = wrapper.findComponent({ name: "makeQuestion" });
|
||||||
makeQuestionWrapper.vm.initializeComponent = makeQuestion.methods.initializeComponent;
|
makeQuestionWrapper.vm.initializeComponent = makeQuestion.methods.initializeComponent;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ jest.mock("@/helpers/layout-helper.js", () => ({
|
||||||
describe("vehicle-year.vue", () => {
|
describe("vehicle-year.vue", () => {
|
||||||
test("Year question component is initized with api data", async (done) => {
|
test("Year question component is initized with api data", async (done) => {
|
||||||
|
|
||||||
//Arange
|
//Arrange
|
||||||
const radioQuestionCmsContent = { QuestionText: "What year is your vehicle?" };
|
const radioQuestionCmsContent = { QuestionText: "What year is your vehicle?" };
|
||||||
const yearQuestionInitialData = ["2023", "2022", "2021"];
|
const yearQuestionInitialData = ["2023", "2022", "2021"];
|
||||||
const { wrapper, apiPromise } = setupMocks( {
|
const { wrapper, apiPromise } = setupMocks( {
|
||||||
|
|
@ -35,7 +35,7 @@ describe("vehicle-year.vue", () => {
|
||||||
describe("vehicle-year.vue", () => {
|
describe("vehicle-year.vue", () => {
|
||||||
test("Page header is passed data from CMS", async (done) => {
|
test("Page header is passed data from CMS", async (done) => {
|
||||||
|
|
||||||
//Arange
|
//Arrange
|
||||||
const { wrapper, apiPromise } = setupMocks( { pageHeaderWidgetHeaderText: "Select a year to get started" });
|
const { wrapper, apiPromise } = setupMocks( { pageHeaderWidgetHeaderText: "Select a year to get started" });
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
|
|
@ -54,6 +54,7 @@ function setupMocks({
|
||||||
radioQuestionCmsContent = {},
|
radioQuestionCmsContent = {},
|
||||||
yearQuestionInitialData = {},
|
yearQuestionInitialData = {},
|
||||||
pageHeaderWidgetHeaderText = {},
|
pageHeaderWidgetHeaderText = {},
|
||||||
|
mountOptionsMockData = {},
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
//Mock api responses
|
//Mock api responses
|
||||||
|
|
@ -84,7 +85,7 @@ function setupMocks({
|
||||||
loadInitialData: jest.fn(),
|
loadInitialData: jest.fn(),
|
||||||
initializeComponent: jest.fn(),
|
initializeComponent: jest.fn(),
|
||||||
};
|
};
|
||||||
const mountOptions = getMountOptions({ });
|
const mountOptions = getMountOptions(mountOptionsMockData);
|
||||||
const wrapper = shallowMount(vehicleYear, mountOptions);
|
const wrapper = shallowMount(vehicleYear, mountOptions);
|
||||||
const yearQuestionWrapper = wrapper.findComponent({ name: "yearQuestion" });
|
const yearQuestionWrapper = wrapper.findComponent({ name: "yearQuestion" });
|
||||||
yearQuestionWrapper.vm.initializeComponent = yearQuestion.methods.initializeComponent;
|
yearQuestionWrapper.vm.initializeComponent = yearQuestion.methods.initializeComponent;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue