Files
labelmain/app/component/label/ffmpeg/cap.test.ts
2026-02-03 18:05:47 +08:00

19 lines
554 B
TypeScript

import { appendCapped } from "./cap"
describe("appendCapped", () => {
test("keeps all items when under max", () => {
expect(appendCapped([1, 2], [3], 10)).toEqual([1, 2, 3])
})
test("drops from head when exceeding max", () => {
expect(appendCapped([1, 2], [3, 4, 5], 3)).toEqual([3, 4, 5])
})
test("calls onDrop for dropped items", () => {
const dropped: number[] = []
const result = appendCapped([1, 2], [3, 4, 5], 3, (x) => dropped.push(x))
expect(result).toEqual([3, 4, 5])
expect(dropped).toEqual([1, 2])
})
})