This repository has been archived by the owner on Sep 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
jest-mock.js
146 lines (133 loc) · 4.37 KB
/
jest-mock.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* Mock implementation for test runners.
*
* Example:
*
* ```js
* jest.mock('@notifee/react-native', () => require('@notifee/react-native/jest-mock'));
* ```
*/
import { version as SDK_VERSION } from './dist/version';
export * from './dist/types/Library';
export * from './dist/types/Notification';
export * from './dist/types/Trigger';
export * from './dist/types/NotificationIOS';
export * from './dist/types/NotificationAndroid';
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable no-undef */
export const testNotification = {
id: 'test-id',
title: 'test-title',
body: 'test-body',
android: {
channelId: 'default',
},
};
export const testChannel = {
id: 'channel-id',
name: 'channel-name',
};
export const testChannelGroup = {
id: 'channel-group-id',
name: 'channel-group',
};
export const testTrigger = {
type: 'TIMESTAMP',
timestamp: new Date(Date.now()).getTime(),
};
export const testTriggerNotificationIds = ['trigger1', 'trigger2'];
export const testTriggerNotifications = [
{
notification: testNotification,
trigger: testTrigger,
},
];
export const testDisplayedNotifications = [
{
id: testNotification.id,
date: testTrigger.timestamp,
notification: testNotification,
trigger: testTrigger,
},
];
export const testCategory = {
id: 'test-category',
actions: [
{
id: 'test-action',
title: 'Test',
},
],
allowInCarPlay: false,
allowAnnouncement: false,
hiddenPreviewsShowTitle: false,
hiddenPreviewsShowSubtitle: false,
};
export const testNotificationSettings = {
alert: true,
badge: true,
sound: true,
carPlay: true,
criticalAlert: true,
provisional: true,
lockScreen: true,
notificationCenter: true,
showPreviews: true,
inAppNotificationSettings: true,
};
export const testBadgeCount = 1;
export const testPowerManagerSettings = {
activity: 'test-activity',
manufacturer: 'test-manufacturer',
model: 'test-model',
version: 'test-version',
};
export default {
SDK_VERSION,
displayNotification: jest.fn(async notification => notification?.id || testNotification.id),
createTriggerNotification: jest.fn(
async (notification, _) => notification?.id || testNotification.id,
),
getChannel: jest.fn(async id => ({
...testChannel,
id,
})),
getChannels: jest.fn(async () => [testChannel]),
getChannelGroup: jest.fn(async () => testChannelGroup),
getChannelGroups: jest.fn(async () => [testChannelGroup]),
isChannelBlocked: jest.fn(async () => false),
isChannelCreated: jest.fn(async () => true),
getTriggerNotificationIds: jest.fn(async () => testTriggerNotificationIds),
getDisplayedNotifications: jest.fn(async () => testDisplayedNotifications),
getTriggerNotifications: jest.fn(async () => testTriggerNotifications),
cancelAllNotifications: jest.fn(async () => {}),
cancelDisplayedNotifications: jest.fn(async () => {}),
cancelTriggerNotifications: jest.fn(async () => {}),
cancelNotification: jest.fn(async () => {}),
cancelDisplayedNotification: jest.fn(async () => {}),
cancelTriggerNotification: jest.fn(async () => {}),
createChannel: jest.fn(async channel => channel?.id || testChannel.id),
createChannelGroup: jest.fn(async channelGroup => channelGroup?.id || testChannelGroup.id),
createChannelGroups: jest.fn(async () => {}),
deleteChannel: jest.fn(async () => {}),
getInitialNotification: jest.fn(async () => testNotification),
onBackgroundEvent: jest.fn(),
onForegroundEvent: jest.fn(),
openNotificationSettings: jest.fn(),
requestPermission: jest.fn(async () => testNotificationSettings),
registerForegroundService: jest.fn(),
setNotificationCategories: jest.fn(async () => {}),
getNotificationCategories: jest.fn(async () => [testCategory]),
getNotificationSettings: jest.fn(async () => testNotificationSettings),
getBadgeCount: jest.fn(async () => testBadgeCount),
setBadgeCount: jest.fn(async () => {}),
incrementBadgeCount: jest.fn(async () => {}),
decrementBadgeCount: jest.fn(async () => {}),
isBatteryOptimizationEnabled: jest.fn(async () => true),
openBatteryOptimizationSettings: jest.fn(async () => {}),
getPowerManagerInfo: jest.fn(async () => {}),
openPowerManagerSettings: jest.fn(async () => testPowerManagerSettings),
stopForegroundService: jest.fn(async () => {}),
hideNotificationDrawer: jest.fn(async () => {}),
};