-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35886 from ruben-rebelo/ts-migration/react-native…
…-permissions-mock [TS migration] Migrate react-native-permissions mock
- Loading branch information
Showing
3 changed files
with
82 additions
and
84 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import {PERMISSIONS, RESULTS} from 'react-native-permissions/dist/commonjs/permissions'; | ||
import type {ValueOf} from 'type-fest'; | ||
|
||
type Results = ValueOf<typeof RESULTS>; | ||
type ResultsCollection = Record<string, Results>; | ||
type NotificationSettings = Record<string, boolean>; | ||
type Notification = {status: Results; settings: NotificationSettings}; | ||
|
||
const openLimitedPhotoLibraryPicker: jest.Mock<void> = jest.fn(() => {}); | ||
const openSettings: jest.Mock<void> = jest.fn(() => {}); | ||
const check = jest.fn(() => RESULTS.GRANTED as string); | ||
const request = jest.fn(() => RESULTS.GRANTED as string); | ||
const checkLocationAccuracy: jest.Mock<string> = jest.fn(() => 'full'); | ||
const requestLocationAccuracy: jest.Mock<string> = jest.fn(() => 'full'); | ||
|
||
const notificationOptions: string[] = ['alert', 'badge', 'sound', 'carPlay', 'criticalAlert', 'provisional']; | ||
|
||
const notificationSettings: NotificationSettings = { | ||
alert: true, | ||
badge: true, | ||
sound: true, | ||
carPlay: true, | ||
criticalAlert: true, | ||
provisional: true, | ||
lockScreen: true, | ||
notificationCenter: true, | ||
}; | ||
|
||
const checkNotifications: jest.Mock<Notification> = jest.fn(() => ({ | ||
status: RESULTS.GRANTED, | ||
settings: notificationSettings, | ||
})); | ||
|
||
const requestNotifications: jest.Mock<Notification> = jest.fn((options: Record<string, string>) => ({ | ||
status: RESULTS.GRANTED, | ||
settings: Object.keys(options) | ||
.filter((option: string) => notificationOptions.includes(option)) | ||
.reduce((acc: NotificationSettings, option: string) => ({...acc, [option]: true}), { | ||
lockScreen: true, | ||
notificationCenter: true, | ||
}), | ||
})); | ||
|
||
const checkMultiple: jest.Mock<ResultsCollection> = jest.fn((permissions: string[]) => | ||
permissions.reduce( | ||
(acc: ResultsCollection, permission: string) => ({ | ||
...acc, | ||
[permission]: RESULTS.GRANTED, | ||
}), | ||
{}, | ||
), | ||
); | ||
|
||
const requestMultiple: jest.Mock<ResultsCollection> = jest.fn((permissions: string[]) => | ||
permissions.reduce( | ||
(acc: ResultsCollection, permission: string) => ({ | ||
...acc, | ||
[permission]: RESULTS.GRANTED, | ||
}), | ||
{}, | ||
), | ||
); | ||
|
||
export { | ||
PERMISSIONS, | ||
RESULTS, | ||
check, | ||
checkLocationAccuracy, | ||
checkMultiple, | ||
checkNotifications, | ||
openLimitedPhotoLibraryPicker, | ||
openSettings, | ||
request, | ||
requestLocationAccuracy, | ||
requestMultiple, | ||
requestNotifications, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare module 'react-native-permissions/dist/commonjs/permissions' { | ||
import {PERMISSIONS, RESULTS} from 'react-native-permissions'; | ||
|
||
export {PERMISSIONS, RESULTS}; | ||
} |