Files
glchat/web/tests/app.test.tsx
T

82 lines
2.7 KiB
TypeScript
Raw Normal View History

import { describe, expect, it } from 'vitest';
import { screen, waitFor } from '@testing-library/react';
import { installFetch, installFailingFetch, json, renderApp } from './helpers';
import type { InstanceMeta } from '@/api/meta';
const meta: InstanceMeta = {
name: 'glchat',
version: 'v0.1.0-test',
commit: 'deadbee',
build_date: '2026-09-19T00:00:00Z',
api_version: 'v1',
base_url: 'https://gl.localhost',
files_url: 'https://files.gl.localhost',
gateway_url: 'wss://gl.localhost/gateway',
rtc_path: '/rtc',
max_upload_size: 26214400,
features: {
registration_enabled: true,
anti_bot_enabled: false,
voice_enabled: false,
web_push_enabled: false,
passkeys_enabled: false,
oauth_enabled: false,
},
};
const readyBody = { status: 'ready', version: 'test', checks: { database: 'ok' } };
/** Страница состояния — бывший лендинг Фазы 0, перенесён на маршрут /status. */
describe('страница /status', () => {
it('рендерит мету инстанса из API', async () => {
installFetch([
{ match: '/api/v1/meta', response: () => json(meta) },
{ match: '/api/v1/readyz', response: () => json(readyBody) },
]);
renderApp('/status');
await waitFor(() => {
expect(screen.getByText('v0.1.0-test')).toBeInTheDocument();
});
expect(screen.getByText('v1')).toBeInTheDocument();
expect(screen.getByText('25 MB')).toBeInTheDocument();
expect(screen.getByTestId('connection-state')).toHaveTextContent('Сервер доступен');
});
it('локализует ошибку сервера по коду и предлагает повтор', async () => {
installFetch([
{
match: '/api/v1/meta',
response: () => json({ error: { code: 'internal.error', message: 'boom' } }, 500),
},
{ match: '/api/v1/readyz', response: () => json(readyBody) },
]);
renderApp('/status');
await waitFor(
() => {
expect(screen.getByRole('alert')).toHaveTextContent('Внутренняя ошибка сервера.');
},
{ timeout: 5000 },
);
expect(screen.getByRole('button', { name: 'Повторить' })).toBeInTheDocument();
});
it('показывает сообщение о недоступном сервере', async () => {
installFailingFetch();
renderApp('/status');
await waitFor(
() => {
expect(screen.getByRole('alert')).toHaveTextContent('Сервер не отвечает');
},
{ timeout: 5000 },
);
expect(screen.getByTestId('connection-state')).toHaveTextContent('Сервер недоступен');
});
});