Some checks failed
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
72 lines
2.1 KiB
TypeScript
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();
|
|
});
|
|
});
|