forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-native-permissions.ts
77 lines (68 loc) · 2.42 KB
/
react-native-permissions.ts
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
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;
return acc;
},
{
lockScreen: true,
notificationCenter: true,
},
),
}));
const checkMultiple: jest.Mock<ResultsCollection> = jest.fn((permissions: string[]) =>
permissions.reduce((acc: ResultsCollection, permission: string) => {
acc[permission] = RESULTS.GRANTED;
return acc;
}, {}),
);
const requestMultiple: jest.Mock<ResultsCollection> = jest.fn((permissions: string[]) =>
permissions.reduce((acc: ResultsCollection, permission: string) => {
acc[permission] = RESULTS.GRANTED;
return acc;
}, {}),
);
export {
PERMISSIONS,
RESULTS,
check,
checkLocationAccuracy,
checkMultiple,
checkNotifications,
openLimitedPhotoLibraryPicker,
openSettings,
request,
requestLocationAccuracy,
requestMultiple,
requestNotifications,
};