-
Notifications
You must be signed in to change notification settings - Fork 69
/
index.tsx
105 lines (94 loc) · 2.32 KB
/
index.tsx
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
/**
* External dependencies
*/
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
/**
* Internal dependencies
*/
import InstantDepositButton from '../';
import { useInstantDeposit } from 'wcpay/data';
import type * as AccountOverview from 'wcpay/types/account-overview';
jest.mock( 'wcpay/data', () => ( { useInstantDeposit: jest.fn() } ) );
const mockUseInstantDeposit = useInstantDeposit as jest.MockedFunction<
typeof useInstantDeposit
>;
mockUseInstantDeposit.mockReturnValue( {
deposit: undefined,
inProgress: false,
submit: () => null,
} );
const mockInstantBalance = {
amount: 12345,
fee: 123.45,
net: 12221.55,
fee_percentage: 1.5,
currency: 'USD',
} as AccountOverview.InstantBalance;
const mockZeroInstantBalance = {
amount: 0,
fee: 0,
net: 0,
fee_percentage: 1.5,
currency: 'USD',
} as AccountOverview.InstantBalance;
declare const global: {
wcpaySettings: {
zeroDecimalCurrencies: string[];
currencyData: Record< string, any >;
connect: {
country: string;
};
};
};
describe( 'Instant deposit button and modal', () => {
beforeEach( () => {
jest.clearAllMocks();
global.wcpaySettings = {
zeroDecimalCurrencies: [],
connect: {
country: 'US',
},
currencyData: {
US: {
code: 'USD',
symbol: '$',
symbolPosition: 'left',
thousandSeparator: ',',
decimalSeparator: '.',
precision: 2,
},
},
};
} );
test( 'button renders correctly with zero balance', () => {
const { container } = render(
<InstantDepositButton instantBalance={ mockZeroInstantBalance } />
);
expect( container ).toMatchSnapshot();
} );
test( 'button renders correctly with balance', () => {
const { container } = render(
<InstantDepositButton instantBalance={ mockInstantBalance } />
);
expect( container ).toMatchSnapshot();
} );
test( 'modal renders correctly', () => {
render(
<InstantDepositButton instantBalance={ mockInstantBalance } />
);
expect(
screen.queryByRole( 'dialog', { name: /instant deposit/i } )
).not.toBeInTheDocument();
fireEvent.click(
screen.getByRole( 'button', {
name: /Instantly deposit \$123\.45/i,
} )
);
const modal = screen.queryByRole( 'dialog', {
name: /instant deposit/i,
} );
expect( modal ).toBeInTheDocument();
expect( modal ).toMatchSnapshot();
} );
} );