-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBtcVaultPage.test.tsx
More file actions
288 lines (249 loc) · 8.84 KB
/
Copy pathBtcVaultPage.test.tsx
File metadata and controls
288 lines (249 loc) · 8.84 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import type { ReactNode } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { cleanup, render, screen } from '@testing-library/react'
import { TooltipProvider } from '@radix-ui/react-tooltip'
import { BtcVaultPage } from './BtcVaultPage'
const mockUseAccount = vi.fn()
const mockUseActionEligibility = vi.fn()
vi.mock('wagmi', async importOriginal => {
const actual = await importOriginal<typeof import('wagmi')>()
return {
...actual,
useAccount: () => mockUseAccount(),
useWriteContract: () => ({
writeContractAsync: vi.fn(),
data: undefined,
isPending: false,
}),
useWaitForTransactionReceipt: () => ({ isPending: false, failureReason: null }),
}
})
vi.mock('@tanstack/react-query', async importOriginal => {
const actual = await importOriginal<typeof import('@tanstack/react-query')>()
return {
...actual,
useQueryClient: () => ({ invalidateQueries: vi.fn() }),
}
})
vi.mock('./hooks/useActionEligibility', () => ({
useActionEligibility: (address: string | undefined) => mockUseActionEligibility(address),
}))
vi.mock('./hooks/useSubmitDeposit', () => ({
useSubmitDeposit: () => ({
onRequestDeposit: vi.fn(),
isRequesting: false,
isTxPending: false,
isTxFailed: false,
depositTxHash: undefined,
}),
}))
vi.mock('@/shared/notification', () => ({
executeTxFlow: vi.fn(),
}))
vi.mock('@/shared/walletConnection/connection/useAppKitFlow', () => ({
useAppKitFlow: vi.fn(() => ({
onConnectWalletButtonClick: vi.fn(),
handleConnectWallet: vi.fn(),
handleCloseIntermediateStep: vi.fn(),
})),
}))
vi.mock('@/shared/hooks/useIsDesktop', () => ({
useIsDesktop: () => true,
}))
vi.mock('@/shared/context', () => ({
usePricesContext: () => ({ prices: {} }),
}))
vi.mock('@/app/backing/components/DecorativeSquares', () => ({
DecorativeSquares: () => null,
}))
vi.mock('@/components/Countdown/Countdown', () => ({
Countdown: () => <span data-testid="countdown">5d 23h 59m</span>,
}))
vi.mock('./components/request-processing/ActiveRequestSection', () => ({
ActiveRequestSection: () => null,
}))
vi.mock('./hooks/useActiveRequests', () => ({
useActiveRequests: () => ({ data: undefined, refetch: vi.fn() }),
}))
vi.mock('./components/capital-allocation/CapitalAllocationSection', () => ({
CapitalAllocationSection: () => null,
}))
vi.mock('./components/dashboard/BtcVaultDashboard', () => ({
BtcVaultDashboard: () => (
<>
<section data-testid="btc-vault-dashboard" />
<div data-testid="btc-vault-actions" />
</>
),
}))
vi.mock('./components/dashboard/BtcVaultMetrics', () => ({
BtcVaultMetrics: () => null,
}))
vi.mock('./hooks/useVaultMetrics', () => ({
useVaultMetrics: () => ({
data: {
tvlFormatted: '50',
apyFormatted: '8.50',
pricePerShareFormatted: '1.02',
timestamp: 1709000000,
pricePerShareRaw: 1_020_000_000_000n,
},
isLoading: false,
}),
}))
vi.mock('./hooks/useEpochState', () => ({
useEpochState: () => ({
data: {
epochId: '1',
status: 'open',
statusSummary: 'Closes in 5m',
isAcceptingRequests: true,
endTime: Math.floor(Date.now() / 1000) + 86400,
closesAtFormatted: '23 Feb 2025',
},
isLoading: false,
}),
}))
vi.mock('./components/BtcVaultEligibilityAndDepositCard', () => ({
BtcVaultEligibilityAndDepositCard: () => (
<div data-testid="btc-vault-eligibility-and-deposit-card" />
),
}))
function Wrapper({ children }: { children: ReactNode }) {
return <TooltipProvider>{children}</TooltipProvider>
}
describe('BtcVaultPage', () => {
beforeEach(() => {
mockUseAccount.mockReturnValue({ address: undefined, isConnected: false })
mockUseActionEligibility.mockReturnValue({ data: undefined })
})
afterEach(() => {
cleanup()
vi.clearAllMocks()
})
it('shows wallet disconnected section at bottom when wallet is not connected', () => {
mockUseAccount.mockReturnValue({ address: undefined, isConnected: false })
render(<BtcVaultPage />, { wrapper: Wrapper })
expect(screen.getByTestId('BtcVaultWalletDisconnectedSection')).toBeInTheDocument()
expect(screen.getByText('Your wallet is not connected')).toBeInTheDocument()
expect(screen.getByTestId('ConnectWallet')).toBeInTheDocument()
})
it('shows disclosure banner and not disclosure section when wallet is not connected', () => {
mockUseAccount.mockReturnValue({ address: undefined, isConnected: false })
render(<BtcVaultPage />, { wrapper: Wrapper })
expect(screen.getByTestId('DisclosureBanner')).toBeInTheDocument()
expect(screen.getByText('DISCLOSURE')).toBeInTheDocument()
expect(screen.getByTestId('DisclosureContent')).toBeInTheDocument()
expect(screen.queryByTestId('BtcVaultDisclosureSection')).not.toBeInTheDocument()
})
it('does not show wallet disconnected section when wallet is connected', () => {
mockUseAccount.mockReturnValue({
address: '0x123',
isConnected: true,
})
mockUseActionEligibility.mockReturnValue({
data: {
canDeposit: true,
canWithdraw: true,
depositBlockReason: '',
withdrawBlockReason: '',
},
})
render(<BtcVaultPage />, { wrapper: Wrapper })
expect(screen.queryByTestId('BtcVaultWalletDisconnectedSection')).not.toBeInTheDocument()
})
it('renders Vault Metrics section with section title', () => {
mockUseAccount.mockReturnValue({
address: '0x123',
isConnected: true,
})
mockUseActionEligibility.mockReturnValue({
data: {
canDeposit: true,
canWithdraw: true,
depositBlockReason: '',
withdrawBlockReason: '',
},
})
render(<BtcVaultPage />, { wrapper: Wrapper })
expect(screen.getByTestId('btc-vault-metrics')).toBeInTheDocument()
expect(screen.getByText('VAULT METRICS')).toBeInTheDocument()
})
it('shows main content when connected and eligible', () => {
mockUseAccount.mockReturnValue({
address: '0x123',
isConnected: true,
})
mockUseActionEligibility.mockReturnValue({
data: {
canDeposit: true,
canWithdraw: true,
depositBlockReason: '',
withdrawBlockReason: '',
},
})
render(<BtcVaultPage />, { wrapper: Wrapper })
expect(screen.getByTestId('BTC Vault')).toBeInTheDocument()
expect(screen.getByTestId('btc-vault-metrics')).toBeInTheDocument()
expect(screen.getByTestId('btc-vault-dashboard')).toBeInTheDocument()
expect(screen.getByTestId('btc-vault-actions')).toBeInTheDocument()
expect(screen.getByTestId('btc-vault-request-queue')).toBeInTheDocument()
expect(screen.getByTestId('btc-vault-history')).toBeInTheDocument()
expect(screen.queryByTestId('NotAuthorizedBanner')).not.toBeInTheDocument()
expect(screen.queryByTestId('BtcVaultWalletDisconnectedSection')).not.toBeInTheDocument()
})
it('shows disclosure section and not disclosure banner when wallet is connected', () => {
mockUseAccount.mockReturnValue({
address: '0x123',
isConnected: true,
})
mockUseActionEligibility.mockReturnValue({
data: {
canDeposit: true,
canWithdraw: true,
depositBlockReason: '',
withdrawBlockReason: '',
},
})
render(<BtcVaultPage />, { wrapper: Wrapper })
expect(screen.getByTestId('BtcVaultDisclosureSection')).toBeInTheDocument()
expect(screen.getByTestId('DisclosureContent')).toBeInTheDocument()
expect(screen.getByText('estimated')).toBeInTheDocument()
expect(screen.getByText(/Execution may be delayed\/batched by epoch/)).toBeInTheDocument()
expect(screen.queryByTestId('DisclosureBanner')).not.toBeInTheDocument()
})
it('shows main content when connected but blocked by pause (not eligibility)', () => {
mockUseAccount.mockReturnValue({
address: '0x123',
isConnected: true,
})
mockUseActionEligibility.mockReturnValue({
data: {
canDeposit: false,
canWithdraw: true,
depositBlockReason: 'Deposits are currently paused',
withdrawBlockReason: '',
},
})
render(<BtcVaultPage />, { wrapper: Wrapper })
expect(screen.getByTestId('BTC Vault')).toBeInTheDocument()
expect(screen.queryByTestId('NotAuthorizedBanner')).not.toBeInTheDocument()
})
it('shows main content when connected but blocked by active request (not eligibility)', () => {
mockUseAccount.mockReturnValue({
address: '0x123',
isConnected: true,
})
mockUseActionEligibility.mockReturnValue({
data: {
canDeposit: false,
canWithdraw: false,
depositBlockReason: 'You already have an active request',
withdrawBlockReason: 'You already have an active request',
},
})
render(<BtcVaultPage />, { wrapper: Wrapper })
expect(screen.getByTestId('BTC Vault')).toBeInTheDocument()
expect(screen.queryByTestId('NotAuthorizedBanner')).not.toBeInTheDocument()
})
})