import { beforeEach, describe, expect, it } from "vitest";
import { clearDraft, emptyDraft, loadDraft, saveDraft } from "./wizardState";

describe("wizard draft scopes", () => {
  beforeEach(() => localStorage.clear());

  it("keeps new and existing play drafts isolated", () => {
    const newDraft = { ...emptyDraft(), title: "New play" };
    const existingDraft = { ...emptyDraft(), title: "Existing play", playId: "play-42" };

    saveDraft(newDraft, "new");
    saveDraft(existingDraft, "play-42");

    expect(loadDraft("new")).toEqual(newDraft);
    expect(loadDraft("play-42")).toEqual(existingDraft);
  });

  it("clears only the requested draft scope", () => {
    const existingDraft = { ...emptyDraft(), title: "Keep me", playId: "play-42" };
    saveDraft({ ...emptyDraft(), title: "Discard me" }, "new");
    saveDraft(existingDraft, "play-42");

    clearDraft("new");

    expect(loadDraft("new")).toMatchObject({ title: "", stepIndex: 0 });
    expect(loadDraft("play-42")).toEqual(existingDraft);
  });
});
