feat(library): sort by rating and priority

This commit is contained in:
lobo committed 2026-09-24 13:17:12 +02:00
1 parent bad11807e0
commit 03259d0515
4 files changed
+27 -12

No files matched your search

+2
View File
@@ -26,6 +26,8 @@ const SORT_OPTIONS = [
{value: 'playtimeMinutes,asc', labelKey: 'LIBRARY.SORT_PLAYTIME_ASC'},
{value: 'lastSeenAt,desc', labelKey: 'LIBRARY.SORT_LAST_SEEN'},
{value: 'firstSeenAt,desc', labelKey: 'LIBRARY.SORT_FIRST_SEEN'},
{value: 'rating,desc', labelKey: 'LIBRARY.SORT_RATING'},
{value: 'priority,desc', labelKey: 'LIBRARY.SORT_PRIORITY'},
];
export default function GameLibrary() {
+19 -10
View File
@@ -39,17 +39,17 @@ function renderLibrary(initialEntry = '/library') {
const typeInto = (value) => fireEvent.change(screen.getByRole('searchbox'), {target: {value}});
beforeEach(() => {
localStorage.setItem('tbp_jwt', 'token');
globalThis.fetch = vi.fn(async () => ({ok: true, status: 200, json: async () => page}));
});
afterEach(() => {
cleanup();
localStorage.clear();
});
describe('GameLibrary search', () => {
beforeEach(() => {
localStorage.setItem('tbp_jwt', 'token');
globalThis.fetch = vi.fn(async () => ({ok: true, status: 200, json: async () => page}));
});
afterEach(() => {
cleanup();
localStorage.clear();
});
it('writes the trimmed search to the URL after the delay and resets the page', async () => {
const lib = renderLibrary('/library?page=3');
@@ -93,3 +93,12 @@ describe('GameLibrary search', () => {
await waitFor(() => expect(screen.getByRole('searchbox').value).toBe(''));
});
});
describe('GameLibrary sort', () => {
it.each(['rating,desc', 'priority,desc'])('sends the sort %s from the URL', async (sort) => {
renderLibrary(`/library?sort=${encodeURIComponent(sort)}`);
await waitFor(() => expect(fetch).toHaveBeenCalled());
expect(new URL(fetch.mock.calls[0][0], 'http://x').searchParams.get('sort')).toBe(sort);
});
});