import { createRoot } from "solid-js";
import { describe, expect, it } from "vitest";
import { createRegisterId } from "../../src/primitives/create-register-id";

describe("createRegisterId", () => {
  it("starts with undefined", () => {
    createRoot((dispose) => {
      const [getId] = createRegisterId();
      expect(getId()).toBeUndefined();
      dispose();
    });
  });

  it("returns registered id after set", () => {
    createRoot((dispose) => {
      const [getId, setId] = createRegisterId();
      setId("my-id");
      expect(getId()).toBe("my-id");
      dispose();
    });
  });

  it("returns undefined after clearing", () => {
    createRoot((dispose) => {
      const [getId, setId] = createRegisterId();
      setId("my-id");
      setId(undefined);
      expect(getId()).toBeUndefined();
      dispose();
    });
  });
});
