import { mount } from "@vue/test-utils";
import servicePackageRadio from "./service-package-radio";
import inputButtonWrapperMixin from "@/mixins/input-button-wrapper-mixin";

describe("service-package-radio.vue", () => {
    it("Should include buttonLabel in html", async () => {
        // Arrange
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: mockProps,
            },
        });

        // Act
        const outputHtml = wrapper.html();

        // Assert
        expect(outputHtml).toEqual(expect.stringContaining(mockProps["buttonLabel"]));
    });

    it("Should include buttonLabelSubCopy in html", async () => {
        // Arrange
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: mockProps,
            },
        });

        // Act
        const outputHtml = wrapper.html();

        // Assert
        expect(outputHtml).toEqual(expect.stringContaining(mockProps["buttonLabelSubCopy"]));
    });
    it("Should include buttonFooterCopy in html", async () => {
        // Arrange
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: mockProps,
            },
        });

        // Act
        const outputHtml = wrapper.html();

        // Assert
        expect(outputHtml).toEqual(expect.stringContaining(mockProps["buttonFooterCopy"]));
    });
    it("Should get 5 strings from getArrayOfListItemsFromRawCmsCopy when provided with a <ul><li>...</li>(x5)</ul> buttonBodyCopy", async () => {
        // Arrange
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: mockProps,
            },
        });
        // Act
        const results = wrapper.vm.getArrayOfListItemsFromRawCmsCopy(wrapper.vm.buttonBodyCopy);

        // Assert
        expect(results.length).toBe(5);
    });
    it("Should get strings from getArrayOfListItemsFromRawCmsCopy without <ul> or <li> tags when provided with a <ul><li>...</li></ul> buttonBodyCopy", async () => {
        // Arrange
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: mockProps,
            },
        });

        // Act
        const results = wrapper.vm.getArrayOfListItemsFromRawCmsCopy(wrapper.vm.buttonBodyCopy);

        // Assert
        const fileredResults = results.filter((result) => {
            return (
                result.includes("<ul>") ||
                result.includes("</ul>") ||
                result.includes("<li>") ||
                result.includes("</li>")
            );
        });
        expect(fileredResults.length).toBe(0);
    });
    it("Should get 5 strings from getArrayOfListItemsFromRawCmsCopy when buttonBodyCopy has 6 total <li>...</li>, but one is empty ", async () => {
        // Arrange
        const moddedProps = mockProps;
        moddedProps["buttonBodyCopy"] =
            "<ul><li>buttonBodyCopy test copy</li><li>2</li><li>3</li><li>4</li><li>5</li><li></li></ul>";
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: moddedProps,
            },
        });

        // Act
        const results = wrapper.vm.getArrayOfListItemsFromRawCmsCopy(wrapper.vm.buttonBodyCopy);

        // Assert
        expect(results.length).toBe(5);
    });
});

const mockProps = {
    groupName: "group-name",
    buttonLabel: "buttonLabel test copy",
    buttonLabelAuxillaryCopy: "buttonLabelAuxillaryCopy test copy",
    buttonLabelSubCopy: "buttonLabelSubCopy test copy",
    buttonBodyCopy:
        "<ul><li>buttonBodyCopy test copy</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>",
    buttonFooterCopy: "buttonFooterCopy test copy",
    buttonAuxillaryCopy: "buttonAuxillaryCopy test copy",
    additionalButtonData: {
        strikeThroughPrice: "strikeThroughPrice test copy",
        servicePackageDiscount: true,
        Text: "Special save",
    },
};

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

    return { wrapper };
}
