import { mount } from "@vue/test-utils";
import shopListButton from "./shop-list-button";
import inputButtonWrapperMixin from "@/mixins/input-button-wrapper-mixin";

describe("shop-list-button.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 buttonLabelAuxillaryCopy in html", async () => {
        // Arrange
        let { wrapper } = setupMocks({
            mountOptionsMockData: {
                propsData: mockProps,
            },
        });

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

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

const startDate = new Date();
const endDate = new Date();
endDate.setDate(startDate.getDate() + 7);
const getAvailabilityRating = jest.fn().mockImplementation((actionName, request) => {
    return Promise.resolve({
        data: {},
    });
});

const formattedStartDate = startDate.toISOString().split("T")[0];
const formattedEndDate = endDate.toISOString().split("T")[0];

const mockProps = {
    buttonLabel: "buttonLabel 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>",
    buttonLabelAuxillaryCopy: "buttonLabelAuxillaryCopy test copy",
    value: 0,
    modelValue: 0,
    groupName: "mockGroup",
    additionalButtonData: {
        availabilityRatingCallback: getAvailabilityRating,
        startDate: formattedStartDate,
        endDate: formattedEndDate,
        shopAppointmentType: "Dropoff",
    },
};

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

    return { wrapper };
}
