-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathUnstakeConfirmationView.test.tsx
More file actions
118 lines (106 loc) · 3.35 KB
/
UnstakeConfirmationView.test.tsx
File metadata and controls
118 lines (106 loc) · 3.35 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
import React from 'react';
import UnstakeConfirmationView from './UnstakeConfirmationView';
import renderWithProvider, {
DeepPartial,
} from '../../../../../util/test/renderWithProvider';
import { Image, ImageSize } from 'react-native';
import { createMockAccountsControllerState } from '../../../../../util/test/accountsControllerTestUtils';
import { backgroundState } from '../../../../../util/test/initial-root-state';
import { UnstakeConfirmationViewRouteParams } from './UnstakeConfirmationView.types';
import { MOCK_POOL_STAKING_SDK } from '../../__mocks__/stakeMockData';
import { RootState } from '../../../../../reducers';
import { strings } from '../../../../../../locales/i18n';
const MOCK_ADDRESS_1 = '0x0';
const MOCK_ADDRESS_2 = '0x1';
const MOCK_ACCOUNTS_CONTROLLER_STATE = createMockAccountsControllerState([
MOCK_ADDRESS_1,
MOCK_ADDRESS_2,
]);
const mockSelectedAccount =
MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts[
MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.selectedAccount
];
const mockInitialState: DeepPartial<RootState> = {
settings: {},
engine: {
backgroundState: {
...backgroundState,
AccountsController: MOCK_ACCOUNTS_CONTROLLER_STATE,
AccountTreeController: {
accountTree: {
wallets: {
'keyring:test-wallet': {
groups: {
'keyring:test-wallet/ethereum': {
accounts: [mockSelectedAccount.id],
},
},
},
},
},
selectedAccountGroup: 'keyring:test-wallet/ethereum',
},
},
},
};
jest.mock('../../../../hooks/useIpfsGateway', () => jest.fn());
Image.getSize = jest.fn(
(
_uri: string,
success?: (width: number, height: number) => void,
_failure?: (error: Error) => void,
) => {
if (success) {
success(100, 100);
}
return Promise.resolve<ImageSize>({ width: 100, height: 100 });
},
);
const mockNavigate = jest.fn();
const mockSetOptions = jest.fn();
jest.mock('@react-navigation/native', () => {
const actualReactNavigation = jest.requireActual('@react-navigation/native');
return {
...actualReactNavigation,
useNavigation: () => ({
navigate: mockNavigate,
setOptions: mockSetOptions,
goBack: jest.fn(),
}),
useRoute: () => ({
key: '1',
name: 'params',
params: {
amountWei: '4999820000000000000',
amountFiat: '12894.52',
} as UnstakeConfirmationViewRouteParams,
}),
};
});
jest.mock('../../hooks/usePoolStakedDeposit', () => ({
__esModule: true,
default: () => ({
attemptDepositTransaction: jest.fn(),
}),
}));
jest.mock('../../hooks/usePooledStakes', () => ({
__esModule: true,
default: () => ({
refreshPooledStakes: jest.fn(),
}),
}));
jest.mock('../../hooks/useStakeContext', () => ({
__esModule: true,
useStakeContext: jest.fn(() => MOCK_POOL_STAKING_SDK),
}));
describe('UnstakeConfirmationView', () => {
it('renders unstake confirmation view', () => {
const { getByText } = renderWithProvider(<UnstakeConfirmationView />, {
state: mockInitialState,
});
expect(getByText(strings('stake.unstaking_to'))).toBeOnTheScreen();
expect(getByText(strings('stake.interacting_with'))).toBeOnTheScreen();
expect(getByText('Cancel')).toBeOnTheScreen();
expect(getByText('Continue')).toBeOnTheScreen();
});
});