mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 10:08:46 +02:00
Add Playwright assistant regression coverage
This commit is contained in:
33
frontend/e2e/subtitles.ts
Normal file
33
frontend/e2e/subtitles.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
export interface Clip {
|
||||
title: string;
|
||||
caption: string;
|
||||
file: string;
|
||||
startMs: number;
|
||||
endMs: number;
|
||||
narration: { path: string; durationMs: number } | null;
|
||||
}
|
||||
|
||||
export function msToSrtTimestamp(ms: number): string {
|
||||
const clamped = Math.max(0, Math.round(ms));
|
||||
const hours = Math.floor(clamped / 3_600_000);
|
||||
const minutes = Math.floor((clamped % 3_600_000) / 60_000);
|
||||
const seconds = Math.floor((clamped % 60_000) / 1000);
|
||||
const millis = clamped % 1000;
|
||||
const pad = (n: number, len = 2) => String(n).padStart(len, "0");
|
||||
return `${pad(hours)}:${pad(minutes)}:${pad(seconds)},${pad(millis, 3)}`;
|
||||
}
|
||||
|
||||
/** One subtitle cue per step, spanning its full on-screen duration. */
|
||||
export function buildSrt(clips: Clip[]): string {
|
||||
return clips
|
||||
.map((clip, i) => {
|
||||
const index = i + 1;
|
||||
return [
|
||||
String(index),
|
||||
`${msToSrtTimestamp(clip.startMs)} --> ${msToSrtTimestamp(clip.endMs)}`,
|
||||
clip.caption,
|
||||
"",
|
||||
].join("\n");
|
||||
})
|
||||
.join("\n");
|
||||
}
|
||||
Reference in New Issue
Block a user