import { mount } from "@vue/test-utils";
import checkbox from "./checkbox";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import inputButtonWrapperMixin from "@/mixins/input-button-wrapper-mixin";

describe("checkbox.vue", () => {
    it("Should have correct group name", async () => {
        // Arrange
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: {
                    groupName: "checkbox-button-test",
                    value: "test value",
                },
            },
        });

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

        // Assert
        expect(input.attributes().name).toEqual("checkbox-button-test");
    });

    it("Should have correct label text", async () => {
        // Act
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: {
                    groupName: "checkbox-button-test",
                    buttonLabel: "label text",
                    value: "test value",
                },
            },
        });

        // Arrange
        const paragraph = wrapper.find("p");

        // Assert
        expect(paragraph.text()).toEqual("label text");
    });

    it("Should have correct screenreader-only text", async () => {
        // Act
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: {
                    groupName: "checkbox-button-test",
                    buttonLabel: "label text",
                    value: "test value",
                },
            },
        });

        // Arrange
        await wrapper.setProps({
            screenReaderOnlyText: "screenreader text",
            value: "test value",
        });
        const paragraph = wrapper.find(".sr-only");

        // Assert
        expect(paragraph.text()).toEqual("screenreader text");
    });
});

function setupMocks({ mountOptionsMockData = {} }) {
    const wrapper = mount(checkbox, {
        ...mountOptionsMockData,
        mixins: [inputButtonWrapperMixin],
    });

    return { wrapper };
}
