import { describe, expect, it } from "vitest";
import {
  captureMethodCardCustomizeSnapshot,
  isMethodCardCustomizeUnloadBlocked,
} from "../../lib/create/methodCardCustomizeSession";

const HEADER_0 = { title: "", description: "" };

describe("isMethodCardCustomizeUnloadBlocked", () => {
  it("is false when the modal is closed or snapshot is missing", () => {
    const snap = captureMethodCardCustomizeSnapshot({ x: 1 }, null, HEADER_0);
    expect(
      isMethodCardCustomizeUnloadBlocked(false, snap, { x: 2 }, null, HEADER_0),
    ).toBe(false);
    expect(
      isMethodCardCustomizeUnloadBlocked(true, null, { x: 2 }, null, HEADER_0),
    ).toBe(false);
  });

  it("is true only when the open modal is dirty", () => {
    const snap = captureMethodCardCustomizeSnapshot({ x: 1 }, null, HEADER_0);
    expect(
      isMethodCardCustomizeUnloadBlocked(true, snap, { x: 1 }, null, HEADER_0),
    ).toBe(false);
    expect(
      isMethodCardCustomizeUnloadBlocked(true, snap, { x: 2 }, null, HEADER_0),
    ).toBe(true);
  });
});
