// @vitest-environment jsdom

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

describe("EnabledSwitchRow", () => {
  it("renders an enabled switch row with visible status", () => {
    render(
      <EnabledSwitchRow
        title="Enable image tag checks before execution"
        description="Verify the target image tag before applying changes."
        checked
        onChange={vi.fn()}
      />
    );

    expect(
      screen.getByRole("switch", {
        name: "Enable image tag checks before execution",
      })
    ).toBeChecked();
    expect(screen.getByText("Enabled")).toBeInTheDocument();
    expect(
      screen.getByText("Verify the target image tag before applying changes.")
    ).toBeInTheDocument();
  });

  it("toggles when the row is clicked", () => {
    const onChange = vi.fn();
    render(
      <EnabledSwitchRow
        title="Also update variant templates"
        description="Keep provider variant templates aligned with selected regions."
        checked={false}
        onChange={onChange}
      />
    );

    fireEvent.click(screen.getByText("Also update variant templates"));

    expect(onChange).toHaveBeenCalledWith(true);
    expect(screen.getByText("Disabled")).toBeInTheDocument();
  });
});
