-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathBasicFunctionalityModal.test.js
More file actions
102 lines (90 loc) · 2.89 KB
/
Copy pathBasicFunctionalityModal.test.js
File metadata and controls
102 lines (90 loc) · 2.89 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
// Third party dependencies.
import React from 'react';
import { fireEvent, waitFor } from '@testing-library/react-native';
// Internal dependencies.
import BasicFunctionalityModal from './BasicFunctionalityModal';
import renderWithProvider from '../../../../util/test/renderWithProvider';
import { useNavigation } from '@react-navigation/native';
import { toggleBasicFunctionality } from '../../../../actions/settings';
/**
* @typedef {import('../../../../reducers').RootState} RootState
* @typedef {import('redux').DeepPartial<RootState>} MockRootState
*/
/** @type {MockRootState} */
const mockInitialState = {
settings: {
basicFunctionalityEnabled: true,
},
engine: {
backgroundState: {
UserStorageController: {
isBackupAndSyncEnabled: false,
},
NotificationServicesController: {
isNotificationServicesEnabled: false,
},
},
},
};
jest.mock('react-native-safe-area-context', () => {
const inset = { top: 0, right: 0, bottom: 0, left: 0 };
const frame = { width: 0, height: 0, x: 0, y: 0 };
return {
SafeAreaProvider: jest.fn().mockImplementation(({ children }) => children),
SafeAreaConsumer: jest
.fn()
.mockImplementation(({ children }) => children(inset)),
useSafeAreaInsets: jest.fn().mockImplementation(() => inset),
useSafeAreaFrame: jest.fn().mockImplementation(() => frame),
};
});
jest.mock('@react-navigation/native', () => {
const actualReactNavigation = jest.requireActual('@react-navigation/native');
return {
...actualReactNavigation,
useNavigation: () => ({
navigate: jest.fn(),
setOptions: jest.fn(),
goBack: jest.fn(),
reset: jest.fn(),
dangerouslyGetParent: () => ({
pop: jest.fn(),
}),
isFocused: jest.fn(() => true),
}),
};
});
// Mock the toggleBasicFunctionality thunk action
jest.mock('../../../../actions/settings', () => ({
toggleBasicFunctionality: jest.fn(() => () => Promise.resolve()),
}));
describe('BasicFunctionalityModal', () => {
const mockRoute = {
params: {
caller: 'Settings',
},
};
beforeEach(() => {
jest.clearAllMocks();
});
it('should render correctly', () => {
const { toJSON } = renderWithProvider(
<BasicFunctionalityModal route={mockRoute} />,
{ state: mockInitialState },
);
expect(toJSON()).toMatchSnapshot();
});
// Test coverage for the new thunk action integration
it('should call toggleBasicFunctionality thunk action when toggling', async () => {
const { getByText } = renderWithProvider(
<BasicFunctionalityModal route={mockRoute} />,
{ state: mockInitialState },
);
// Find and press the turn off button (when basicFunctionality is enabled)
const turnOffButton = getByText('Turn off');
fireEvent.press(turnOffButton);
await waitFor(() => {
expect(toggleBasicFunctionality).toHaveBeenCalledWith(false);
});
});
});