Files
Jellify/jest/functional/Shuffle.test.tsx
Violet Caulfield 2961ca39bb Introduction of Transcoding Support (#490)
Implements proper server negotation for performing transcoding

Depending on the user's platform (i.e. iOS, Android) and the desired quality specified in the settings, Jellify will playback a transcoded audio file from Jellyfin

This is helpful when the source audio file is not compatible with the user's device (i.e. playing back an ALAC encoded .M4A on Android) or if the user want to stream at a lower quality to save bandwidth

This also drives downloads in different qualities, meaning the download quality selector in the Settings is now working properly. When a track is downloaded, it will download at the quality selected by the user, and in a format compatible with the device

There is also a toggle in the "Player" Settings for displaying a badge in the player that shows the quality and container of the audio being played
2025-08-28 13:04:38 -05:00

60 lines
2.0 KiB
TypeScript

import 'react-native'
import { shuffleJellifyTracks } from '../../src/providers/Player/utils/shuffle'
import { QueuingType } from '../../src/enums/queuing-type'
import JellifyTrack from '../../src/types/JellifyTrack'
import { BaseItemDto } from '@jellyfin/sdk/lib/generated-client/models'
// Test the shuffle utility function directly
describe('Shuffle Utility Function', () => {
const createMockTracks = (count: number): JellifyTrack[] => {
return Array.from({ length: count }, (_, i) => ({
url: `https://example.com/${i + 1}`,
id: `track-${i + 1}`,
title: `Track ${i + 1}`,
artist: `Artist ${i + 1}`,
duration: 420,
sessionId: 'TEST_SESSION_ID',
sourceType: 'stream',
item: {
Id: `${i + 1}`,
Name: `Track ${i + 1}`,
Artists: [`Artist ${i + 1}`],
} as BaseItemDto,
QueuingType: QueuingType.FromSelection,
}))
}
test('should shuffle tracks correctly', () => {
const tracks = createMockTracks(5)
const result = shuffleJellifyTracks(tracks)
expect(result.shuffled).toHaveLength(5)
expect(result.original).toEqual(tracks)
expect(result.manuallyQueued).toHaveLength(0)
// Verify all tracks are still present (just reordered)
const originalIds = tracks.map((t) => t.item.Id).sort()
const shuffledIds = result.shuffled.map((t) => t.item.Id).sort()
expect(shuffledIds).toEqual(originalIds)
})
test('should handle manually queued tracks correctly', () => {
const tracks = createMockTracks(3)
tracks[1].QueuingType = QueuingType.DirectlyQueued // Make one track manually queued
const result = shuffleJellifyTracks(tracks)
expect(result.shuffled).toHaveLength(2) // Only non-manually queued tracks
expect(result.manuallyQueued).toHaveLength(1)
expect(result.manuallyQueued[0].item.Id).toBe('2')
})
test('should handle empty array', () => {
const result = shuffleJellifyTracks([])
expect(result.shuffled).toHaveLength(0)
expect(result.original).toHaveLength(0)
expect(result.manuallyQueued).toHaveLength(0)
})
})