var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import React from "react";
import { render, fireEvent } from "@testing-library/react";
import { describe, it, expect, vi } from "vitest";
import { ScoresPillList } from ".";
vi.mock("react-i18next", (importOriginal) => __awaiter(void 0, void 0, void 0, function* () {
    return (Object.assign(Object.assign({}, (yield importOriginal())), { useTranslation: () => ({
            t: (key) => key,
        }) }));
}));
const postEventMock = vi.fn();
const trackAnalyticsEventMock = vi.fn();
vi.mock("~/tracking", () => ({
    useTracking: () => ({
        postEvent: postEventMock,
        trackAnalyticsEvent: trackAnalyticsEventMock,
    }),
}));
const handleSelectScoreMock = vi.fn();
vi.mock("~/sdks/LocalContent/context", () => ({
    useLocalContent: () => ({
        activeScore: undefined,
        handleSelectScore: (score) => () => {
            handleSelectScoreMock(score);
        },
    }),
}));
describe("ScoresPillList", () => {
    const renderComponent = (props = {}) => render(React.createElement(ScoresPillList, Object.assign({ scores: ["pedestrian_friendly", "groceries", "wellness"], backgroundColor: "#ffffff", fillColor: "#000000" }, props)));
    beforeEach(() => {
        vi.resetAllMocks();
    });
    it("renders the correct number of score pills", () => {
        const { getAllByRole } = renderComponent();
        const buttons = getAllByRole("button");
        expect(buttons).toHaveLength(3);
    });
    it("calls handleSelectScore when a score pill is clicked", () => {
        const { getAllByRole } = renderComponent();
        const buttons = getAllByRole("button");
        fireEvent.click(buttons[0]);
        expect(handleSelectScoreMock).toHaveBeenCalledWith("pedestrian_friendly");
    });
    it("tracks events with correct attributes", () => {
        const { getAllByRole } = renderComponent();
        const buttons = getAllByRole("button");
        fireEvent.click(buttons[0]);
        expect(postEventMock).toHaveBeenCalledWith({
            eventType: "LC-Sidebar-Score-Selected",
            eventAttributes: [
                { label: "scoreKey", data: "pedestrian_friendly" },
                { label: "isExpanded", data: false },
            ],
        });
        expect(trackAnalyticsEventMock).toHaveBeenCalledWith({
            eventName: "categories_menu_score_selected",
            eventAttributes: {
                scoreKey: "pedestrian_friendly",
                isExpanded: false,
            },
        });
    });
    it("applies the correct styles based on props", () => {
        const { container } = renderComponent({
            backgroundColor: "#ff0000",
            fillColor: "#00ff00",
        });
        const pillList = container.firstChild;
        expect(pillList).toHaveStyle("--background: #ff0000");
        expect(pillList).toHaveStyle("--fill: #00ff00");
    });
    it("does not render when scores prop is undefined or empty", () => {
        const { container: containerUndefined } = renderComponent({
            scores: undefined,
        });
        expect(containerUndefined.firstChild).toBeNull();
        const { container: containerEmpty } = renderComponent({ scores: [] });
        expect(containerEmpty.firstChild).toBeNull();
    });
});
//# sourceMappingURL=index.test.js.map