Skip to content

The open-source app everyone uses to manage agents at work

1.0 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { fitPrint } from "./ArtifactPrint";
import { SINGLE_BOX, STACK_BOX } from "./geometry";

describe("fitPrint", () => {
  it("fits a landscape print to the stack box by width and a portrait one by height", () => {
    expect(fitPrint(4 / 3, STACK_BOX)).toEqual({ width: 245, height: 183.75, border: 3.3 });
    expect(fitPrint(3 / 4, STACK_BOX)).toEqual({ width: 165, height: 220, border: 3.3 });
  });

  it("never lets a print grow past the box", () => {
    for (const aspect of [0.5, 1, 2, 16 / 9]) {
      const print = fitPrint(aspect, STACK_BOX);
      expect(print.width).toBeLessThanOrEqual(STACK_BOX.maxWidth);
      expect(print.height).toBeLessThanOrEqual(STACK_BOX.maxHeight);
      expect(print.width / print.height).toBeCloseTo(aspect, 2);
    }
  });

  it("assumes 4:3 until the picture's ratio is known", () => {
    expect(fitPrint(null, SINGLE_BOX)).toEqual({ width: 240, height: 180, border: 4 });
    expect(fitPrint(0, SINGLE_BOX)).toEqual(fitPrint(undefined, SINGLE_BOX));
  });
});