// DetailAccountWizard — unit tests (Issue #215).
//
// NOTE: this project has no jsdom / @testing-library harness (see
// SecurityPicker.test.ts, StarterAccountsModal.test.tsx). We exercise the pure
// toggle-payload builder — the load-bearing decision of the wizard — directly.
// DOM rendering / the confirm click are not exercised here; the wizard is thin
// orchestration over `buildDetailToggleInput` + `updateBalanceAccount`.

import { describe, it, expect } from "vitest";
import { buildDetailToggleInput } from "./DetailAccountWizard";

describe("buildDetailToggleInput", () => {
  it("flips kind to detailed and pins the pivot to today's local civil day", () => {
    // 2026-06-06 in the local civil day (midday avoids any DST edge confusion).
    const today = new Date(2026, 5, 6, 12, 30, 0);
    const input = buildDetailToggleInput(today);
    expect(input).toEqual({ kind: "detailed", detailed_since: "2026-06-06" });
  });

  it("zero-pads single-digit month and day to a YYYY-MM-DD snapshot shape", () => {
    // January 2nd → "2026-01-02", matching normalizeSnapshotDate's ISO regex.
    const today = new Date(2026, 0, 2, 9, 0, 0);
    const input = buildDetailToggleInput(today);
    expect(input.detailed_since).toBe("2026-01-02");
    expect(input.kind).toBe("detailed");
  });

  it("never emits a detailed → simple downgrade or an envelope mutation", () => {
    const input = buildDetailToggleInput(new Date(2026, 11, 31, 23, 0, 0));
    // Only the two pivot fields are set; vehicle_type/name/etc. stay untouched
    // so updateBalanceAccount's read-and-rewrite preserves them.
    expect(Object.keys(input).sort()).toEqual(["detailed_since", "kind"]);
    expect(input.kind).not.toBe("simple");
  });
});
