Add typed API wrappers (api/logs.ts, api/troubleshoot.ts) and two new screens: LogsScreen (paged, level-badged, server-side filtered log table) and TroubleshootingScreen (General JSON viewer with copy, plus per-platform NVIDIA/QSV/VAAPI/VideoToolbox capability tabs when populated). Both are registered under a new "System" nav group in App.tsx alongside Settings. Settings' Classic UI help text and About card now point at the new screens instead of the Blazor logs/troubleshooting pages.
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { getLogs } from './logs';
|
|
|
|
const samplePage = {
|
|
totalCount: 2,
|
|
page: [
|
|
{ timestamp: '2026-07-07T00:00:00Z', level: 'Warning', message: 'uh oh' },
|
|
{ timestamp: '2026-07-07T00:01:00Z', level: 'Information', message: 'all good' }
|
|
]
|
|
};
|
|
|
|
describe('getLogs', () => {
|
|
beforeEach(() => {
|
|
window.localStorage.clear();
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it('GETs /api/logs with no query string when called without params', async () => {
|
|
const fetchSpy = vi.spyOn(window, 'fetch').mockResolvedValue(
|
|
new Response(JSON.stringify(samplePage), {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
status: 200
|
|
})
|
|
);
|
|
|
|
await expect(getLogs()).resolves.toMatchObject({ totalCount: 2 });
|
|
|
|
const [url, init] = fetchSpy.mock.calls[0];
|
|
expect(url).toBe('/api/logs');
|
|
expect((init?.method ?? 'GET').toUpperCase()).toBe('GET');
|
|
});
|
|
|
|
it('builds the query string from filter, pageNum and pageSize', async () => {
|
|
const fetchSpy = vi.spyOn(window, 'fetch').mockResolvedValue(
|
|
new Response(JSON.stringify(samplePage), {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
status: 200
|
|
})
|
|
);
|
|
|
|
await getLogs({ filter: 'boom', pageNum: 2, pageSize: 50 });
|
|
|
|
const [url] = fetchSpy.mock.calls[0];
|
|
expect(url).toBe('/api/logs?filter=boom&pageNum=2&pageSize=50');
|
|
});
|
|
|
|
it('rejects with the ApiError status on failure', async () => {
|
|
vi.spyOn(window, 'fetch').mockResolvedValue(
|
|
new Response(JSON.stringify({ status: 500, title: 'Server Error' }), {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
status: 500
|
|
})
|
|
);
|
|
|
|
await expect(getLogs()).rejects.toMatchObject({ status: 500 });
|
|
});
|
|
});
|