74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import { describe, expect, it } from 'vitest'
|
|
import type { PositionWithPrice } from '@/shared/api'
|
|
import { BondPositionTable } from './BondPositionTable'
|
|
|
|
vi.mock('@tanstack/react-router', () => ({
|
|
Link: ({ children }: { children: React.ReactNode }) => <a href="/mock">{children}</a>,
|
|
}))
|
|
|
|
const positions: PositionWithPrice[] = [
|
|
{
|
|
id: 1,
|
|
secid: 'SU26238RMFS5',
|
|
shortName: 'ОФЗ 26238',
|
|
type: 'bond',
|
|
quantity: 5,
|
|
buyPrice: 980,
|
|
buyDate: null,
|
|
notes: null,
|
|
tags: null,
|
|
currentPrice: 985,
|
|
totalCost: 4900,
|
|
currentValue: 4925,
|
|
weightPercent: 7.5,
|
|
pnl: 25,
|
|
pnlPercent: 0.5,
|
|
dividendIncome: null,
|
|
totalReturn: null,
|
|
totalReturnPercent: null,
|
|
change: 5,
|
|
changePercent: 0.5,
|
|
yieldToMaturity: 8.2,
|
|
duration: 3.5,
|
|
couponValue: 36.9,
|
|
couponPercent: 7.5,
|
|
nextCouponDate: '2024-07-15',
|
|
matDate: '2027-05-15',
|
|
accruedInt: 8.45,
|
|
bid: 984,
|
|
offer: 986,
|
|
couponPeriod: 182,
|
|
bondType: 'ОФЗ',
|
|
offerDate: null,
|
|
},
|
|
]
|
|
|
|
describe('BondPositionTable', () => {
|
|
it('renders section title and bond row', () => {
|
|
render(
|
|
<BondPositionTable
|
|
positions={positions}
|
|
onUpdatePosition={() => undefined}
|
|
onDeletePosition={() => undefined}
|
|
/>,
|
|
)
|
|
|
|
expect(screen.getByText('Облигации')).toBeInTheDocument()
|
|
expect(screen.getByText('SU26238RMFS5')).toBeInTheDocument()
|
|
expect(screen.getByText('ОФЗ 26238')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders nothing when there are no positions', () => {
|
|
const { container } = render(
|
|
<BondPositionTable
|
|
positions={[]}
|
|
onUpdatePosition={() => undefined}
|
|
onDeletePosition={() => undefined}
|
|
/>,
|
|
)
|
|
|
|
expect(container).toBeEmptyDOMElement()
|
|
})
|
|
})
|