forked from StellarSend/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEscrowItem.test.tsx
More file actions
95 lines (87 loc) · 3.13 KB
/
Copy pathEscrowItem.test.tsx
File metadata and controls
95 lines (87 loc) · 3.13 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
import { render, screen } from '@testing-library/react'
import { describe, it, expect, vi } from 'vitest'
import { EscrowItem } from './EscrowItem'
import type { Escrow } from '@/types'
const DEPOSITOR = 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'
const BENEFICIARY = 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'
const ARBITER = 'GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBSMQ7B3W6C'
function makeEscrow(overrides: Partial<Escrow> = {}): Escrow {
return {
id: 'esc_1',
depositorPublicKey: DEPOSITOR,
beneficiaryPublicKey: BENEFICIARY,
arbiterPublicKey: ARBITER,
assetCode: 'XLM',
assetIssuer: null,
amount: '100',
unlockTime: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), // 1 day from now
status: 'funded',
createdAt: new Date().toISOString(),
...overrides,
}
}
const noop = vi.fn()
describe('EscrowItem release/refund gating', () => {
it('does not show the release button to the depositor before unlock (not beneficiary/arbiter)', () => {
render(
<EscrowItem
escrow={makeEscrow()}
currentPublicKey={DEPOSITOR}
onRelease={noop}
onRefund={noop}
/>,
)
expect(screen.queryByRole('button', { name: /release/i })).not.toBeInTheDocument()
// Refund also hidden pre-unlock for the depositor.
expect(screen.queryByRole('button', { name: /refund/i })).not.toBeInTheDocument()
})
it('shows the release button to the beneficiary even before unlock time', () => {
render(
<EscrowItem
escrow={makeEscrow()}
currentPublicKey={BENEFICIARY}
onRelease={noop}
onRefund={noop}
/>,
)
expect(screen.getByRole('button', { name: /release/i })).toBeInTheDocument()
expect(screen.queryByRole('button', { name: /refund/i })).not.toBeInTheDocument()
})
it('shows the release button to the arbiter even before unlock time', () => {
render(
<EscrowItem
escrow={makeEscrow()}
currentPublicKey={ARBITER}
onRelease={noop}
onRefund={noop}
/>,
)
expect(screen.getByRole('button', { name: /release/i })).toBeInTheDocument()
})
it('allows the depositor to refund once the unlock time has passed', () => {
const pastUnlock = makeEscrow({ unlockTime: new Date(Date.now() - 60_000).toISOString() })
render(
<EscrowItem
escrow={pastUnlock}
currentPublicKey={DEPOSITOR}
onRelease={noop}
onRefund={noop}
/>,
)
expect(screen.getByRole('button', { name: /refund/i })).toBeInTheDocument()
// Depositor still cannot release — only beneficiary/arbiter can.
expect(screen.queryByRole('button', { name: /release/i })).not.toBeInTheDocument()
})
it('hides both actions once the escrow is no longer funded', () => {
render(
<EscrowItem
escrow={makeEscrow({ status: 'released' })}
currentPublicKey={BENEFICIARY}
onRelease={noop}
onRefund={noop}
/>,
)
expect(screen.queryByRole('button', { name: /release/i })).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: /refund/i })).not.toBeInTheDocument()
})
})