import "./toggle-switch.js";
import "../../node_modules/vitest-browser-lit/dist/index.js";
import { html } from "lit";
import { describe, beforeEach, it } from "../../node_modules/@vitest/runner/dist/index.js";
import { g as globalExpect, v as vi } from "../../node_modules/vitest/dist/chunks/test.CTcmp4Su.js";
import { render as render$1 } from "../../node_modules/vitest-browser-lit/dist/pure-D9bcvh0k.js";
describe("obc-toggle-switch", () => {
  let el;
  let input;
  async function setup(markup = html`<obc-toggle-switch></obc-toggle-switch>`) {
    const screen = render$1(markup);
    el = screen.baseElement.querySelector(
      "obc-toggle-switch"
    );
    await el.updateComplete;
    if (!el.shadowRoot) {
      console.error("Shadow root not found", el);
      throw new Error("Shadow root not found");
    }
    input = el.shadowRoot.querySelector(
      'input[type="checkbox"]'
    );
    if (!input) {
      console.error("Input not found", el.shadowRoot);
      throw new Error("Input not found");
    }
  }
  beforeEach(async () => {
    await setup();
  });
  it("defaults to unchecked", async () => {
    globalExpect(el.checked).toBe(false);
    globalExpect(input.checked).toBe(false);
  });
  describe("toggling (internal control)", () => {
    it("dispatches input event with next checked value", async () => {
      const handler = vi.fn();
      el.addEventListener("input", handler);
      input.click();
      await el.updateComplete;
      globalExpect(handler).toHaveBeenCalledTimes(1);
      const event = handler.mock.calls[0]?.[0];
      globalExpect(event.detail).toEqual({ checked: true });
    });
    it("combination of click and js control", async () => {
      el.checked = true;
      await el.updateComplete;
      globalExpect(el.checked).toBe(true);
      globalExpect(input.checked).toBe(true);
      input.click();
      await el.updateComplete;
      globalExpect(el.checked).toBe(false);
      globalExpect(input.checked).toBe(false);
      input.click();
      await el.updateComplete;
      globalExpect(el.checked).toBe(true);
      globalExpect(input.checked).toBe(true);
      el.checked = false;
      await el.updateComplete;
      globalExpect(el.checked).toBe(false);
      globalExpect(input.checked).toBe(false);
    });
    it("updates checked when user toggles", async () => {
      input.click();
      await el.updateComplete;
      globalExpect(el.checked).toBe(true);
      globalExpect(input.checked).toBe(true);
    });
  });
  describe("externalControl", () => {
    beforeEach(async () => {
      el.externalControl = true;
      await el.updateComplete;
    });
    it("does not change checked when user toggles", async () => {
      globalExpect(el.checked).toBe(false);
      globalExpect(input.checked).toBe(false);
      input.click();
      await el.updateComplete;
      globalExpect(el.checked).toBe(false);
      globalExpect(input.checked).toBe(false);
    });
    it("still dispatches input event with suggested next state", async () => {
      const handler = vi.fn();
      el.addEventListener("input", handler);
      input.click();
      await el.updateComplete;
      globalExpect(handler).toHaveBeenCalledTimes(1);
      const event = handler.mock.calls[0]?.[0];
      globalExpect(event.detail).toEqual({ checked: true });
    });
  });
  describe("disabled", () => {
    beforeEach(async () => {
      el.disabled = true;
      await el.updateComplete;
    });
    it("prevents toggling", async () => {
      globalExpect(el.checked).toBe(false);
      globalExpect(input.disabled).toBe(true);
      input.click();
      await el.updateComplete;
      globalExpect(el.checked).toBe(false);
      globalExpect(input.checked).toBe(false);
    });
    it("does not dispatch input event", async () => {
      const handler = vi.fn();
      el.addEventListener("input", handler);
      input.click();
      await el.updateComplete;
      globalExpect(handler).not.toHaveBeenCalled();
    });
  });
});
//# sourceMappingURL=toggle-switch.spec.js.map
