import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import i18n from "../i18n.test";
import { LanguageToggle } from "./LanguageToggle";

describe("LanguageToggle", () => {
  it("renders without crashing", () => {
    const { container } = render(<LanguageToggle />);
    expect(container.firstChild).toBeInTheDocument();
  });

  it("displays both language flags", () => {
    const { container } = render(<LanguageToggle />);
    expect(container).toHaveTextContent("🇬🇧");
    expect(container).toHaveTextContent("🇫🇷");
  });

  it("renders a switch component", () => {
    render(<LanguageToggle />);
    const switchElement = screen.getByRole("switch");
    expect(switchElement).toBeInTheDocument();
  });

  it("calls changeLanguage when switch is toggled", () => {
    render(<LanguageToggle />);
    const switchElement = screen.getByRole("switch");
    const initialLang = i18n.language;
    fireEvent.click(switchElement);
    // Language should have changed
    expect(i18n.language).not.toBe(initialLang);
  });
});
