moex-vibe/apps/frontend/src/pages/BondPage.test.tsx
Sergey Krylov 729e94b4db
Some checks failed
CI / lint (pull_request) Failing after 1m53s
CI / test (pull_request) Failing after 1m45s
CI / build (pull_request) Failing after 1m44s
CI / lint (push) Failing after 1m39s
CI / test (push) Failing after 1m40s
CI / build (push) Failing after 1m34s
test: add 95 frontend unit tests with vitest, RTL, and MSW
95 tests across 22 files covering all frontend modules:
- API layer: client, auth
- Components: BondDetails, Layout, PriceChart, ProtectedRoute, SearchBar, StockDetails
- Context: AuthContext
- Hooks: useAuth, useBond, useBondCandles, useSearch, useStock, useStockCandles, useStockDividends
- Pages: BondPage, HomePage, LoginPage, ProfilePage, RegisterPage, StockPage

Infrastructure:
- vitest + @testing-library/react + MSW v2 with 13 API handlers
- Co-located test files alongside source files
- Test utilities: setup, server, factories, test-utils
- BrowserRouter future flags for MemoryRouter test compatibility
- Root test:frontend script for workspace-wide execution
2026-06-14 08:27:15 +03:00

49 lines
1.5 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { screen } from '@testing-library/react';
import { Routes, Route } from 'react-router-dom';
import { http, HttpResponse } from 'msw';
import { server } from '../test/server';
import { BondPage } from './BondPage';
import { renderWithProviders } from '../test/test-utils';
const API = '/api/v1';
function renderBondPage(secid = 'SU26238RMFS5') {
return renderWithProviders(
<Routes>
<Route path="/bonds/:secid" element={<BondPage />} />
</Routes>,
{ route: `/bonds/${secid}` },
);
}
describe('BondPage', () => {
it('shows loading state', () => {
server.use(http.get(`${API}/securities/bonds/:secid`, () => new Promise(() => {})));
renderBondPage();
expect(screen.getByText('Загрузка...')).toBeInTheDocument();
});
it('renders bond details after loading', async () => {
renderBondPage();
expect(await screen.findByText('ОФЗ 26238')).toBeInTheDocument();
});
it('renders price chart', async () => {
renderBondPage();
expect(await screen.findByText('График цены')).toBeInTheDocument();
});
it('shows error state for not found', async () => {
server.use(
http.get(`${API}/securities/bonds/:secid`, () => new HttpResponse(null, { status: 404 })),
http.get(
`${API}/securities/bonds/:secid/candles`,
() => new HttpResponse(null, { status: 404 }),
),
);
renderBondPage('NOTFOUND');
expect(await screen.findByText('Инструмент не найден')).toBeInTheDocument();
});
});