54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import { StepReplayFrame } from '../core/models/stream.model';
|
|
import { TimelineSegment } from './recording-timeline.util';
|
|
import { buildVideoStepMarkers } from './video-step-markers.util';
|
|
|
|
describe('buildVideoStepMarkers', () => {
|
|
const start = 1_800_000_000;
|
|
const segments: TimelineSegment[] = [
|
|
{ start: 0, duration: 10, offset_ms: 1000, duration_ms: 10000 },
|
|
{ start: 10, duration: 10, offset_ms: 13000, duration_ms: 10000 }
|
|
];
|
|
const frame = (stepNumber: number, seconds: number, status = 'dispatched'): StepReplayFrame => ({
|
|
index: stepNumber - 1,
|
|
stepNumber,
|
|
title: `步骤 ${stepNumber}`,
|
|
imageUrl: 'step.png',
|
|
timestamp: start + seconds,
|
|
status
|
|
});
|
|
|
|
it('places markers on the playable timeline across recording restart gaps', () => {
|
|
const markers = buildVideoStepMarkers([frame(1, 4), frame(2, 15)], start, segments, 20);
|
|
expect(markers.map((marker) => marker.time)).toEqual([3, 12]);
|
|
expect(markers.map((marker) => marker.percent)).toEqual([15, 60]);
|
|
});
|
|
|
|
it('snaps a step in a recording gap to the following segment', () => {
|
|
const markers = buildVideoStepMarkers([frame(1, 12)], start, segments, 20);
|
|
expect(markers[0].time).toBe(10);
|
|
});
|
|
|
|
it('omits steps outside the actual recording and without timestamps', () => {
|
|
const missing = { ...frame(4, 5), timestamp: undefined };
|
|
const markers = buildVideoStepMarkers(
|
|
[frame(1, 0), frame(2, 2), frame(3, 24), missing], start, segments, 20
|
|
);
|
|
expect(markers.map((marker) => marker.steps[0].stepNumber)).toEqual([2]);
|
|
});
|
|
|
|
it('groups crowded steps and keeps failure information', () => {
|
|
const markers = buildVideoStepMarkers(
|
|
[frame(1, 4), frame(2, 4.1, 'failed'), frame(3, 8)], start, segments, 20
|
|
);
|
|
expect(markers.length).toBe(2);
|
|
expect(markers[0].steps.map((step) => step.stepNumber)).toEqual([1, 2]);
|
|
expect(markers[0].failed).toBeTrue();
|
|
});
|
|
|
|
it('uses session seconds directly for a legacy playlist or single video', () => {
|
|
expect(buildVideoStepMarkers([frame(1, 6)], start, [{ start: 0, duration: 20 }], 20)[0].time).toBe(6);
|
|
expect(buildVideoStepMarkers([frame(1, 6)], start, [], 20)[0].time).toBe(6);
|
|
expect(buildVideoStepMarkers([frame(1, 6)], undefined, [], 20)).toEqual([]);
|
|
});
|
|
});
|