forked from FlowwStar/FlowStar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream-card.test.tsx
More file actions
108 lines (93 loc) · 3.54 KB
/
Copy pathstream-card.test.tsx
File metadata and controls
108 lines (93 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import { StreamCard } from '@/components/streams/stream-card'
import type { StreamData } from '@/types/stream'
vi.mock('next/link', () => ({
default: ({ href, children, ...props }: any) => (
<a href={href} {...props}>
{children}
</a>
),
}))
vi.mock('@/hooks/use-now', () => ({ useNow: vi.fn(() => 1_700_050_000) }))
vi.mock('@/hooks/use-wallet', () => ({ useWallet: vi.fn(() => ({ address: 'GSENDER111' })) }))
const TOKEN = { address: 'CUSDC', symbol: 'USDC', decimals: 7 }
const NOW = 1_700_050_000
function makeStream(overrides?: Partial<StreamData>): StreamData {
return {
id: 'stream-abc',
sender: 'GSENDER111',
recipient: 'GRCPT222',
token: TOKEN,
depositedAmount: 100_000_000n,
withdrawnAmount: 0n,
startTime: BigInt(NOW - 3600),
endTime: BigInt(NOW + 3600),
cliffTime: BigInt(NOW - 3600),
cliffAmount: 0n,
amountPerSecond: 27_777n,
linearAmount: 100_000_000n,
duration: 7200n,
cancelled: false,
...overrides,
}
}
describe('StreamCard', () => {
it('renders link to stream detail page', () => {
render(<StreamCard stream={makeStream()} />)
expect(screen.getByRole('link')).toHaveAttribute('href', '/app/stream/stream-abc')
})
it('shows Streaming badge for active stream', () => {
render(<StreamCard stream={makeStream()} />)
expect(screen.getByText('Streaming')).toBeInTheDocument()
})
it('shows Completed badge for ended stream', () => {
render(<StreamCard stream={makeStream({ endTime: BigInt(NOW - 100) })} />)
expect(screen.getByText('Completed')).toBeInTheDocument()
})
it('shows Cancelled badge for cancelled stream', () => {
render(<StreamCard stream={makeStream({ cancelled: true })} />)
expect(screen.getByText('Cancelled')).toBeInTheDocument()
})
it('shows Scheduled badge for not-yet-started stream', () => {
render(
<StreamCard
stream={makeStream({
startTime: BigInt(NOW + 3600),
endTime: BigInt(NOW + 7200),
cliffTime: BigInt(NOW + 3600),
})}
/>,
)
expect(screen.getByText('Scheduled')).toBeInTheDocument()
})
it('shows "Sending to" label for outgoing stream', () => {
render(<StreamCard stream={makeStream()} />)
expect(screen.getByText('Sending to')).toBeInTheDocument()
})
it('shows "Receiving from" label for incoming stream', () => {
render(<StreamCard stream={makeStream({ sender: 'GOTHER', recipient: 'GSENDER111' })} />)
expect(screen.getByText('Receiving from')).toBeInTheDocument()
})
it('renders a progress bar with aria attributes', () => {
render(<StreamCard stream={makeStream()} />)
const bar = screen.getByRole('progressbar')
expect(bar).toBeInTheDocument()
expect(Number(bar.getAttribute('aria-valuenow'))).toBeGreaterThan(0)
})
it('has aria-label describing direction, amount, and status', () => {
render(<StreamCard stream={makeStream()} />)
const label = screen.getByRole('link').getAttribute('aria-label') ?? ''
expect(label).toContain('Sending')
expect(label).toContain('USDC')
expect(label).toContain('streaming')
})
it('shows token symbol', () => {
render(<StreamCard stream={makeStream()} />)
expect(screen.getAllByText('USDC').length).toBeGreaterThan(0)
})
it('shows "Ended" label for completed/cancelled streams', () => {
render(<StreamCard stream={makeStream({ endTime: BigInt(NOW - 100) })} />)
expect(screen.getByText('Ended')).toBeInTheDocument()
})
})