DigitalConsumer.FixMyGlass/src/mixins/vin-pages-mixin.spec.js

70 lines
1.9 KiB
JavaScript

import vinPagesMixin from "@/mixins/vin-pages-mixin";
import { shallowMount } from "@vue/test-utils";
import { setupMocksForJsFiles, getMountOptions } from "@/helpers/unit-test-helper.js";
import { storeActions } from "@/constants/store-actions";
import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin";
jest.mock("@/helpers/heritage-integration/navigation-helper", () => ({
navigateForward: jest.fn(),
}));
jest.mock("@/helpers/heritage-integration/order-helper.js", () => ({
saveSession: jest.fn(),
}));
describe("vin-pages-mixin", () => {
afterEach(() => {
jest.clearAllMocks();
});
describe("navigateForwardWithSingleCarMatch", () => {
test("should navigateForward", async () => {
// Arrange
const { wrapper } = setupMocks({});
vehicleQuestionsMixin.methods.navigateForward = jest.fn();
// Act
await wrapper.vm.navigateForwardWithSingleCarMatch();
// Assert
expect(vehicleQuestionsMixin.methods.navigateForward).toHaveBeenCalled();
});
});
});
function setupMocks({ partsOrQuestions = [] }) {
const baseMixin = setupMocksForJsFiles({
actionList: [
{
actionName: storeActions.GET_PARTS_OR_QUESTIONS,
data: {
partsOrQuestions: partsOrQuestions,
},
},
],
});
const mocks = getMountOptions({
router: {
navigate: jest.fn(),
navigateWithSaving: jest.fn(),
navigateWithoutSaving: jest.fn(),
},
store: {
commit: jest.fn(),
getters: {
applicationUser: {
savedSessionId: 1,
},
},
},
});
const mockVinComponent = {
mixins: [vinPagesMixin, baseMixin.baseMixin],
};
const wrapper = shallowMount(mockVinComponent, mocks);
return { wrapper };
}