Files
reader/web/test/platform-server-url.test.ts
hectorqin 73f9eb6e20 feat(media): add isolated media libraries and playback
Support local and OpenList libraries, metadata, independent media navigation, themes, and audio/video playback. Preserve approved v2 prototypes and current documentation; archive superseded review artifacts and keep generated validation output outside version control.
2026-09-27 18:22:51 +08:00

41 lines
1.8 KiB
TypeScript

// @vitest-environment jsdom
import { afterEach, expect, it, vi } from 'vitest';
import { App } from '../src/app.ts';
import { ReaderApi } from '../src/api/client.ts';
afterEach(() => { vi.unstubAllGlobals(); delete window.ReaderAndroid; });
it.each(['web', 'android'])('%s requests use the selected server after platform creation', async host => {
if (host === 'android') window.ReaderAndroid = {
shellVersion: () => 1, connectivity: () => 'online',
watchConnectivity: () => undefined, deviceLabel: () => 'test',
toast: () => undefined, hasNetwork: () => true, viewport: () => '{}',
cacheUsage: () => '{}', diagnostics: () => '{}', renderPage: () => false,
hidePage: () => undefined, canOpenDocument: () => false,
};
const calls: string[] = [];
vi.stubGlobal('fetch', vi.fn(async (url: string) => {
calls.push(url);
return Response.json(url.endsWith('/auth/login') || url.endsWith('/auth/refresh') ? {
user: { id: 'user' }, accessToken: 'test', refreshToken: 'refresh', accessTokenExpiresAt: 0,
} : {});
}));
const context = { options: { defaultServerUrl: '' }, api: undefined as ReaderApi | undefined };
const platform = await Reflect.apply(App.prototype['createPlatform'], context, []);
const api = context.api = new ReaderApi(platform, {
load: async () => null, save: async () => undefined, clear: async () => undefined,
});
api.setBaseUrl('http://first.test:5888/');
await api.login('user', 'password');
await api.renewSessionIfNeeded();
await api.upload([], '', 'skip');
api.setBaseUrl('http://second.test:5888');
await api.instance();
expect(calls).toEqual([
'http://first.test:5888/api/v1/auth/login',
'http://first.test:5888/api/v1/auth/refresh',
'http://first.test:5888/api/v1/library/upload',
'http://second.test:5888/api/v1/instance',
]);
});