import React from "react";
import { render, screen } from "@testing-library/react";
import { vi } from "vitest";
import { Header } from ".";
vi.mock("~/tracking", () => ({
    useTracking: () => ({
        postEvent: vi.fn(),
        trackAnalyticsEvent: vi.fn(),
    }),
}));
// Mock translations
const tMock = vi.fn().mockImplementation((key) => key);
vi.mock("react-i18next", () => ({
    useTranslation: () => ({
        t: tMock,
    }),
}));
// Mock context
const mockUseRootElement = vi.fn();
const onToggleIsExpandedMock = vi.fn();
vi.mock("../context", () => ({
    useRootElement: () => mockUseRootElement(),
}));
describe("Header", () => {
    beforeEach(() => {
        vi.resetAllMocks();
    });
    it("renders without crashing", () => {
        mockUseRootElement.mockReturnValue({
            activeScore: null,
            isExpanded: true,
            onToggleIsExpanded: onToggleIsExpandedMock,
        });
        render(React.createElement(Header, null));
        expect(screen.getByTestId("sidebar-header")).toBeInTheDocument();
    });
    it("renders the title when isExpanded is true and activeScore is null", () => {
        mockUseRootElement.mockReturnValue({
            activeScore: null,
            isExpanded: true,
            onToggleIsExpanded: onToggleIsExpandedMock,
        });
        render(React.createElement(Header, null));
        const title = screen.getByTestId("sidebar-header-title");
        expect(title).toBeInTheDocument();
    });
    it("renders the close button when isExpanded is true and activeScore is not null", () => {
        mockUseRootElement.mockReturnValue({
            activeScore: "pedestrian_friendly",
            isExpanded: true,
            onToggleIsExpanded: onToggleIsExpandedMock,
        });
        render(React.createElement(Header, null));
        const toggleButton = screen.getByTestId("sidebar-header-toggle");
        expect(toggleButton).toBeInTheDocument();
    });
    it("toggles isExpanded state when arrow button is clicked", () => {
        mockUseRootElement.mockReturnValue({
            activeScore: null,
            isExpanded: true,
            onToggleIsExpanded: onToggleIsExpandedMock,
        });
        render(React.createElement(Header, null));
        const toggleButton = screen.getByTestId("sidebar-header-toggle");
        toggleButton.click();
        expect(onToggleIsExpandedMock).toHaveBeenCalled();
    });
});
//# sourceMappingURL=index.test.js.map