Merge branch 'master' into streaming-bitrate-add-max
This commit is contained in:
@@ -1,35 +1,36 @@
|
||||
import type { FolderStorageDto } from '@jellyfin/sdk/lib/generated-client/models/folder-storage-dto';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { calculateUsedPercentage, calculateTotal } from './space';
|
||||
|
||||
describe('calculateTotal()', () => {
|
||||
it('should return the total', () => {
|
||||
expect(calculateTotal({ FreeSpace: 1, UsedSpace: 2 })).toBe(3);
|
||||
expect(calculateTotal({ FreeSpace: 1, UsedSpace: 2 } as FolderStorageDto)).toBe(3);
|
||||
});
|
||||
|
||||
it('should return -1 for invalid used space values', () => {
|
||||
expect(calculateTotal({ FreeSpace: 1 })).toBe(-1);
|
||||
expect(calculateTotal({ FreeSpace: 1, UsedSpace: -1 })).toBe(-1);
|
||||
expect(calculateTotal({ FreeSpace: 1 } as FolderStorageDto)).toBe(-1);
|
||||
expect(calculateTotal({ FreeSpace: 1, UsedSpace: -1 } as FolderStorageDto)).toBe(-1);
|
||||
});
|
||||
|
||||
it('should treat invalid free space values as 0', () => {
|
||||
expect(calculateTotal({ UsedSpace: 1 })).toBe(1);
|
||||
expect(calculateTotal({ FreeSpace: -1, UsedSpace: 1 })).toBe(1);
|
||||
expect(calculateTotal({ UsedSpace: 1 } as FolderStorageDto)).toBe(1);
|
||||
expect(calculateTotal({ FreeSpace: -1, UsedSpace: 1 } as FolderStorageDto)).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('calculateUsedPercentage', () => {
|
||||
it('should return the percentage used', () => {
|
||||
expect(calculateUsedPercentage({ FreeSpace: 1, UsedSpace: 3 })).toBe(75);
|
||||
expect(calculateUsedPercentage({ FreeSpace: 1, UsedSpace: 3 } as FolderStorageDto)).toBe(75);
|
||||
});
|
||||
|
||||
it('should return 0 for invalid used space values', () => {
|
||||
expect(calculateUsedPercentage({ FreeSpace: 1 })).toBe(0);
|
||||
expect(calculateUsedPercentage({ FreeSpace: 1, UsedSpace: -1 })).toBe(0);
|
||||
expect(calculateUsedPercentage({ FreeSpace: 1 } as FolderStorageDto)).toBe(0);
|
||||
expect(calculateUsedPercentage({ FreeSpace: 1, UsedSpace: -1 } as FolderStorageDto)).toBe(0);
|
||||
});
|
||||
|
||||
it('should return 100 for invalid free space values', () => {
|
||||
expect(calculateUsedPercentage({ UsedSpace: 1 })).toBe(100);
|
||||
expect(calculateUsedPercentage({ FreeSpace: -1, UsedSpace: 1 })).toBe(100);
|
||||
expect(calculateUsedPercentage({ UsedSpace: 1 } as FolderStorageDto)).toBe(100);
|
||||
expect(calculateUsedPercentage({ FreeSpace: -1, UsedSpace: 1 } as FolderStorageDto)).toBe(100);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ import type { NullableString } from 'types/base/common/shared/types';
|
||||
import type { ItemDto } from 'types/base/models/item-dto';
|
||||
|
||||
interface PlayAllFromHereOptions {
|
||||
item: ItemDto;
|
||||
item?: ItemDto;
|
||||
items: ItemDto[];
|
||||
serverId: NullableString;
|
||||
queue?: boolean;
|
||||
@@ -166,7 +166,7 @@ const MoreCommandsButton: FC<MoreCommandsButtonProps> = ({
|
||||
serverId: item?.ServerId
|
||||
});
|
||||
playAllFromHere({
|
||||
item: item || {},
|
||||
item: item,
|
||||
items: items || [],
|
||||
serverId: item?.ServerId
|
||||
}).catch(err => {
|
||||
@@ -174,7 +174,7 @@ const MoreCommandsButton: FC<MoreCommandsButtonProps> = ({
|
||||
});
|
||||
} else if (result.command === 'queueallfromhere') {
|
||||
playAllFromHere({
|
||||
item: item || {},
|
||||
item: item,
|
||||
items: items || [],
|
||||
serverId: item?.ServerId,
|
||||
queue: true
|
||||
|
||||
@@ -47,7 +47,7 @@ export function getImageUrl(item: ItemDto, options: ImageOptions = {}) {
|
||||
const itemId = item.PrimaryImageItemId || item.Id;
|
||||
|
||||
if (itemId && item.ImageTags?.[options.type]) {
|
||||
options.tag = item.ImageTags[options.type];
|
||||
options.tag = item.ImageTags[options.type] ?? undefined;
|
||||
return ServerConnections.getApiClient(item.ServerId).getScaledImageUrl(itemId, options);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { getItemTextLines } from './itemText';
|
||||
|
||||
describe('getItemTextLines', () => {
|
||||
it('Should return undefined if item is invalid', () => {
|
||||
let lines = getItemTextLines({});
|
||||
let lines = getItemTextLines({} as ItemDto);
|
||||
expect(lines).toBeUndefined();
|
||||
lines = getItemTextLines(null);
|
||||
expect(lines).toBeUndefined();
|
||||
@@ -16,9 +16,9 @@ describe('getItemTextLines', () => {
|
||||
});
|
||||
|
||||
it('Should return the name and index number', () => {
|
||||
const item: ItemDto = {
|
||||
const item = {
|
||||
Name: 'Item Name'
|
||||
};
|
||||
} as ItemDto;
|
||||
let lines = getItemTextLines(item);
|
||||
expect(lines).toBeDefined();
|
||||
expect(lines).toHaveLength(1);
|
||||
@@ -39,13 +39,13 @@ describe('getItemTextLines', () => {
|
||||
});
|
||||
|
||||
it('Should add artist names', () => {
|
||||
let item: ItemDto = {
|
||||
let item = {
|
||||
Name: 'Item Name',
|
||||
ArtistItems: [
|
||||
{ Name: 'Artist 1' },
|
||||
{ Name: 'Artist 2' }
|
||||
]
|
||||
};
|
||||
} as ItemDto;
|
||||
let lines = getItemTextLines(item);
|
||||
expect(lines).toBeDefined();
|
||||
expect(lines).toHaveLength(2);
|
||||
@@ -58,7 +58,7 @@ describe('getItemTextLines', () => {
|
||||
'Artist 1',
|
||||
'Artist 2'
|
||||
]
|
||||
};
|
||||
} as ItemDto;
|
||||
lines = getItemTextLines(item);
|
||||
expect(lines).toBeDefined();
|
||||
expect(lines).toHaveLength(2);
|
||||
@@ -67,10 +67,10 @@ describe('getItemTextLines', () => {
|
||||
});
|
||||
|
||||
it('Should add album or series name', () => {
|
||||
let item: ItemDto = {
|
||||
let item = {
|
||||
Name: 'Item Name',
|
||||
SeriesName: 'Series'
|
||||
};
|
||||
} as ItemDto;
|
||||
let lines = getItemTextLines(item);
|
||||
expect(lines).toBeDefined();
|
||||
expect(lines).toHaveLength(2);
|
||||
@@ -80,7 +80,7 @@ describe('getItemTextLines', () => {
|
||||
item = {
|
||||
Name: 'Item Name',
|
||||
Album: 'Album'
|
||||
};
|
||||
} as ItemDto;
|
||||
lines = getItemTextLines(item);
|
||||
expect(lines).toBeDefined();
|
||||
expect(lines).toHaveLength(2);
|
||||
@@ -92,7 +92,7 @@ describe('getItemTextLines', () => {
|
||||
const item = {
|
||||
Name: 'Item Name',
|
||||
ProductionYear: 2025
|
||||
};
|
||||
} as ItemDto;
|
||||
const lines = getItemTextLines(item);
|
||||
expect(lines).toBeDefined();
|
||||
expect(lines).toHaveLength(2);
|
||||
|
||||
Reference in New Issue
Block a user