|
1 | 1 | import React from 'react';
|
2 | 2 | import { fireEvent } from '@testing-library/react-native';
|
3 |
| -import { TouchableOpacity } from 'react-native'; |
4 | 3 | import { RevealPrivateKey } from './RevealPrivateKey';
|
5 | 4 | import { internalAccount1 as mockAccount } from '../../../../../util/test/accountsControllerTestUtils';
|
6 | 5 | import { KeyringTypes } from '@metamask/keyring-controller';
|
7 | 6 | import { strings } from '../../../../../../locales/i18n';
|
8 |
| -import { SafeAreaProvider } from 'react-native-safe-area-context'; |
9 | 7 | import renderWithProvider from '../../../../../util/test/renderWithProvider';
|
10 | 8 | import { backgroundState } from '../../../../../util/test/initial-root-state';
|
11 |
| - |
12 |
| -jest.mock('react-native-safe-area-context', () => { |
13 |
| - const inset = { top: 0, right: 0, bottom: 0, left: 0 }; |
14 |
| - const frame = { width: 0, height: 0, x: 0, y: 0 }; |
15 |
| - return { |
16 |
| - SafeAreaProvider: jest.fn().mockImplementation(({ children }) => children), |
17 |
| - SafeAreaConsumer: jest |
18 |
| - .fn() |
19 |
| - .mockImplementation(({ children }) => children(inset)), |
20 |
| - useSafeAreaInsets: jest.fn().mockImplementation(() => inset), |
21 |
| - useSafeAreaFrame: jest.fn().mockImplementation(() => frame), |
22 |
| - }; |
23 |
| -}); |
| 9 | +import { SHEET_HEADER_BACK_BUTTON_ID } from '../../../../../component-library/components/Sheet/SheetHeader/SheetHeader.constants'; |
24 | 10 |
|
25 | 11 | const mockGoBack = jest.fn();
|
26 | 12 | const mockNavigate = jest.fn();
|
@@ -82,12 +68,7 @@ const render = () => {
|
82 | 68 | },
|
83 | 69 | },
|
84 | 70 | };
|
85 |
| - return renderWithProvider( |
86 |
| - <SafeAreaProvider> |
87 |
| - <RevealPrivateKey /> |
88 |
| - </SafeAreaProvider>, |
89 |
| - { state: initialState }, |
90 |
| - ); |
| 71 | + return renderWithProvider(<RevealPrivateKey />, { state: initialState }); |
91 | 72 | };
|
92 | 73 |
|
93 | 74 | describe('RevealPrivateKey', () => {
|
@@ -123,15 +104,8 @@ describe('RevealPrivateKey', () => {
|
123 | 104 | });
|
124 | 105 |
|
125 | 106 | it('navigates back when the back button is pressed', () => {
|
126 |
| - const rendered = render(); |
127 |
| - const { root } = rendered; |
128 |
| - const touchableOpacities = root.findAllByType(TouchableOpacity); |
129 |
| - |
130 |
| - // Hack to get the button |
131 |
| - const backButton = touchableOpacities.find( |
132 |
| - (touchable) => |
133 |
| - touchable.props.accessible === true && touchable.props.onPress, |
134 |
| - ); |
| 107 | + const { getByTestId } = render(); |
| 108 | + const backButton = getByTestId(SHEET_HEADER_BACK_BUTTON_ID); |
135 | 109 |
|
136 | 110 | expect(backButton).toBeTruthy();
|
137 | 111 | if (backButton) {
|
|
0 commit comments