import { describe, expect, it } from "vitest";
import { clampScanLimit, clampSkipRows, resolveScanTargetCount } from "./scannerSession";

describe("scannerSession helpers", () => {
  it("clamps scan target counts into a sane range", () => {
    expect(clampScanLimit(0)).toBe(1);
    expect(clampScanLimit(2500)).toBe(1800);
  });

  it("respects the manual scan limit and only caps it against the detected inventory count", () => {
    expect(resolveScanTargetCount(16, 124)).toBe(16);
    expect(resolveScanTargetCount(200, 124)).toBe(124);
    expect(resolveScanTargetCount(16, 0)).toBe(16);
    expect(resolveScanTargetCount(16, null)).toBe(16);
  });

  it("keeps skipped rows within the visible grid range", () => {
    expect(clampSkipRows(-5)).toBe(0);
    expect(clampSkipRows(99)).toBe(8);
  });
});
