Public Access
Gitea #34 slice 2 of 3. Core lists each set once now. The hide duplicates toggle and its param are not needed. PlatformIcons shows a badge per platform (platforms[]).
70 lines
2.8 KiB
JavaScript
70 lines
2.8 KiB
JavaScript
import {describe, expect, it} from 'vitest';
|
|
import {backlogShare, libraryQuery, NO_PRIORITY, parseSources, parseStatus, toBacklogRequest} from './backlog.js';
|
|
|
|
describe('toBacklogRequest', () => {
|
|
it('sends every field', () => {
|
|
expect(toBacklogRequest({status: 'FINISHED', rating: 4, notes: 'Great', priority: 'HIGH'}))
|
|
.toEqual({status: 'FINISHED', rating: 4, notes: 'Great', priority: 'HIGH'});
|
|
});
|
|
|
|
it('sends null for cleared fields', () => {
|
|
expect(toBacklogRequest({status: 'BACKLOG', rating: 0, notes: ' ', priority: NO_PRIORITY}))
|
|
.toEqual({status: 'BACKLOG', rating: null, notes: null, priority: null});
|
|
});
|
|
});
|
|
|
|
describe('parseStatus', () => {
|
|
it('accepts a known status only', () => {
|
|
expect(parseStatus('PLAYING')).toBe('PLAYING');
|
|
expect(parseStatus('playing')).toBeNull();
|
|
expect(parseStatus(null)).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('libraryQuery', () => {
|
|
it('leaves out empty filters', () => {
|
|
expect(libraryQuery({page: 0, size: 20, sort: 'playtimeMinutes,desc', status: null, q: ' '}))
|
|
.toBe('page=0&size=20&sort=playtimeMinutes%2Cdesc');
|
|
});
|
|
|
|
it('adds the time-to-beat limit', () => {
|
|
expect(libraryQuery({page: 0, size: 20, sort: 'appid,asc', status: null, q: '', maxMinutes: 600}))
|
|
.toBe('page=0&size=20&sort=appid%2Casc&maxMinutes=600');
|
|
});
|
|
|
|
it('adds status and the trimmed, encoded search', () => {
|
|
expect(libraryQuery({page: 1, size: 40, sort: 'appid,asc', status: 'DROPPED', q: ' 100% & more '}))
|
|
.toBe('page=1&size=40&sort=appid%2Casc&status=DROPPED&q=100%25+%26+more');
|
|
});
|
|
});
|
|
|
|
describe('backlogShare', () => {
|
|
it('is the rounded backlog percent of the library', () => {
|
|
expect(backlogShare({total: 3, byStatus: {BACKLOG: 2}})).toBe(67);
|
|
});
|
|
|
|
it('uses the pile without coming games when Core sends it', () => {
|
|
expect(backlogShare({total: 4, byStatus: {BACKLOG: 3}, pileGames: 1})).toBe(25);
|
|
});
|
|
|
|
it('is 0 for an empty library', () => {
|
|
expect(backlogShare({total: 0, byStatus: {BACKLOG: 0}})).toBe(0);
|
|
expect(backlogShare(null)).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('sources', () => {
|
|
it('parseSources_KeepsKnownValuesInOrder', () => {
|
|
expect(parseSources('PSN,FOO,STEAM,PSN')).toEqual(['STEAM', 'PSN']);
|
|
expect(parseSources(null)).toEqual([]);
|
|
expect(parseSources('')).toEqual([]);
|
|
});
|
|
|
|
it('libraryQuery_SetsSourceOnlyWhenSelected', () => {
|
|
const base = {page: 0, size: 20, sort: 'appid,asc', status: null, q: ''};
|
|
expect(libraryQuery({...base, source: 'STEAM,PSN'})).toBe('page=0&size=20&sort=appid%2Casc&source=STEAM%2CPSN');
|
|
expect(libraryQuery({...base, source: ''})).not.toContain('source');
|
|
expect(libraryQuery(base)).not.toContain('source');
|
|
});
|
|
});
|