@imatis/react-native-notifications 4.3.3-imatis.11 → 4.3.3-imatis.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +1 -1
- package/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java +8 -3
- package/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java +3 -11
- package/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java +8 -0
- package/lib/android/app/src/reactNative59/java/com/wix/reactnativenotifications/NotificationManagerCompatFacade.java +2 -2
- package/lib/dist/DTO/Notification.d.ts +11 -0
- package/lib/dist/DTO/Notification.js +30 -0
- package/lib/dist/DTO/Notification.test.d.ts +1 -0
- package/lib/dist/DTO/Notification.test.js +52 -0
- package/lib/dist/DTO/NotificationAndroid.d.ts +7 -0
- package/lib/dist/DTO/NotificationAndroid.js +20 -0
- package/lib/dist/DTO/NotificationAndroid.test.d.ts +1 -0
- package/lib/dist/DTO/NotificationAndroid.test.js +25 -0
- package/lib/dist/DTO/NotificationFactory.d.ts +4 -0
- package/lib/dist/DTO/NotificationFactory.js +18 -0
- package/lib/dist/DTO/NotificationIOS.d.ts +12 -0
- package/lib/dist/DTO/NotificationIOS.js +41 -0
- package/lib/dist/DTO/NotificationIOS.test.d.ts +1 -0
- package/lib/dist/DTO/NotificationIOS.test.js +58 -0
- package/lib/dist/Notifications.d.ts +65 -0
- package/lib/dist/Notifications.js +108 -0
- package/lib/dist/NotificationsAndroid.d.ts +14 -0
- package/lib/dist/NotificationsAndroid.js +33 -0
- package/lib/dist/NotificationsIOS.d.ts +51 -0
- package/lib/dist/NotificationsIOS.js +85 -0
- package/lib/dist/adapters/CompletionCallbackWrapper.d.ts +11 -0
- package/lib/dist/adapters/CompletionCallbackWrapper.js +45 -0
- package/lib/dist/adapters/NativeCommandsSender.d.ts +31 -0
- package/lib/dist/adapters/NativeCommandsSender.js +74 -0
- package/lib/dist/adapters/NativeEventsReceiver.d.ts +19 -0
- package/lib/dist/adapters/NativeEventsReceiver.js +49 -0
- package/lib/dist/adapters/UniqueIdProvider.d.ts +3 -0
- package/lib/dist/adapters/UniqueIdProvider.js +10 -0
- package/lib/dist/commands/Commands.d.ts +32 -0
- package/lib/dist/commands/Commands.js +82 -0
- package/lib/dist/commands/Commands.test.d.ts +1 -0
- package/lib/dist/commands/Commands.test.js +201 -0
- package/lib/dist/events/EventsRegistry.d.ts +18 -0
- package/lib/dist/events/EventsRegistry.js +30 -0
- package/lib/dist/events/EventsRegistry.test.d.ts +1 -0
- package/lib/dist/events/EventsRegistry.test.js +183 -0
- package/lib/dist/events/EventsRegistryIOS.d.ts +12 -0
- package/lib/dist/events/EventsRegistryIOS.js +21 -0
- package/lib/dist/events/EventsRegistryIOS.test.d.ts +1 -0
- package/lib/dist/events/EventsRegistryIOS.test.js +53 -0
- package/lib/dist/index.d.ts +7 -0
- package/lib/dist/index.js +12 -0
- package/lib/dist/interfaces/EventSubscription.d.ts +3 -0
- package/lib/dist/interfaces/EventSubscription.js +2 -0
- package/lib/dist/interfaces/NotificationActionResponse.d.ts +5 -0
- package/lib/dist/interfaces/NotificationActionResponse.js +12 -0
- package/lib/dist/interfaces/NotificationCategory.d.ts +18 -0
- package/lib/dist/interfaces/NotificationCategory.js +27 -0
- package/lib/dist/interfaces/NotificationChannel.d.ts +14 -0
- package/lib/dist/interfaces/NotificationChannel.js +2 -0
- package/lib/dist/interfaces/NotificationCompletion.d.ts +10 -0
- package/lib/dist/interfaces/NotificationCompletion.js +9 -0
- package/lib/dist/interfaces/NotificationEvents.d.ts +18 -0
- package/lib/dist/interfaces/NotificationEvents.js +2 -0
- package/lib/dist/interfaces/NotificationPermissions.d.ts +14 -0
- package/lib/dist/interfaces/NotificationPermissions.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ts_mockito_1 = require("ts-mockito");
|
|
4
|
+
const Commands_1 = require("./Commands");
|
|
5
|
+
const NativeCommandsSender_1 = require("../adapters/NativeCommandsSender");
|
|
6
|
+
const Notification_1 = require("../DTO/Notification");
|
|
7
|
+
const UniqueIdProvider_1 = require("../adapters/UniqueIdProvider");
|
|
8
|
+
const NotificationFactory_1 = require("../DTO/NotificationFactory");
|
|
9
|
+
const NotificationAndroid_1 = require("../DTO/NotificationAndroid");
|
|
10
|
+
const react_native_1 = require("react-native");
|
|
11
|
+
const NotificationIOS_1 = require("../DTO/NotificationIOS");
|
|
12
|
+
describe('Commands', () => {
|
|
13
|
+
let uut;
|
|
14
|
+
let mockedNativeCommandsSender;
|
|
15
|
+
let mockedUniqueIdProvider;
|
|
16
|
+
let notificationFactory;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
notificationFactory = new NotificationFactory_1.NotificationFactory();
|
|
19
|
+
mockedNativeCommandsSender = (0, ts_mockito_1.mock)(NativeCommandsSender_1.NativeCommandsSender);
|
|
20
|
+
mockedUniqueIdProvider = (0, ts_mockito_1.mock)(UniqueIdProvider_1.UniqueIdProvider);
|
|
21
|
+
(0, ts_mockito_1.when)(mockedUniqueIdProvider.generate()).thenCall(() => 12);
|
|
22
|
+
uut = new Commands_1.Commands((0, ts_mockito_1.instance)(mockedNativeCommandsSender), (0, ts_mockito_1.instance)(mockedUniqueIdProvider), notificationFactory);
|
|
23
|
+
});
|
|
24
|
+
describe('getInitialNotification', () => {
|
|
25
|
+
it('sends to native', () => {
|
|
26
|
+
uut.getInitialNotification();
|
|
27
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.getInitialNotification()).called();
|
|
28
|
+
});
|
|
29
|
+
it('Android - returns a promise with the initial notification', async () => {
|
|
30
|
+
react_native_1.Platform.OS = 'android';
|
|
31
|
+
const expectedNotification = new NotificationAndroid_1.NotificationAndroid({ 'google.message_id': 'id' });
|
|
32
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.getInitialNotification()).thenResolve({ 'google.message_id': 'id' });
|
|
33
|
+
const result = await uut.getInitialNotification();
|
|
34
|
+
expect(result).toEqual(expectedNotification);
|
|
35
|
+
});
|
|
36
|
+
it('Should return undefined initial notification', async () => {
|
|
37
|
+
react_native_1.Platform.OS = 'android';
|
|
38
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.getInitialNotification()).thenResolve();
|
|
39
|
+
const result = await uut.getInitialNotification();
|
|
40
|
+
expect(result).toEqual(undefined);
|
|
41
|
+
});
|
|
42
|
+
it('iOS - returns a promise with the initial notification', async () => {
|
|
43
|
+
react_native_1.Platform.OS = 'ios';
|
|
44
|
+
const expectedNotification = new NotificationIOS_1.NotificationIOS({ identifier: 'id' });
|
|
45
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.getInitialNotification()).thenResolve({ identifier: 'id' });
|
|
46
|
+
const result = await uut.getInitialNotification();
|
|
47
|
+
expect(result).toEqual(expectedNotification);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('requestPermissions', () => {
|
|
51
|
+
it('sends to native', () => {
|
|
52
|
+
const opts = {};
|
|
53
|
+
uut.requestPermissions(opts);
|
|
54
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.requestPermissions(opts)).called();
|
|
55
|
+
});
|
|
56
|
+
it('sends to native with options', () => {
|
|
57
|
+
const opts = { criticalAlert: true };
|
|
58
|
+
uut.requestPermissions(opts);
|
|
59
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.requestPermissions(opts)).called();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe('registerPushKit', () => {
|
|
63
|
+
it('sends to native', () => {
|
|
64
|
+
uut.registerPushKit();
|
|
65
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.registerPushKit()).called();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('setCategories', () => {
|
|
69
|
+
it('sends to native', () => {
|
|
70
|
+
const emptyCategoriesArray = [];
|
|
71
|
+
uut.setCategories(emptyCategoriesArray);
|
|
72
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.setCategories(emptyCategoriesArray)).called();
|
|
73
|
+
});
|
|
74
|
+
it('sends to native with categories', () => {
|
|
75
|
+
const category = { identifier: 'id', actions: [] };
|
|
76
|
+
const categoriesArray = [category];
|
|
77
|
+
uut.setCategories(categoriesArray);
|
|
78
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.setCategories(categoriesArray)).called();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe('abandonPermissions', () => {
|
|
82
|
+
it('sends to native', () => {
|
|
83
|
+
uut.abandonPermissions();
|
|
84
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.abandonPermissions()).called();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('postLocalNotification', () => {
|
|
88
|
+
it('sends to native', () => {
|
|
89
|
+
const notification = new Notification_1.Notification({ identifier: 'id' });
|
|
90
|
+
uut.postLocalNotification(notification);
|
|
91
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.postLocalNotification(notification, (0, ts_mockito_1.anyNumber)())).called();
|
|
92
|
+
});
|
|
93
|
+
it('generates unique identifier', () => {
|
|
94
|
+
const notification = new Notification_1.Notification({ identifier: 'id' });
|
|
95
|
+
uut.postLocalNotification(notification);
|
|
96
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.postLocalNotification(notification, (0, ts_mockito_1.anyNumber)())).called();
|
|
97
|
+
});
|
|
98
|
+
it('use passed notification id', () => {
|
|
99
|
+
const notification = new Notification_1.Notification({ identifier: 'id' });
|
|
100
|
+
const passedId = 2;
|
|
101
|
+
uut.postLocalNotification(notification, passedId);
|
|
102
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.postLocalNotification(notification, passedId)).called();
|
|
103
|
+
});
|
|
104
|
+
it('return notification id', () => {
|
|
105
|
+
const notification = new Notification_1.Notification({ identifier: 'id' });
|
|
106
|
+
const notificationId = 2;
|
|
107
|
+
const response = uut.postLocalNotification(notification, notificationId);
|
|
108
|
+
expect(response).toEqual(notificationId);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
describe('getBadgeCount', () => {
|
|
112
|
+
it('sends to native', () => {
|
|
113
|
+
uut.getBadgeCount();
|
|
114
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.getBadgeCount()).called();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
describe('setBadgeCount', () => {
|
|
118
|
+
it('sends to native', () => {
|
|
119
|
+
uut.setBadgeCount(10);
|
|
120
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.setBadgeCount(10)).called();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe('cancelLocalNotification', () => {
|
|
124
|
+
it('sends to native', () => {
|
|
125
|
+
const notificationId = 1;
|
|
126
|
+
uut.cancelLocalNotification(notificationId);
|
|
127
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.cancelLocalNotification(notificationId)).called();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('cancelAllLocalNotifications', () => {
|
|
131
|
+
it('sends to native', () => {
|
|
132
|
+
uut.cancelAllLocalNotifications();
|
|
133
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.cancelAllLocalNotifications()).called();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe('isRegisteredForRemoteNotifications', () => {
|
|
137
|
+
it('sends to native', () => {
|
|
138
|
+
uut.isRegisteredForRemoteNotifications();
|
|
139
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).called();
|
|
140
|
+
});
|
|
141
|
+
it('return positive response from native', async () => {
|
|
142
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).thenResolve(true);
|
|
143
|
+
const isRegistered = await uut.isRegisteredForRemoteNotifications();
|
|
144
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).called();
|
|
145
|
+
expect(isRegistered).toEqual(true);
|
|
146
|
+
});
|
|
147
|
+
it('return negative response from native', async () => {
|
|
148
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).thenResolve(false);
|
|
149
|
+
const isRegistered = await uut.isRegisteredForRemoteNotifications();
|
|
150
|
+
expect(isRegistered).toEqual(false);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe('checkPermissions', () => {
|
|
154
|
+
it('sends to native', () => {
|
|
155
|
+
uut.checkPermissions();
|
|
156
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.checkPermissions()).called();
|
|
157
|
+
});
|
|
158
|
+
it('return negative response from native', async () => {
|
|
159
|
+
const expectedPermissions = {
|
|
160
|
+
badge: false,
|
|
161
|
+
alert: true,
|
|
162
|
+
sound: false,
|
|
163
|
+
carPlay: false,
|
|
164
|
+
criticalAlert: false,
|
|
165
|
+
providesAppNotificationSettings: false,
|
|
166
|
+
provisional: false,
|
|
167
|
+
announcement: false,
|
|
168
|
+
notificationCenter: true,
|
|
169
|
+
lockScreen: false,
|
|
170
|
+
};
|
|
171
|
+
(0, ts_mockito_1.when)(mockedNativeCommandsSender.checkPermissions()).thenResolve(expectedPermissions);
|
|
172
|
+
const permissions = await uut.checkPermissions();
|
|
173
|
+
expect(permissions).toEqual(expectedPermissions);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
describe('removeAllDeliveredNotifications', () => {
|
|
177
|
+
it('sends to native', () => {
|
|
178
|
+
uut.removeAllDeliveredNotifications();
|
|
179
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.removeAllDeliveredNotifications()).called();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe('removeDeliveredNotifications', () => {
|
|
183
|
+
it('sends to native', () => {
|
|
184
|
+
const identifiers = ["id1", "id2"];
|
|
185
|
+
uut.removeDeliveredNotifications(identifiers);
|
|
186
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.removeDeliveredNotifications(identifiers)).called();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
describe('getDeliveredNotifications', () => {
|
|
190
|
+
it('sends to native', () => {
|
|
191
|
+
uut.getDeliveredNotifications();
|
|
192
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.getDeliveredNotifications()).called();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
describe('refreshToken', () => {
|
|
196
|
+
it('sends to native', () => {
|
|
197
|
+
uut.refreshToken();
|
|
198
|
+
(0, ts_mockito_1.verify)(mockedNativeCommandsSender.refreshToken()).called();
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EmitterSubscription } from 'react-native';
|
|
2
|
+
import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
|
|
3
|
+
import { Registered, RegistrationError } from '../interfaces/NotificationEvents';
|
|
4
|
+
import { NotificationActionResponse } from '../interfaces/NotificationActionResponse';
|
|
5
|
+
import { CompletionCallbackWrapper } from '../adapters/CompletionCallbackWrapper';
|
|
6
|
+
import { Notification } from '../DTO/Notification';
|
|
7
|
+
import { NotificationCompletion, NotificationBackgroundFetchResult } from '../interfaces/NotificationCompletion';
|
|
8
|
+
export declare class EventsRegistry {
|
|
9
|
+
private nativeEventsReceiver;
|
|
10
|
+
private completionCallbackWrapper;
|
|
11
|
+
constructor(nativeEventsReceiver: NativeEventsReceiver, completionCallbackWrapper: CompletionCallbackWrapper);
|
|
12
|
+
registerRemoteNotificationsRegistered(callback: (event: Registered) => void): EmitterSubscription;
|
|
13
|
+
registerNotificationReceivedForeground(callback: (notification: Notification, completion: (response: NotificationCompletion) => void) => void): EmitterSubscription;
|
|
14
|
+
registerNotificationReceivedBackground(callback: (notification: Notification, completion: (response: NotificationBackgroundFetchResult) => void) => void): EmitterSubscription;
|
|
15
|
+
registerNotificationOpened(callback: (notification: Notification, completion: () => void, actionResponse?: NotificationActionResponse) => void): EmitterSubscription;
|
|
16
|
+
registerRemoteNotificationsRegistrationFailed(callback: (event: RegistrationError) => void): EmitterSubscription;
|
|
17
|
+
registerRemoteNotificationsRegistrationDenied(callback: () => void): EmitterSubscription;
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventsRegistry = void 0;
|
|
4
|
+
class EventsRegistry {
|
|
5
|
+
nativeEventsReceiver;
|
|
6
|
+
completionCallbackWrapper;
|
|
7
|
+
constructor(nativeEventsReceiver, completionCallbackWrapper) {
|
|
8
|
+
this.nativeEventsReceiver = nativeEventsReceiver;
|
|
9
|
+
this.completionCallbackWrapper = completionCallbackWrapper;
|
|
10
|
+
}
|
|
11
|
+
registerRemoteNotificationsRegistered(callback) {
|
|
12
|
+
return this.nativeEventsReceiver.registerRemoteNotificationsRegistered(callback);
|
|
13
|
+
}
|
|
14
|
+
registerNotificationReceivedForeground(callback) {
|
|
15
|
+
return this.nativeEventsReceiver.registerNotificationReceived(this.completionCallbackWrapper.wrapReceivedForegroundCallback(callback));
|
|
16
|
+
}
|
|
17
|
+
registerNotificationReceivedBackground(callback) {
|
|
18
|
+
return this.nativeEventsReceiver.registerNotificationReceivedBackground(this.completionCallbackWrapper.wrapReceivedBackgroundCallback(callback));
|
|
19
|
+
}
|
|
20
|
+
registerNotificationOpened(callback) {
|
|
21
|
+
return this.nativeEventsReceiver.registerNotificationOpened(this.completionCallbackWrapper.wrapOpenedCallback(callback));
|
|
22
|
+
}
|
|
23
|
+
registerRemoteNotificationsRegistrationFailed(callback) {
|
|
24
|
+
return this.nativeEventsReceiver.registerRemoteNotificationsRegistrationFailed(callback);
|
|
25
|
+
}
|
|
26
|
+
registerRemoteNotificationsRegistrationDenied(callback) {
|
|
27
|
+
return this.nativeEventsReceiver.registerRemoteNotificationsRegistrationDenied(callback);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.EventsRegistry = EventsRegistry;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_native_1 = require("react-native");
|
|
4
|
+
const Notification_1 = require("../DTO/Notification");
|
|
5
|
+
const CompletionCallbackWrapper_1 = require("../adapters/CompletionCallbackWrapper");
|
|
6
|
+
const NativeCommandsSender_1 = require("../adapters/NativeCommandsSender");
|
|
7
|
+
const NativeEventsReceiver_1 = require("../adapters/NativeEventsReceiver");
|
|
8
|
+
const NotificationCompletion_1 = require("../interfaces/NotificationCompletion");
|
|
9
|
+
const EventsRegistry_1 = require("./EventsRegistry");
|
|
10
|
+
jest.mock('../adapters/NativeCommandsSender');
|
|
11
|
+
jest.mock('../adapters/NativeEventsReceiver');
|
|
12
|
+
describe('EventsRegistry', () => {
|
|
13
|
+
let uut;
|
|
14
|
+
const mockNativeEventsReceiver = new NativeEventsReceiver_1.NativeEventsReceiver();
|
|
15
|
+
const mockNativeCommandsSender = new NativeCommandsSender_1.NativeCommandsSender();
|
|
16
|
+
const completionCallbackWrapper = new CompletionCallbackWrapper_1.CompletionCallbackWrapper(mockNativeCommandsSender);
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
uut = new EventsRegistry_1.EventsRegistry(mockNativeEventsReceiver, completionCallbackWrapper);
|
|
19
|
+
});
|
|
20
|
+
describe('registerRemoteNotificationsReceivedForeground', () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
react_native_1.AppState.currentState = 'active';
|
|
23
|
+
});
|
|
24
|
+
it('delegates to nativeEventsReceiver', () => {
|
|
25
|
+
const cb = jest.fn();
|
|
26
|
+
uut.registerNotificationReceivedForeground(cb);
|
|
27
|
+
expect(mockNativeEventsReceiver.registerNotificationReceived).toHaveBeenCalledTimes(1);
|
|
28
|
+
expect(mockNativeEventsReceiver.registerNotificationReceived).toHaveBeenCalledWith(expect.any(Function));
|
|
29
|
+
});
|
|
30
|
+
it('should wrap callback with completion block', () => {
|
|
31
|
+
const wrappedCallback = jest.fn();
|
|
32
|
+
const notification = new Notification_1.Notification({ identifier: 'identifier' });
|
|
33
|
+
uut.registerNotificationReceivedForeground(wrappedCallback);
|
|
34
|
+
const call = mockNativeEventsReceiver.registerNotificationReceived.mock.calls[0][0];
|
|
35
|
+
call(notification);
|
|
36
|
+
expect(wrappedCallback).toBeCalledWith(notification, expect.any(Function));
|
|
37
|
+
expect(wrappedCallback).toBeCalledTimes(1);
|
|
38
|
+
});
|
|
39
|
+
it('should wrap callback with completion block', () => {
|
|
40
|
+
const expectedNotification = new Notification_1.Notification({ identifier: 'identifier' });
|
|
41
|
+
uut.registerNotificationReceivedForeground((notification) => {
|
|
42
|
+
expect(notification).toEqual(expectedNotification);
|
|
43
|
+
});
|
|
44
|
+
const call = mockNativeEventsReceiver.registerNotificationReceived.mock.calls[0][0];
|
|
45
|
+
call(expectedNotification);
|
|
46
|
+
});
|
|
47
|
+
it('should invoke finishPresentingNotification', () => {
|
|
48
|
+
const notification = new Notification_1.Notification({ identifier: 'notificationId' });
|
|
49
|
+
const response = { alert: true };
|
|
50
|
+
uut.registerNotificationReceivedForeground((notification, completion) => {
|
|
51
|
+
completion(response);
|
|
52
|
+
expect(mockNativeCommandsSender.finishPresentingNotification).toBeCalledWith(notification.identifier, response);
|
|
53
|
+
});
|
|
54
|
+
const call = mockNativeEventsReceiver.registerNotificationReceived.mock.calls[0][0];
|
|
55
|
+
call(notification);
|
|
56
|
+
});
|
|
57
|
+
it('should not invoke finishPresentingNotification on Android', () => {
|
|
58
|
+
react_native_1.Platform.OS = 'android';
|
|
59
|
+
const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' });
|
|
60
|
+
const response = { alert: true };
|
|
61
|
+
uut.registerNotificationReceivedForeground((notification, completion) => {
|
|
62
|
+
completion(response);
|
|
63
|
+
expect(expectedNotification).toEqual(notification);
|
|
64
|
+
expect(mockNativeCommandsSender.finishPresentingNotification).toBeCalledTimes(0);
|
|
65
|
+
});
|
|
66
|
+
const call = mockNativeEventsReceiver.registerNotificationReceived.mock.calls[0][0];
|
|
67
|
+
call(expectedNotification);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('registerRemoteNotificationsReceivedBackground', () => {
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
react_native_1.AppState.currentState = 'background';
|
|
73
|
+
});
|
|
74
|
+
it('delegates to nativeEventsReceiver', () => {
|
|
75
|
+
const cb = jest.fn();
|
|
76
|
+
uut.registerNotificationReceivedBackground(cb);
|
|
77
|
+
expect(mockNativeEventsReceiver.registerNotificationReceivedBackground).toHaveBeenCalledTimes(1);
|
|
78
|
+
expect(mockNativeEventsReceiver.registerNotificationReceivedBackground).toHaveBeenCalledWith(expect.any(Function));
|
|
79
|
+
});
|
|
80
|
+
it('should wrap callback with completion block', () => {
|
|
81
|
+
const wrappedCallback = jest.fn();
|
|
82
|
+
const notification = new Notification_1.Notification({ identifier: 'identifier' });
|
|
83
|
+
uut.registerNotificationReceivedBackground(wrappedCallback);
|
|
84
|
+
const call = mockNativeEventsReceiver.registerNotificationReceivedBackground.mock.calls[0][0];
|
|
85
|
+
call(notification);
|
|
86
|
+
expect(wrappedCallback).toBeCalledWith(notification, expect.any(Function));
|
|
87
|
+
expect(wrappedCallback).toBeCalledTimes(1);
|
|
88
|
+
});
|
|
89
|
+
it('should wrap callback with completion block', () => {
|
|
90
|
+
const expectedNotification = new Notification_1.Notification({ identifier: 'identifier' });
|
|
91
|
+
uut.registerNotificationReceivedBackground((notification) => {
|
|
92
|
+
expect(notification).toEqual(expectedNotification);
|
|
93
|
+
});
|
|
94
|
+
const call = mockNativeEventsReceiver.registerNotificationReceivedBackground.mock.calls[0][0];
|
|
95
|
+
call(expectedNotification);
|
|
96
|
+
});
|
|
97
|
+
it('should invoke finishHandlingBackgroundAction', () => {
|
|
98
|
+
const notification = new Notification_1.Notification({ identifier: 'notificationId' });
|
|
99
|
+
const response = NotificationCompletion_1.NotificationBackgroundFetchResult.NO_DATA;
|
|
100
|
+
uut.registerNotificationReceivedBackground((notification, completion) => {
|
|
101
|
+
completion(response);
|
|
102
|
+
expect(mockNativeCommandsSender.finishHandlingBackgroundAction).toBeCalledWith(notification.identifier, response);
|
|
103
|
+
});
|
|
104
|
+
const call = mockNativeEventsReceiver.registerNotificationReceivedBackground.mock.calls[0][0];
|
|
105
|
+
call(notification);
|
|
106
|
+
});
|
|
107
|
+
it('should not invoke finishHandlingBackgroundAction on Android', () => {
|
|
108
|
+
react_native_1.Platform.OS = 'android';
|
|
109
|
+
const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' });
|
|
110
|
+
const response = NotificationCompletion_1.NotificationBackgroundFetchResult.NO_DATA;
|
|
111
|
+
uut.registerNotificationReceivedBackground((notification, completion) => {
|
|
112
|
+
completion(response);
|
|
113
|
+
expect(expectedNotification).toEqual(notification);
|
|
114
|
+
expect(mockNativeCommandsSender.finishHandlingBackgroundAction).toBeCalledTimes(0);
|
|
115
|
+
});
|
|
116
|
+
const call = mockNativeEventsReceiver.registerNotificationReceivedBackground.mock.calls[0][0];
|
|
117
|
+
call(expectedNotification);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
describe('', () => {
|
|
121
|
+
it('delegates to nativeEventsReceiver', () => {
|
|
122
|
+
const cb = jest.fn();
|
|
123
|
+
uut.registerNotificationOpened(cb);
|
|
124
|
+
expect(mockNativeEventsReceiver.registerNotificationOpened).toHaveBeenCalledTimes(1);
|
|
125
|
+
expect(mockNativeEventsReceiver.registerNotificationOpened).toHaveBeenCalledWith(expect.any(Function));
|
|
126
|
+
});
|
|
127
|
+
it('should wrap callback with completion block', () => {
|
|
128
|
+
const wrappedCallback = jest.fn();
|
|
129
|
+
const notification = new Notification_1.Notification({ identifier: 'identifier' });
|
|
130
|
+
const response = {
|
|
131
|
+
notification,
|
|
132
|
+
identifier: 'responseId',
|
|
133
|
+
action: { identifier: 'actionIdentifier', text: 'userText' },
|
|
134
|
+
};
|
|
135
|
+
uut.registerNotificationOpened(wrappedCallback);
|
|
136
|
+
const call = mockNativeEventsReceiver.registerNotificationOpened.mock.calls[0][0];
|
|
137
|
+
call(response.notification, response.action);
|
|
138
|
+
expect(wrappedCallback).toBeCalledWith(response.notification, expect.any(Function), response.action);
|
|
139
|
+
expect(wrappedCallback).toBeCalledTimes(1);
|
|
140
|
+
});
|
|
141
|
+
it('should wrap callback with completion block', () => {
|
|
142
|
+
const notification = new Notification_1.Notification({ identifier: 'identifier' });
|
|
143
|
+
uut.registerNotificationOpened((response) => {
|
|
144
|
+
expect(response).toEqual(notification);
|
|
145
|
+
});
|
|
146
|
+
const call = mockNativeEventsReceiver.registerNotificationOpened.mock.calls[0][0];
|
|
147
|
+
call(notification);
|
|
148
|
+
});
|
|
149
|
+
it('calling completion should invoke finishHandlingAction', () => {
|
|
150
|
+
const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' });
|
|
151
|
+
uut.registerNotificationOpened((notification, completion) => {
|
|
152
|
+
completion();
|
|
153
|
+
expect(expectedNotification).toEqual(notification);
|
|
154
|
+
expect(mockNativeCommandsSender.finishHandlingAction).toBeCalledWith(notification.identifier);
|
|
155
|
+
});
|
|
156
|
+
const call = mockNativeEventsReceiver.registerNotificationOpened.mock.calls[0][0];
|
|
157
|
+
call(expectedNotification);
|
|
158
|
+
});
|
|
159
|
+
it('should not invoke finishHandlingAction on Android', () => {
|
|
160
|
+
react_native_1.Platform.OS = 'android';
|
|
161
|
+
const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' });
|
|
162
|
+
uut.registerNotificationOpened((notification, completion) => {
|
|
163
|
+
completion();
|
|
164
|
+
expect(expectedNotification).toEqual(notification);
|
|
165
|
+
expect(mockNativeCommandsSender.finishHandlingAction).toBeCalledTimes(0);
|
|
166
|
+
});
|
|
167
|
+
const call = mockNativeEventsReceiver.registerNotificationOpened.mock.calls[0][0];
|
|
168
|
+
call(expectedNotification);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
it('delegates registerRemoteNotificationsRegistered to nativeEventsReceiver', () => {
|
|
172
|
+
const cb = jest.fn();
|
|
173
|
+
uut.registerRemoteNotificationsRegistered(cb);
|
|
174
|
+
expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistered).toHaveBeenCalledTimes(1);
|
|
175
|
+
expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistered).toHaveBeenCalledWith(cb);
|
|
176
|
+
});
|
|
177
|
+
it('delegates registerRemoteNotificationsRegistrationFailed to nativeEventsReceiver', () => {
|
|
178
|
+
const cb = jest.fn();
|
|
179
|
+
uut.registerRemoteNotificationsRegistrationFailed(cb);
|
|
180
|
+
expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistrationFailed).toHaveBeenCalledTimes(1);
|
|
181
|
+
expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistrationFailed).toHaveBeenCalledWith(cb);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EmitterSubscription } from 'react-native';
|
|
2
|
+
import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
|
|
3
|
+
import { RegisteredPushKit } from '../interfaces/NotificationEvents';
|
|
4
|
+
import { CompletionCallbackWrapper } from '../adapters/CompletionCallbackWrapper';
|
|
5
|
+
export declare class EventsRegistryIOS {
|
|
6
|
+
private nativeEventsReceiver;
|
|
7
|
+
private completionCallbackWrapper;
|
|
8
|
+
constructor(nativeEventsReceiver: NativeEventsReceiver, completionCallbackWrapper: CompletionCallbackWrapper);
|
|
9
|
+
registerPushKitRegistered(callback: (event: RegisteredPushKit) => void): EmitterSubscription;
|
|
10
|
+
registerPushKitNotificationReceived(callback: (event: object, completion: () => void) => void): EmitterSubscription;
|
|
11
|
+
appNotificationSettingsLinked(callback: () => void): EmitterSubscription;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventsRegistryIOS = void 0;
|
|
4
|
+
class EventsRegistryIOS {
|
|
5
|
+
nativeEventsReceiver;
|
|
6
|
+
completionCallbackWrapper;
|
|
7
|
+
constructor(nativeEventsReceiver, completionCallbackWrapper) {
|
|
8
|
+
this.nativeEventsReceiver = nativeEventsReceiver;
|
|
9
|
+
this.completionCallbackWrapper = completionCallbackWrapper;
|
|
10
|
+
}
|
|
11
|
+
registerPushKitRegistered(callback) {
|
|
12
|
+
return this.nativeEventsReceiver.registerPushKitRegistered(callback);
|
|
13
|
+
}
|
|
14
|
+
registerPushKitNotificationReceived(callback) {
|
|
15
|
+
return this.nativeEventsReceiver.registerPushKitNotificationReceived(this.completionCallbackWrapper.wrapOpenedCallback(callback));
|
|
16
|
+
}
|
|
17
|
+
appNotificationSettingsLinked(callback) {
|
|
18
|
+
return this.nativeEventsReceiver.appNotificationSettingsLinked(callback);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.EventsRegistryIOS = EventsRegistryIOS;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const EventsRegistryIOS_1 = require("./EventsRegistryIOS");
|
|
4
|
+
const CompletionCallbackWrapper_1 = require("../adapters/CompletionCallbackWrapper");
|
|
5
|
+
const NativeCommandsSender_1 = require("../adapters/NativeCommandsSender");
|
|
6
|
+
const NativeEventsReceiver_1 = require("../adapters/NativeEventsReceiver");
|
|
7
|
+
jest.mock('../adapters/NativeCommandsSender');
|
|
8
|
+
jest.mock('../adapters/NativeEventsReceiver');
|
|
9
|
+
describe('EventsRegistryIOS', () => {
|
|
10
|
+
let uut;
|
|
11
|
+
const mockNativeEventsReceiver = new NativeEventsReceiver_1.NativeEventsReceiver();
|
|
12
|
+
const mockNativeCommandsSender = new NativeCommandsSender_1.NativeCommandsSender();
|
|
13
|
+
const completionCallbackWrapper = new CompletionCallbackWrapper_1.CompletionCallbackWrapper(mockNativeCommandsSender);
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
uut = new EventsRegistryIOS_1.EventsRegistryIOS(mockNativeEventsReceiver, completionCallbackWrapper);
|
|
16
|
+
});
|
|
17
|
+
it('delegates registerPushKitRegistered to nativeEventsReceiver', () => {
|
|
18
|
+
const cb = jest.fn();
|
|
19
|
+
uut.registerPushKitRegistered(cb);
|
|
20
|
+
expect(mockNativeEventsReceiver.registerPushKitRegistered).toHaveBeenCalledTimes(1);
|
|
21
|
+
expect(mockNativeEventsReceiver.registerPushKitRegistered).toHaveBeenCalledWith(cb);
|
|
22
|
+
});
|
|
23
|
+
it('delegates registerPushKitNotificationReceived to nativeEventsReceiver', () => {
|
|
24
|
+
const cb = jest.fn();
|
|
25
|
+
uut.registerPushKitNotificationReceived(cb);
|
|
26
|
+
expect(mockNativeEventsReceiver.registerPushKitNotificationReceived).toHaveBeenCalledTimes(1);
|
|
27
|
+
expect(mockNativeEventsReceiver.registerPushKitNotificationReceived).toHaveBeenCalledWith(expect.any(Function));
|
|
28
|
+
});
|
|
29
|
+
it('should wrap callback with completion block', () => {
|
|
30
|
+
const expectedNotification = { identifier: 'notificationId' };
|
|
31
|
+
uut.registerPushKitNotificationReceived((notification) => {
|
|
32
|
+
expect(notification).toEqual(expectedNotification);
|
|
33
|
+
});
|
|
34
|
+
const call = mockNativeEventsReceiver.registerPushKitNotificationReceived.mock.calls[0][0];
|
|
35
|
+
call(expectedNotification);
|
|
36
|
+
});
|
|
37
|
+
it('should invoke finishPresentingNotification', () => {
|
|
38
|
+
const expectedNotification = { identifier: 'notificationId' };
|
|
39
|
+
uut.registerPushKitNotificationReceived((notification, completion) => {
|
|
40
|
+
completion();
|
|
41
|
+
expect(notification).toEqual(expectedNotification);
|
|
42
|
+
expect(mockNativeCommandsSender.finishHandlingAction).toBeCalledWith('notificationId');
|
|
43
|
+
});
|
|
44
|
+
const call = mockNativeEventsReceiver.registerPushKitNotificationReceived.mock.calls[0][0];
|
|
45
|
+
call(expectedNotification);
|
|
46
|
+
});
|
|
47
|
+
it('delegates appNotificationSettingsLinked to nativeEventsReceiver', () => {
|
|
48
|
+
const cb = jest.fn();
|
|
49
|
+
uut.appNotificationSettingsLinked(cb);
|
|
50
|
+
expect(mockNativeEventsReceiver.appNotificationSettingsLinked).toHaveBeenCalledTimes(1);
|
|
51
|
+
expect(mockNativeEventsReceiver.appNotificationSettingsLinked).toHaveBeenCalledWith(cb);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NotificationsRoot } from './Notifications';
|
|
2
|
+
export declare const Notifications: NotificationsRoot;
|
|
3
|
+
export * from './interfaces/EventSubscription';
|
|
4
|
+
export * from './DTO/Notification';
|
|
5
|
+
export * from './interfaces/NotificationEvents';
|
|
6
|
+
export * from './interfaces/NotificationCategory';
|
|
7
|
+
export * from './interfaces/NotificationCompletion';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Notifications = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Notifications_1 = require("./Notifications");
|
|
6
|
+
const notificationsSingleton = new Notifications_1.NotificationsRoot();
|
|
7
|
+
exports.Notifications = notificationsSingleton;
|
|
8
|
+
tslib_1.__exportStar(require("./interfaces/EventSubscription"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./DTO/Notification"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./interfaces/NotificationEvents"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./interfaces/NotificationCategory"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./interfaces/NotificationCompletion"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationActionResponse = void 0;
|
|
4
|
+
class NotificationActionResponse {
|
|
5
|
+
identifier;
|
|
6
|
+
text;
|
|
7
|
+
constructor(response) {
|
|
8
|
+
this.identifier = response.identifier;
|
|
9
|
+
this.text = response.text;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.NotificationActionResponse = NotificationActionResponse;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class NotificationCategory {
|
|
2
|
+
identifier: string;
|
|
3
|
+
actions?: NotificationAction[];
|
|
4
|
+
constructor(identifier: string, actions?: NotificationAction[]);
|
|
5
|
+
}
|
|
6
|
+
export interface NotificationTextInput {
|
|
7
|
+
buttonTitle: string;
|
|
8
|
+
placeholder: string;
|
|
9
|
+
}
|
|
10
|
+
export type ActivationMode = 'background' | 'foreground' | 'authenticationRequired' | 'destructive';
|
|
11
|
+
export declare class NotificationAction {
|
|
12
|
+
identifier: string;
|
|
13
|
+
activationMode: ActivationMode;
|
|
14
|
+
title: string;
|
|
15
|
+
authenticationRequired: boolean;
|
|
16
|
+
textInput?: NotificationTextInput;
|
|
17
|
+
constructor(identifier: string, activationMode: ActivationMode, title: string, authenticationRequired: boolean, textInput?: NotificationTextInput);
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotificationAction = exports.NotificationCategory = void 0;
|
|
4
|
+
class NotificationCategory {
|
|
5
|
+
identifier;
|
|
6
|
+
actions;
|
|
7
|
+
constructor(identifier, actions) {
|
|
8
|
+
this.identifier = identifier;
|
|
9
|
+
this.actions = actions;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.NotificationCategory = NotificationCategory;
|
|
13
|
+
class NotificationAction {
|
|
14
|
+
identifier;
|
|
15
|
+
activationMode;
|
|
16
|
+
title;
|
|
17
|
+
authenticationRequired;
|
|
18
|
+
textInput;
|
|
19
|
+
constructor(identifier, activationMode, title, authenticationRequired, textInput) {
|
|
20
|
+
this.identifier = identifier;
|
|
21
|
+
this.activationMode = activationMode;
|
|
22
|
+
this.title = title;
|
|
23
|
+
this.authenticationRequired = authenticationRequired;
|
|
24
|
+
this.textInput = textInput;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.NotificationAction = NotificationAction;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface NotificationChannel {
|
|
2
|
+
channelId: string;
|
|
3
|
+
name: string;
|
|
4
|
+
importance: -1000 | 0 | 1 | 2 | 3 | 4 | 5;
|
|
5
|
+
description?: string;
|
|
6
|
+
enableLights?: boolean;
|
|
7
|
+
enableVibration?: boolean;
|
|
8
|
+
groupId?: string;
|
|
9
|
+
groupName?: string;
|
|
10
|
+
lightColor?: string;
|
|
11
|
+
showBadge?: boolean;
|
|
12
|
+
soundFile?: string;
|
|
13
|
+
vibrationPattern?: number[];
|
|
14
|
+
}
|