-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathStakeConfirmationView.test.tsx
More file actions
130 lines (117 loc) · 3.55 KB
/
StakeConfirmationView.test.tsx
File metadata and controls
130 lines (117 loc) · 3.55 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
import React from 'react';
import renderWithProvider, {
DeepPartial,
} from '../../../../../util/test/renderWithProvider';
import StakeConfirmationView from './StakeConfirmationView';
import { Image, ImageSize } from 'react-native';
import { createMockAccountsControllerState } from '../../../../../util/test/accountsControllerTestUtils';
import { backgroundState } from '../../../../../util/test/initial-root-state';
import configureMockStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import { StakeConfirmationViewRouteParams } from './StakeConfirmationView.types';
import { MOCK_POOL_STAKING_SDK } from '../../__mocks__/stakeMockData';
import { RootState } from '../../../../../reducers';
import { strings } from '../../../../../../locales/i18n';
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 MOCK_ADDRESS_1 = '0x0';
const MOCK_ADDRESS_2 = '0x1';
const MOCK_ACCOUNTS_CONTROLLER_STATE = createMockAccountsControllerState([
MOCK_ADDRESS_1,
MOCK_ADDRESS_2,
]);
const mockStore = configureMockStore();
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',
},
},
},
};
const store = mockStore(mockInitialState);
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: jest
.fn()
.mockImplementation((callback) => callback(mockInitialState)),
}));
jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual('@react-navigation/native');
return {
...actualNav,
useNavigation: () => ({
navigate: jest.fn(),
setOptions: jest.fn(),
goBack: jest.fn(),
}),
useRoute: () => ({
key: '1',
name: 'params',
params: {
amountWei: '10000000000000000',
amountFiat: '26.21',
annualRewardRate: '2.6%',
annualRewardsETH: '0.00026 ETH',
annualRewardsFiat: '$0.68',
chainId: '1',
} as StakeConfirmationViewRouteParams,
}),
};
});
jest.mock('../../hooks/usePoolStakedDeposit', () => ({
__esModule: true,
default: () => ({
attemptDepositTransaction: jest.fn(),
}),
}));
jest.mock('../../hooks/useStakeContext', () => ({
__esModule: true,
useStakeContext: jest.fn(() => MOCK_POOL_STAKING_SDK),
}));
jest.mock('../../hooks/usePooledStakes', () => ({
__esModule: true,
default: () => ({
refreshPooledStakes: jest.fn(),
}),
}));
describe('StakeConfirmationView', () => {
it('renders stake confirmation view', () => {
const { getByText } = renderWithProvider(
<Provider store={store}>
<StakeConfirmationView />
</Provider>,
);
expect(getByText(strings('stake.staking_from'))).toBeOnTheScreen();
});
});