125 lines
3.7 KiB
TypeScript
125 lines
3.7 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { render, screen } from '@testing-library/react';
|
|
import { BondDetails } from './BondDetails';
|
|
import { createMockBond } from '@/shared/lib/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('preserves unit suffixes for missing values', () => {
|
|
const bond = createMockBond({
|
|
marketData: {
|
|
...createMockBond().marketData,
|
|
price: null,
|
|
couponValue: null,
|
|
couponPercent: 7.5,
|
|
accruedInt: null,
|
|
},
|
|
});
|
|
|
|
render(<BondDetails bond={bond} />);
|
|
|
|
expect(screen.getByText('—%')).toBeInTheDocument();
|
|
expect(screen.getByText('— ₽ (7.5%)')).toBeInTheDocument();
|
|
expect(screen.getByText('— ₽')).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows bond type', () => {
|
|
const bond = createMockBond();
|
|
render(<BondDetails bond={bond} />);
|
|
expect(screen.getByText('ОФЗ')).toBeInTheDocument();
|
|
});
|
|
|
|
it('preserves percent suffix when price is missing', () => {
|
|
const bond = createMockBond({
|
|
marketData: {
|
|
...createMockBond().marketData,
|
|
price: null,
|
|
},
|
|
});
|
|
render(<BondDetails bond={bond} />);
|
|
expect(screen.getByText('—%')).toBeInTheDocument();
|
|
});
|
|
|
|
it('preserves currency and percentage formatting when coupon value is missing', () => {
|
|
const bond = createMockBond({
|
|
marketData: {
|
|
...createMockBond().marketData,
|
|
couponValue: null,
|
|
},
|
|
});
|
|
render(<BondDetails bond={bond} />);
|
|
expect(screen.getByText('Купон')).toBeInTheDocument();
|
|
expect(screen.getByText('— ₽ (7.5%)')).toBeInTheDocument();
|
|
});
|
|
|
|
it('preserves currency suffix when accrued interest is missing', () => {
|
|
const bond = createMockBond({
|
|
marketData: {
|
|
...createMockBond().marketData,
|
|
accruedInt: null,
|
|
},
|
|
});
|
|
render(<BondDetails bond={bond} />);
|
|
expect(screen.getByText('НКД')).toBeInTheDocument();
|
|
expect(screen.getByText('— ₽')).toBeInTheDocument();
|
|
});
|
|
});
|