56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { test } from 'node:test'
|
|
import { nextMusicTrack } from '../src/utils/musicGroups.js'
|
|
import { parsePlaylistGroups } from './playlist-groups.js'
|
|
import type { MusicGroup } from '../src/types/screen.js'
|
|
|
|
const groups: MusicGroup[] = [
|
|
{ id: 1, name: 'First', position: 0, endMode: 'repeat' },
|
|
{ id: 2, name: 'Empty', position: 1, endMode: 'repeat' },
|
|
{ id: 3, name: 'Final', position: 2, endMode: 'stop' },
|
|
]
|
|
for (const tc of [
|
|
{ name: 'within group', index: 0, groupId: 1, mode: 'stop', want: { index: 2, groupId: 1 } },
|
|
{ name: 'repeat', index: 2, groupId: 1, mode: 'repeat', want: { index: 0, groupId: 1 } },
|
|
{ name: 'stop overrides whole loop', index: 2, groupId: 1, mode: 'stop', want: null },
|
|
{ name: 'skip empty', index: 2, groupId: 1, mode: 'next', want: { index: 1, groupId: 3 } },
|
|
{ name: 'last stops', index: 1, groupId: 3, mode: 'repeat', want: null },
|
|
{ name: 'whole playlist', index: 0, groupId: 0, mode: 'stop', want: { index: 1, groupId: 0 } },
|
|
{
|
|
name: 'whole playlist loops',
|
|
index: 2,
|
|
groupId: 0,
|
|
mode: 'stop',
|
|
want: { index: 0, groupId: 0 },
|
|
},
|
|
] as const) {
|
|
test(`next music: ${tc.name}`, () => {
|
|
const playlist = {
|
|
tracks: [{ groupId: 1 }, { groupId: 3 }, { groupId: 1 }],
|
|
groups: groups.map((group) => (group.id === 1 ? { ...group, endMode: tc.mode } : group)),
|
|
}
|
|
assert.deepEqual(nextMusicTrack(playlist, tc.index, tc.groupId, true), tc.want)
|
|
})
|
|
}
|
|
test('group parser normalizes omitted repeat and sorts by position', () => {
|
|
assert.deepEqual(
|
|
parsePlaylistGroups([
|
|
{ ID: 2, name: 'B', position: 5, endMode: 2 },
|
|
{ ID: 1, name: 'A' },
|
|
]).map((group) => [group.id, group.endMode]),
|
|
[
|
|
[1, 'repeat'],
|
|
[2, 'next'],
|
|
],
|
|
)
|
|
for (const value of [
|
|
[{ ID: 1, name: 'A', endMode: 'unknown' }],
|
|
[
|
|
{ ID: 1, name: 'A' },
|
|
{ ID: 1, name: 'B' },
|
|
],
|
|
[{ ID: 1, name: 'A', position: -1 }],
|
|
])
|
|
assert.throws(() => parsePlaylistGroups(value))
|
|
})
|