// Components
import textareaQuestion from "./textarea-question";

// Supporting Files
import { shallowMount } from "@vue/test-utils";

const maska = jest.fn();

const questionText = "textareaQuestionText";
const mockMixin = {
    methods: {
        getCmsContent: jest.fn().mockImplementation(() => {
            return questionText;
        }),
    },
};

describe("textarea-question.vue", () => {
    it("Should render a textarea", async () => {
        // Arrange
        const wrapper = shallowMount(textareaQuestion, {
            global: {
                directives: {
                    maska: maska,
                },
            },
            propsData: {
                modelValue: "",
            },
            mixins: [mockMixin],
        });

        wrapper.getCmsContent = jest.fn();

        // Act
        const textarea = wrapper.find("textarea");

        // Assert
        expect(textarea.exists()).toBe(true);
    });

    it("Should emit new value when modelValue is changed", async () => {
        // Act
        const wrapper = shallowMount(textareaQuestion, {
            global: {
                directives: {
                    maska: maska,
                },
            },
            propsData: {
                modelValue: "val",
            },
            mixins: [mockMixin],
        });

        await wrapper.find("textarea").setValue("val2");

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