forked from StellarSend/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubscriptionList.test.tsx
More file actions
84 lines (76 loc) · 2.65 KB
/
Copy pathSubscriptionList.test.tsx
File metadata and controls
84 lines (76 loc) · 2.65 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
import { render, screen } from '@testing-library/react'
import { describe, it, expect, vi } from 'vitest'
import { SubscriptionList } from './SubscriptionList'
import type { Subscription } from '@/types'
function makeSubscription(overrides: Partial<Subscription> = {}): Subscription {
return {
id: 'sub_1',
sourcePublicKey: 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5',
destinationAddress: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',
asset: { code: 'XLM', issuer: null, name: 'Stellar Lumens', decimals: 7 },
amount: '10',
interval: 'monthly',
startDate: new Date().toISOString(),
nextRunAt: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
status: 'active',
createdAt: new Date().toISOString(),
runCount: 0,
...overrides,
}
}
const noop = vi.fn()
describe('SubscriptionList per-row pending state (#52)', () => {
it('shows a row as cancelling only when its own id is in cancellingIds', () => {
const subscriptions = [
makeSubscription({ id: 'subA', amount: '10' }),
makeSubscription({ id: 'subB', amount: '20' }),
]
render(
<SubscriptionList
subscriptions={subscriptions}
isLoading={false}
isError={false}
onRetry={noop}
onCancel={noop}
cancellingIds={new Set(['subB'])}
/>,
)
const cancelButtons = screen.getAllByRole('button', { name: /cancel/i })
expect(cancelButtons).toHaveLength(2)
expect(cancelButtons[0]).not.toBeDisabled()
expect(cancelButtons[1]).toBeDisabled()
})
it('shows two different rows as cancelling simultaneously without clobbering each other (#52)', () => {
const subscriptions = [
makeSubscription({ id: 'subA', amount: '10' }),
makeSubscription({ id: 'subB', amount: '20' }),
makeSubscription({ id: 'subC', amount: '30' }),
]
render(
<SubscriptionList
subscriptions={subscriptions}
isLoading={false}
isError={false}
onRetry={noop}
onCancel={noop}
cancellingIds={new Set(['subA', 'subC'])}
/>,
)
const cancelButtons = screen.getAllByRole('button', { name: /cancel/i })
expect(cancelButtons[0]).toBeDisabled() // subA
expect(cancelButtons[1]).not.toBeDisabled() // subB
expect(cancelButtons[2]).toBeDisabled() // subC
})
it('treats an undefined cancellingIds as nothing pending', () => {
render(
<SubscriptionList
subscriptions={[makeSubscription()]}
isLoading={false}
isError={false}
onRetry={noop}
onCancel={noop}
/>,
)
expect(screen.getByRole('button', { name: /cancel/i })).not.toBeDisabled()
})
})