import { shallowMount } from "@vue/test-utils";
import CashOrInsuranceQuestion from "./cash-or-insurance-question";

describe("cash-or-insurance-question.vue", () => {
    it("Should emit a false boolean value when selectedValues is 'CashAnswer' (update:modelValue)", async () => {
        //Arrange
        const wrapper = shallowMount(CashOrInsuranceQuestion, {
            propsData: mockProps,
            mixins: [mockMixin],
        });

        //Act
        wrapper.vm.selectedValues = "CashAnswer";
        await wrapper.vm.$nextTick();

        //Assert
        expect(wrapper.emitted()["update:modelValue"][0]).toEqual([false]);
        expect(typeof wrapper.emitted()["update:modelValue"][0][0]).toBe("boolean");
    });
    it("Should return 'CashAnswer' from selectedValues when modelValue is set to false", async () => {
        //Arrange
        const wrapper = shallowMount(CashOrInsuranceQuestion, {
            propsData: mockProps,
            mixins: [mockMixin],
        });

        //Act
        wrapper.setProps({ modelValue: false });
        await wrapper.vm.$nextTick();

        //Assert
        expect(wrapper.vm.selectedValues).toBe("CashAnswer");
    });
});

///////////////
// Constants //
///////////////

const mockMixin = {
    methods: {
        getCmsContent: jest.fn((widgetName, cmsFieldName) => {
            return mockCmsContent[cmsFieldName];
        }),
    },
};

const mockProps = {
    modelValue: true,
};

const mockCmsContent = {
    Text: "Sample text here.",
};
