// Components
import vehicle from "@/layouts/vehicle/vehicle.vue";

// Supporting Files
import { shallowMount } from "@vue/test-utils";
import { nextTick } from "vue";
import { getMountOptions } from "@/helpers/unit-test-helper.js";

// Mock our module for promises.
jest.mock("@/helpers/layout-helper.js", () => ({
    settleAllPromises: jest.fn(),
}));

describe("vehicle.vue", () => {
    test("arePagePrerequisitesValid should be true ", async () => {
        //Arrange
        const { wrapper } = setupMocks();

        //Act
        let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
        await nextTick();

        //Assert
        expect(arePagePrerequisitesValid).toBe(true);
    });
});
describe("vehicle.vue", () => {
    describe("navigation", () => {
        test("if the continue button is clicked, navigate forward", async () => {
            // Arrange
            const { wrapper } = setupMocks();

            // Act
            await wrapper.vm.forwardButtonAction();

            // Assert
            expect(wrapper.vm.$router.navigateWithSaving).toHaveBeenCalled();
        });
    });
});

function setupMocks() {
    const wrapper = shallowMount(
        vehicle,
        getMountOptions({
            router: {
                navigate: jest.fn(),
                navigate: jest.fn(),
                navigateWithSaving: jest.fn(),
                navigateWithoutSaving: jest.fn(),
            },
        })
    );

    return { wrapper };
}
