Files
siftlode/frontend/src/lib/timecode.test.ts
T
peter c489b60c8b fix(clip): clip mode keeps its range, its focus and its keys through the player's own moves
- A mark on the very end seeks a moment short of it; while a clip is marked the end of the item
  neither closes the player nor steps the queue, and Plex's auto-skip waits.
- Plex: Escape and Back peel what is over the picture (info, up-next, the countdown) before the
  clip; Back under a dialog is the dialog's; no range opens while the length is unknown.
- YouTube: the focus goes back to the scissors the user can see, else the player; the panel keeps
  its name, Loop and focus when the view is maximised or restored under it.
- A typed time stays in its field until taken, then shows where it landed; unreadable stays marked
  invalid; a decimal comma is read (ui/TimecodeField, the editor's fields too).
- RangeTrack: a drag is its pointer's, a cancelled drag reports final, an adornment sits beside the
  slider, a caller-chosen focus ring (amber on the clip strip). CropFrame: a drag is its pointer's.
- The editor's remove-cut is a real button at the cut's foot; a segment's keep toggle sits over the
  cut's hit area.
2026-10-10 15:35:21 +02:00

42 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { formatTimecode, parseTimecode } from "./timecode";
describe("formatTimecode", () => {
it("is m:ss.d below an hour and h:mm:ss.d from one", () => {
expect(formatTimecode(12.44)).toBe("0:12.4");
expect(formatTimecode(75)).toBe("1:15.0");
expect(formatTimecode(3723.4)).toBe("1:02:03.4");
});
it("shows hours when the item reaches one, so an item's fields agree", () => {
expect(formatTimecode(65, true)).toBe("0:01:05.0");
});
it("carries a rounded tenth into the next second, never a 60.0", () => {
expect(formatTimecode(59.96)).toBe("1:00.0");
});
it("reads a bad clock as zero", () => {
expect(formatTimecode(NaN)).toBe("0:00.0");
expect(formatTimecode(-3)).toBe("0:00.0");
});
});
describe("parseTimecode", () => {
it("reads every shape it writes, and bare seconds", () => {
expect(parseTimecode("0:12.4")).toBeCloseTo(12.4);
expect(parseTimecode("1:02:03.4")).toBeCloseTo(3723.4);
expect(parseTimecode(" 90.5 ")).toBeCloseTo(90.5);
});
it("takes a decimal comma, in the seconds only", () => {
expect(parseTimecode("1:02,5")).toBeCloseTo(62.5);
expect(parseTimecode("12,4")).toBeCloseTo(12.4);
});
it("is null for what is not a timecode", () => {
for (const v of ["", "abc", "1::2", "1:2:3:4", "-5", "1:-2", "1,5:00", "1:02,5,5"])
expect(parseTimecode(v)).toBeNull();
});
});