32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { describe, it } from "node:test"
|
|
import { computeImageInsertFrameSize } from "./docs-graphic-image-size.ts"
|
|
|
|
describe("docs-graphic-image-size", () => {
|
|
it("preserves aspect ratio for landscape images", () => {
|
|
const frame = computeImageInsertFrameSize(1920, 1080)
|
|
assert.equal(frame.width, 560)
|
|
assert.equal(frame.height, 315)
|
|
assert.ok(Math.abs(frame.width / frame.height - 1920 / 1080) < 0.02)
|
|
})
|
|
|
|
it("preserves aspect ratio for portrait images", () => {
|
|
const frame = computeImageInsertFrameSize(1080, 1920)
|
|
assert.equal(frame.height, 720)
|
|
assert.equal(frame.width, 405)
|
|
assert.ok(Math.abs(frame.width / frame.height - 1080 / 1920) < 0.02)
|
|
})
|
|
|
|
it("keeps small images at natural size", () => {
|
|
const frame = computeImageInsertFrameSize(200, 150)
|
|
assert.equal(frame.width, 200)
|
|
assert.equal(frame.height, 150)
|
|
})
|
|
|
|
it("falls back when natural size is invalid", () => {
|
|
const frame = computeImageInsertFrameSize(0, 0)
|
|
assert.equal(frame.width, 240)
|
|
assert.equal(frame.height, 160)
|
|
})
|
|
})
|