import "jest";
import { box, constrain } from "../box";

describe(constrain.name, () => {
  it("leaves boxes smaller than the container as-is", () => {
    expect(constrain(box(10, 20), box(30, 30))).toEqual(box(10, 20));
  });

  it("shrinks over-sized tall boxes proportionally to fit", () => {
    expect(constrain(box(40, 120), box(30, 30))).toEqual(box(10, 30));
    expect(constrain(box(40, 120), box(5, 30))).toEqual(box(5, 15));
    expect(constrain(box(40, 120), box(30, 5))).toEqual(box(2, 5));
  });

  it("shrinks over-sized wide boxes proportionally to fit", () => {
    expect(constrain(box(120, 40), box(30, 30))).toEqual(box(30, 10));
    expect(constrain(box(120, 40), box(30, 5))).toEqual(box(15, 5));
    expect(constrain(box(120, 40), box(5, 30))).toEqual(box(5, 2));
  });

  it("rounds fractional values up to the nearest integer", () => {
    expect(constrain(box(100, 1), box(10, 10))).toEqual(box(10, 1));
    expect(constrain(box(1, 100), box(10, 10))).toEqual(box(1, 10));
  });
});
