import { describe, expect, it } from "vitest";
import { moveBetweenZones, moveWithinZone } from "./overviewReorder";

describe("moveWithinZone", () => {
  it("reorders items within bounds", () => {
    expect(moveWithinZone(["a", "b", "c"], 0, 2)).toEqual(["b", "c", "a"]);
  });

  it("supports moving to end using zone drop target index", () => {
    expect(moveWithinZone(["a", "b", "c"], 1, 3)).toEqual(["a", "c", "b"]);
  });

  it("returns original list when indices are invalid", () => {
    expect(moveWithinZone(["a"], 0, 2)).toEqual(["a"]);
  });
});

describe("moveBetweenZones", () => {
  it("moves one item from source to target at requested index", () => {
    expect(moveBetweenZones(["a", "b"], ["c"], 0, 1)).toEqual({
      sourceItems: ["b"],
      targetItems: ["c", "a"],
    });
  });

  it("returns original zones when source index is invalid", () => {
    expect(moveBetweenZones(["a"], ["b"], 2, 0)).toEqual({
      sourceItems: ["a"],
      targetItems: ["b"],
    });
  });
});
