import { shallowMount } from "@vue/test-utils";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import calendarModalQuestion from "@/layouts/confirmation/add-to-calendar/calendar-modal-question/calendar-modal-question.vue";

describe("calendar-modal-question.vue", () => {
    test("When selected calendar option is changed, a correctly selectedCalendarOption should be emitted", async () => {
        //Arrange
        const url = "iCal url";
        const name = "iCal";
        const icon = "iCal.svg";
        const expectedEmit = [
            [
                {
                    url: url,
                    name: name,
                    icon: icon,
                },
            ],
        ];

        const { wrapper } = setupMocks({
            customMountOptions: {
                propsData: {
                    calendarOptionsData: [
                        {
                            url: url,
                            name: name,
                            icon: icon,
                        },
                    ],
                },
            },
        });

        wrapper.vm.$refs.calendarOptions.closeModal = jest.fn();
        wrapper.vm.selectedCalendarOption = name;

        //Act
        wrapper.vm.setSelectedCalendarOption();

        //Assert
        expect(wrapper.emitted()["update:modelValue"]).toEqual(expectedEmit);
    });
});

function setupMocks({ customMountOptions }) {
    const mountOptions = getMountOptions({
        ...customMountOptions,
    });

    const wrapper = shallowMount(calendarModalQuestion, mountOptions);
    return { wrapper };
}
