moex-vibe/apps/frontend/src/components/BondDetails.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

72 lines
2.1 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { BondDetails } from './BondDetails';
import { createMockBond } from '../test/factories';
describe('BondDetails', () => {
it('renders bond details', () => {
const bond = createMockBond();
render(<BondDetails bond={bond} />);
expect(screen.getByText('ОФЗ 26238')).toBeInTheDocument();
expect(screen.getAllByText('RU000A101XU7').length).toBe(2);
});
it('shows price as percentage', () => {
const bond = createMockBond();
render(<BondDetails bond={bond} />);
expect(screen.getByText('98.50%')).toBeInTheDocument();
});
it('renders maturity date', () => {
const bond = createMockBond();
render(<BondDetails bond={bond} />);
expect(screen.getByText('2027-05-15')).toBeInTheDocument();
});
it('shows coupon with percentage', () => {
const bond = createMockBond();
render(<BondDetails bond={bond} />);
expect(screen.getByText('36.9 ₽ (7.5%)')).toBeInTheDocument();
});
it('shows coupon without percentage when null', () => {
const bond = createMockBond({
marketData: {
...createMockBond().marketData,
couponPercent: null,
},
});
render(<BondDetails bond={bond} />);
expect(screen.getByText('36.9 ₽')).toBeInTheDocument();
});
it('shows dash for missing next coupon date', () => {
const bond = createMockBond({
marketData: {
...createMockBond().marketData,
nextCouponDate: null,
},
});
render(<BondDetails bond={bond} />);
const dashes = screen.getAllByText('—');
expect(dashes.length).toBeGreaterThanOrEqual(1);
});
it('shows dash for null yieldToMaturity', () => {
const bond = createMockBond({
marketData: {
...createMockBond().marketData,
yieldToMaturity: null,
},
});
render(<BondDetails bond={bond} />);
expect(screen.getByText('—')).toBeInTheDocument();
});
it('shows bond type', () => {
const bond = createMockBond();
render(<BondDetails bond={bond} />);
expect(screen.getByText('ОФЗ')).toBeInTheDocument();
});
});