Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __mocks__/react-native-permissions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ValueOf} from 'type-fest';

import {PERMISSIONS} from 'react-native-permissions/dist/commonjs/permissions';
import {PERMISSIONS} from 'react-native-permissions/mock';

const RESULTS = {
UNAVAILABLE: 'unavailable',
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3097,7 +3097,7 @@ PODS:
- ReactCommon/turbomodule/core
- ReactNativeDependencies
- Yoga
- RNPermissions (5.4.0):
- RNPermissions (5.6.3):
- hermes-engine
- RCTRequired
- RCTTypeSafety
Expand Down Expand Up @@ -4184,7 +4184,7 @@ SPEC CHECKSUMS:
RNLocalize: 82e7aa2857ce5dcd9e2a0c04f8c34c2ed50821df
rnmapbox-maps: 1cb6aa142a8ea99d0934a36d83d2acf3f2de45d3
RNNitroSQLite: 8962a30dc9296f8a62bfcc33f3c2a540b1c44aff
RNPermissions: 32bd3b977f28442af0900b102f4458f0f9f9b77c
RNPermissions: 5938a67cf02a23f8a7f69c170608ab481b81713d
RNReactNativeHapticFeedback: 6c8677db48f62a635e6a2065f5d2bd02498d7a73
RNReanimated: e75c988a6527ec651ea2957b93891ddb64d530d4
RNScreens: 433b8c24dd1dfeaa3b61f72d55052cb64fd19c5f
Expand Down
12 changes: 7 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
"react-native-onyx": "3.0.143",
"react-native-pager-view": "9.0.4",
"react-native-pdf": "7.0.2",
"react-native-permissions": "^5.4.0",
"react-native-permissions": "^5.6.3",
"react-native-picker-select": "github:Expensify/react-native-picker-select#69d750a89aaba48392fb8b6f92a3d79f53b99c41",
"react-native-plaid-link-sdk": "12.5.3",
"react-native-qrcode-svg": "6.3.21",
Expand Down
5 changes: 0 additions & 5 deletions src/types/modules/react-native-permissions.d.ts

This file was deleted.

56 changes: 56 additions & 0 deletions tests/unit/hooks/useContactPermissions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {renderHook, waitFor} from '@testing-library/react-native';

import {getContactPermission} from '@libs/ContactPermission';
import useContactPermissions from '@libs/ContactPermission/useContactPermissions';

import type {AppStateStatus} from 'react-native';

import {RESULTS} from 'react-native-permissions';

jest.mock('@libs/ContactPermission', () => ({
getContactPermission: jest.fn(),
}));

let mockOnAppStateChange: ((nextAppState: AppStateStatus) => void) | undefined;
jest.mock('@hooks/useAppState', () => ({
__esModule: true,
default: ({onAppStateChange}: {onAppStateChange?: (nextAppState: AppStateStatus) => void}) => {
mockOnAppStateChange = onAppStateChange;
return {isForeground: true, isInactive: false, isBackground: false};
},
}));

jest.mock('@react-navigation/native', () => ({
useFocusEffect: (callback: () => undefined | (() => void)) => {
jest.requireActual<{useEffect: (effect: () => undefined | (() => void), deps: unknown[]) => void}>('react').useEffect(callback, []);
},
}));

const mockGetContactPermission = jest.mocked(getContactPermission);

function renderContactPermissions() {
const params = {importAndSaveContacts: jest.fn(), setContacts: jest.fn(), contactPermissionState: RESULTS.DENIED, setContactPermissionState: jest.fn()};
renderHook(() => useContactPermissions(params));
return params;
}

describe('useContactPermissions', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('imports the picked contacts when the app comes back with limited contact access', async () => {
// Given contact access isn't decided yet when the page opens
mockGetContactPermission.mockResolvedValue(RESULTS.DENIED);
const params = renderContactPermissions();
await waitFor(() => expect(mockGetContactPermission).toHaveBeenCalled());
expect(params.importAndSaveContacts).not.toHaveBeenCalled();

// When the user picks some contacts in the iOS prompt and the app becomes active again
mockGetContactPermission.mockResolvedValue(RESULTS.LIMITED);
mockOnAppStateChange?.('active');

// Then the picked contacts are imported, since limited access counts as granted
await waitFor(() => expect(params.importAndSaveContacts).toHaveBeenCalledTimes(1));
});
});
Loading