import "./textarea-field.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 { render as render$1 } from "../../node_modules/vitest-browser-lit/dist/pure-D9bcvh0k.js";
import { g as globalExpect, v as vi } from "../../node_modules/vitest/dist/chunks/test.CTcmp4Su.js";
describe("obc-textarea-field", () => {
  let el;
  let textarea;
  beforeEach(async () => {
    const screen = render$1(
      html`<obc-textarea-field value="hello"></obc-textarea-field>`
    );
    el = screen.baseElement.querySelector(
      "obc-textarea-field"
    );
    await el.updateComplete;
    if (!el.shadowRoot) {
      console.error("Shadow root not found", el);
      throw new Error("Shadow root not found");
    }
    textarea = el.shadowRoot.querySelector(
      ".input-field"
    );
    if (!textarea) {
      console.error("Textarea not found", el.shadowRoot);
      throw new Error("Textarea not found");
    }
  });
  describe("rejectUpdates", () => {
    beforeEach(async () => {
      el.rejectUpdates = true;
      await el.updateComplete;
    });
    it("keeps user-typed value when property is set back to previous", async () => {
      el.value = "hello world";
      await el.updateComplete;
      globalExpect(textarea.value).toBe("hello");
    });
  });
  describe("rejectUpdatesOnFocus", () => {
    beforeEach(async () => {
      el.rejectUpdatesOnFocus = true;
      await el.updateComplete;
    });
    it("keeps user-typed value when property is set back to previous value while focused", async () => {
      textarea.focus();
      textarea.value = "hello world";
      textarea.dispatchEvent(new InputEvent("input", { bubbles: true }));
      await el.updateComplete;
      el.value = "hello";
      await el.updateComplete;
      globalExpect(textarea.value).toBe("hello world");
    });
  });
  describe("rejectDuplicateUpdates", () => {
    beforeEach(async () => {
      el.rejectDuplicateUpdates = true;
      await el.updateComplete;
    });
    it("keeps user-typed value when property is set back to previous value while focused", async () => {
      textarea.focus();
      textarea.value = "hello world";
      textarea.dispatchEvent(new InputEvent("input", { bubbles: true }));
      await el.updateComplete;
      globalExpect(textarea.value).toBe("hello world");
      el.value = "hello";
      await el.updateComplete;
      globalExpect(textarea.value).toBe("hello world");
      globalExpect(el.value).toBe("hello world");
    });
    it("updates the value when the property is set to a new value", async () => {
      textarea.focus();
      textarea.value = "hello world";
      textarea.dispatchEvent(new InputEvent("input", { bubbles: true }));
      await el.updateComplete;
      globalExpect(el.value).toBe("hello world");
      el.value = "hello there";
      await el.updateComplete;
      globalExpect(textarea.value).toBe("hello there");
      globalExpect(el.value).toBe("hello there");
    });
  });
  describe("input handling", () => {
    it("updates el.value when user types in the input", async () => {
      textarea.value = "hello world";
      textarea.dispatchEvent(new InputEvent("input", { bubbles: true }));
      await el.updateComplete;
      globalExpect(el.value).toBe("hello world");
    });
    it("dispatches input event when user types", async () => {
      const inputHandler = vi.fn();
      el.addEventListener("input", inputHandler);
      textarea.value = "hello world";
      textarea.dispatchEvent(
        new InputEvent("input", { bubbles: true, composed: true })
      );
      await el.updateComplete;
      globalExpect(inputHandler).toHaveBeenCalled();
    });
  });
  describe("change event", () => {
    it("dispatches change event when input value changes and blur occurs", async () => {
      const changeHandler = vi.fn();
      el.addEventListener("change", changeHandler);
      textarea.value = "new value";
      textarea.dispatchEvent(new InputEvent("input", { bubbles: true }));
      textarea.dispatchEvent(new Event("change", { bubbles: true }));
      await el.updateComplete;
      globalExpect(changeHandler).toHaveBeenCalled();
    });
  });
});
//# sourceMappingURL=textarea-field.spec.js.map
