Skip to content

Commit

Permalink
Add tests for segment utils
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill committed Oct 9, 2024
1 parent b934500 commit 9aeb64e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/apps/stable/features/playback/utils/mediaSegments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { MediaSegmentDto } from '@jellyfin/sdk/lib/generated-client/models/media-segment-dto';
import { MediaSegmentType } from '@jellyfin/sdk/lib/generated-client/models/media-segment-type';
import { describe, expect, it } from 'vitest';

import { findCurrentSegment } from './mediaSegments';

const TEST_SEGMENTS: MediaSegmentDto[] = [
{
Id: 'intro',
Type: MediaSegmentType.Intro,
StartTicks: 0,
EndTicks: 10
},
{
Id: 'preview',
Type: MediaSegmentType.Preview,
StartTicks: 20,
EndTicks: 30
},
{
Id: 'recap',
Type: MediaSegmentType.Recap,
StartTicks: 30,
EndTicks: 40
},
{
Id: 'commercial',
Type: MediaSegmentType.Commercial,
StartTicks: 40,
EndTicks: 50
},
{
Id: 'outro',
Type: MediaSegmentType.Outro,
StartTicks: 50,
EndTicks: 60
}
];

describe('findCurrentSegment()', () => {
it('Should return the current segment', () => {
let segmentDetails = findCurrentSegment(TEST_SEGMENTS, 23);
expect(segmentDetails).toBeDefined();
expect(segmentDetails?.index).toBe(1);
expect(segmentDetails?.segment?.Id).toBe('preview');

segmentDetails = findCurrentSegment(TEST_SEGMENTS, 5, 1);
expect(segmentDetails).toBeDefined();
expect(segmentDetails?.index).toBe(0);
expect(segmentDetails?.segment?.Id).toBe('intro');

segmentDetails = findCurrentSegment(TEST_SEGMENTS, 42, 3);
expect(segmentDetails).toBeDefined();
expect(segmentDetails?.index).toBe(3);
expect(segmentDetails?.segment?.Id).toBe('commercial');
});

it('Should return undefined if not in a segment', () => {
let segmentDetails = findCurrentSegment(TEST_SEGMENTS, 16);
expect(segmentDetails).toBeUndefined();

segmentDetails = findCurrentSegment(TEST_SEGMENTS, 10, 1);
expect(segmentDetails).toBeUndefined();

segmentDetails = findCurrentSegment(TEST_SEGMENTS, 100);
expect(segmentDetails).toBeUndefined();
});
});

0 comments on commit 9aeb64e

Please sign in to comment.