Commit 63b7f8cc authored by 冷佳娟's avatar 冷佳娟 💪

update dist js

parent 5257154b
/build
google-services.json
\ No newline at end of file
export declare class Notification {
identifier: string;
private _data?;
constructor(payload: object);
readonly data: any;
readonly title: string;
readonly body: string;
readonly sound: string;
readonly badge: number;
readonly type: string;
readonly thread: string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Notification {
constructor(payload) {
this._data = payload;
this.identifier = this._data.identifier;
}
get data() {
return this._data;
}
get title() {
return this._data.title;
}
get body() {
return this._data.body;
}
get sound() {
return this._data.sound;
}
get badge() {
return this._data.badge;
}
get type() {
return this._data.type;
}
get thread() {
return this._data.thread;
}
}
exports.Notification = Notification;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Notification_1 = require("./Notification");
describe('Notification', () => {
it('Should create notification with payload', () => {
const payload = { p: 'p' };
const notification = new Notification_1.Notification(payload);
expect(notification.data).toEqual(payload);
});
it('Should create notification with identifier', () => {
const payload = { identifier: 'identifier' };
const notification = new Notification_1.Notification(payload);
expect(notification.identifier).toEqual(payload.identifier);
});
it('Should return title from payload', () => {
const payload = { title: 'title' };
const notification = new Notification_1.Notification(payload);
expect(notification.title).toEqual(payload.title);
});
it('Should return body from payload', () => {
const payload = { body: 'body' };
const notification = new Notification_1.Notification(payload);
expect(notification.body).toEqual(payload.body);
});
it('Should return sound from payload', () => {
const payload = { sound: 'sound.mp4' };
const notification = new Notification_1.Notification(payload);
expect(notification.sound).toEqual(payload.sound);
});
it('Should return badge from payload', () => {
const payload = { badge: 1 };
const notification = new Notification_1.Notification(payload);
expect(notification.badge).toEqual(payload.badge);
});
it('Should return type from payload', () => {
const payload = { type: 'type' };
const notification = new Notification_1.Notification(payload);
expect(notification.type).toEqual(payload.type);
});
it('Should return thread from payload', () => {
const payload = { thread: 'thread' };
const notification = new Notification_1.Notification(payload);
expect(notification.thread).toEqual(payload.thread);
});
});
import { EventsRegistry } from './events/EventsRegistry';
import { Notification } from './DTO/Notification';
import { NotificationCategory } from './interfaces/NotificationCategory';
import { NotificationsIOS } from './NotificationsIOS';
import { NotificationsAndroid } from './NotificationsAndroid';
export declare class NotificationsRoot {
readonly ios: NotificationsIOS;
readonly android: NotificationsAndroid;
private readonly nativeEventsReceiver;
private readonly nativeCommandsSender;
private readonly commands;
private readonly eventsRegistry;
private readonly eventsRegistryIOS;
private readonly uniqueIdProvider;
private readonly completionCallbackWrapper;
constructor();
/**
* registerRemoteNotifications
*/
registerRemoteNotifications(): void;
/**
* postLocalNotification
*/
postLocalNotification(notification: Notification, id: number): void;
/**
* getInitialNotification
*/
getInitialNotification(): Promise<Notification | undefined>;
/**
* setCategories
*/
setCategories(categories: [NotificationCategory?]): void;
/**
* cancelLocalNotification
*/
cancelLocalNotification(notificationId: string): void;
/**
* isRegisteredForRemoteNotifications
*/
isRegisteredForRemoteNotifications(): Promise<boolean>;
/**
* Obtain the events registry instance
*/
events(): EventsRegistry;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const NativeCommandsSender_1 = require("./adapters/NativeCommandsSender");
const NativeEventsReceiver_1 = require("./adapters/NativeEventsReceiver");
const Commands_1 = require("./commands/Commands");
const EventsRegistry_1 = require("./events/EventsRegistry");
const EventsRegistryIOS_1 = require("./events/EventsRegistryIOS");
const UniqueIdProvider_1 = require("./adapters/UniqueIdProvider");
const CompletionCallbackWrapper_1 = require("./adapters/CompletionCallbackWrapper");
const NotificationsIOS_1 = require("./NotificationsIOS");
const NotificationsAndroid_1 = require("./NotificationsAndroid");
class NotificationsRoot {
constructor() {
this.nativeEventsReceiver = new NativeEventsReceiver_1.NativeEventsReceiver();
this.nativeCommandsSender = new NativeCommandsSender_1.NativeCommandsSender();
this.completionCallbackWrapper = new CompletionCallbackWrapper_1.CompletionCallbackWrapper(this.nativeCommandsSender);
this.uniqueIdProvider = new UniqueIdProvider_1.UniqueIdProvider();
this.commands = new Commands_1.Commands(this.nativeCommandsSender, this.uniqueIdProvider);
this.eventsRegistry = new EventsRegistry_1.EventsRegistry(this.nativeEventsReceiver, this.completionCallbackWrapper);
this.eventsRegistryIOS = new EventsRegistryIOS_1.EventsRegistryIOS(this.nativeEventsReceiver);
this.ios = new NotificationsIOS_1.NotificationsIOS(this.commands, this.eventsRegistryIOS);
this.android = new NotificationsAndroid_1.NotificationsAndroid(this.commands);
}
/**
* registerRemoteNotifications
*/
registerRemoteNotifications() {
this.ios.registerRemoteNotifications();
this.android.registerRemoteNotifications();
}
/**
* postLocalNotification
*/
postLocalNotification(notification, id) {
return this.commands.postLocalNotification(notification, id);
}
/**
* getInitialNotification
*/
getInitialNotification() {
return this.commands.getInitialNotification();
}
/**
* setCategories
*/
setCategories(categories) {
this.commands.setCategories(categories);
}
/**
* cancelLocalNotification
*/
cancelLocalNotification(notificationId) {
return this.commands.cancelLocalNotification(notificationId);
}
/**
* isRegisteredForRemoteNotifications
*/
isRegisteredForRemoteNotifications() {
return this.commands.isRegisteredForRemoteNotifications();
}
/**
* Obtain the events registry instance
*/
events() {
return this.eventsRegistry;
}
}
exports.NotificationsRoot = NotificationsRoot;
import { Commands } from './commands/Commands';
export declare class NotificationsAndroid {
private readonly commands;
constructor(commands: Commands);
/**
* Refresh FCM token
*/
registerRemoteNotifications(): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
class NotificationsAndroid {
constructor(commands) {
this.commands = commands;
return new Proxy(this, {
get(target, name) {
if (react_native_1.Platform.OS === 'android') {
return target[name];
}
else {
return () => { };
}
}
});
}
/**
* Refresh FCM token
*/
registerRemoteNotifications() {
this.commands.refreshToken();
}
}
exports.NotificationsAndroid = NotificationsAndroid;
import { Notification } from './DTO/Notification';
import { Commands } from './commands/Commands';
import { EventsRegistryIOS } from './events/EventsRegistryIOS';
export declare class NotificationsIOS {
private readonly commands;
private readonly eventsRegistry;
constructor(commands: Commands, eventsRegistry: EventsRegistryIOS);
/**
* Request permissions to send remote notifications
*/
registerRemoteNotifications(): void;
/**
* Unregister for all remote notifications received via Apple Push Notification service
*/
abandonPermissions(): void;
/**
* registerPushKit
*/
registerPushKit(): void;
/**
* getBadgesCount
*/
getBadgeCount(): Promise<number>;
/**
* setBadgeCount
* @param count number of the new badge count
*/
setBadgeCount(count: number): void;
/**
* cancelAllLocalNotifications
*/
cancelAllLocalNotifications(): void;
/**
* checkPermissions
*/
checkPermissions(): Promise<import("./interfaces/NotificationPermissions").NotificationPermissions>;
/**
* removeAllDeliveredNotifications
*/
removeAllDeliveredNotifications(): void;
/**
* removeDeliveredNotifications
* @param identifiers Array of notification identifiers
*/
removeDeliveredNotifications(identifiers: Array<string>): void;
/**
* getDeliveredNotifications
*/
getDeliveredNotifications(): Array<Notification>;
/**
* Obtain the events registry instance
*/
events(): EventsRegistryIOS;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
class NotificationsIOS {
constructor(commands, eventsRegistry) {
this.commands = commands;
this.eventsRegistry = eventsRegistry;
return new Proxy(this, {
get(target, name) {
if (react_native_1.Platform.OS === 'ios') {
return target[name];
}
else {
return () => { };
}
}
});
}
/**
* Request permissions to send remote notifications
*/
registerRemoteNotifications() {
return this.commands.requestPermissions();
}
/**
* Unregister for all remote notifications received via Apple Push Notification service
*/
abandonPermissions() {
return this.commands.abandonPermissions();
}
/**
* registerPushKit
*/
registerPushKit() {
return this.commands.registerPushKit();
}
/**
* getBadgesCount
*/
getBadgeCount() {
return this.commands.getBadgeCount();
}
/**
* setBadgeCount
* @param count number of the new badge count
*/
setBadgeCount(count) {
return this.commands.setBadgeCount(count);
}
/**
* cancelAllLocalNotifications
*/
cancelAllLocalNotifications() {
this.commands.cancelAllLocalNotifications();
}
/**
* checkPermissions
*/
checkPermissions() {
return this.commands.checkPermissions();
}
/**
* removeAllDeliveredNotifications
*/
removeAllDeliveredNotifications() {
return this.commands.removeAllDeliveredNotifications();
}
/**
* removeDeliveredNotifications
* @param identifiers Array of notification identifiers
*/
removeDeliveredNotifications(identifiers) {
return this.commands.removeDeliveredNotifications(identifiers);
}
/**
* getDeliveredNotifications
*/
getDeliveredNotifications() {
return this.commands.getDeliveredNotifications();
}
/**
* Obtain the events registry instance
*/
events() {
return this.eventsRegistry;
}
}
exports.NotificationsIOS = NotificationsIOS;
import { NativeCommandsSender } from './NativeCommandsSender';
import { Notification } from '../DTO/Notification';
export declare class CompletionCallbackWrapper {
private readonly nativeCommandsSender;
constructor(nativeCommandsSender: NativeCommandsSender);
wrapReceivedCallback(callback: Function): (notification: Notification) => void;
wrapOpenedCallback(callback: Function): (notification: Notification) => void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
class CompletionCallbackWrapper {
constructor(nativeCommandsSender) {
this.nativeCommandsSender = nativeCommandsSender;
}
wrapReceivedCallback(callback) {
return (notification) => {
const completion = (response) => {
if (react_native_1.Platform.OS === 'ios') {
this.nativeCommandsSender.finishPresentingNotification(notification.identifier, response);
}
};
callback(notification, completion);
};
}
wrapOpenedCallback(callback) {
return (notification) => {
const completion = () => {
if (react_native_1.Platform.OS === 'ios') {
this.nativeCommandsSender.finishHandlingAction(notification.identifier);
}
};
callback(notification, completion);
};
}
}
exports.CompletionCallbackWrapper = CompletionCallbackWrapper;
import { Notification } from '../DTO/Notification';
import { NotificationCompletion } from '../interfaces/NotificationCompletion';
import { NotificationPermissions } from '../interfaces/NotificationPermissions';
import { NotificationCategory } from '../interfaces/NotificationCategory';
export declare class NativeCommandsSender {
private readonly nativeCommandsModule;
constructor();
postLocalNotification(notification: Notification, id: number): void;
getInitialNotification(): Promise<Object>;
requestPermissions(): void;
abandonPermissions(): void;
refreshToken(): void;
registerPushKit(): void;
setCategories(categories: [NotificationCategory?]): void;
getBadgeCount(): Promise<number>;
setBadgeCount(count: number): void;
cancelLocalNotification(notificationId: string): void;
cancelAllLocalNotifications(): void;
isRegisteredForRemoteNotifications(): Promise<any>;
checkPermissions(): Promise<NotificationPermissions>;
removeAllDeliveredNotifications(): void;
removeDeliveredNotifications(identifiers: Array<string>): void;
getDeliveredNotifications(): Array<Notification>;
finishPresentingNotification(notificationId: string, notificationCompletion: NotificationCompletion): void;
finishHandlingAction(notificationId: string): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
class NativeCommandsSender {
constructor() {
this.nativeCommandsModule = react_native_1.NativeModules.RNBridgeModule;
}
postLocalNotification(notification, id) {
return this.nativeCommandsModule.postLocalNotification(notification, id);
}
getInitialNotification() {
return this.nativeCommandsModule.getInitialNotification();
}
requestPermissions() {
return this.nativeCommandsModule.requestPermissions();
}
abandonPermissions() {
return this.nativeCommandsModule.abandonPermissions();
}
refreshToken() {
this.nativeCommandsModule.refreshToken();
}
registerPushKit() {
return this.nativeCommandsModule.registerPushKit();
}
setCategories(categories) {
this.nativeCommandsModule.setCategories(categories);
}
getBadgeCount() {
return this.nativeCommandsModule.getBadgeCount();
}
setBadgeCount(count) {
this.nativeCommandsModule.setBadgeCount(count);
}
cancelLocalNotification(notificationId) {
this.nativeCommandsModule.cancelLocalNotification(notificationId);
}
cancelAllLocalNotifications() {
this.nativeCommandsModule.cancelAllLocalNotifications();
}
isRegisteredForRemoteNotifications() {
return this.nativeCommandsModule.isRegisteredForRemoteNotifications();
}
checkPermissions() {
return this.nativeCommandsModule.checkPermissions();
}
removeAllDeliveredNotifications() {
return this.nativeCommandsModule.removeAllDeliveredNotifications();
}
removeDeliveredNotifications(identifiers) {
return this.nativeCommandsModule.removeDeliveredNotifications(identifiers);
}
getDeliveredNotifications() {
return this.nativeCommandsModule.getDeliveredNotifications();
}
finishPresentingNotification(notificationId, notificationCompletion) {
this.nativeCommandsModule.finishPresentingNotification(notificationId, notificationCompletion);
}
finishHandlingAction(notificationId) {
this.nativeCommandsModule.finishHandlingAction(notificationId);
}
}
exports.NativeCommandsSender = NativeCommandsSender;
export declare const NativeCommandsSender: any;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NativeCommandsSender = jest.genMockFromModule('./NativeCommandsSender').NativeCommandsSender;
import { EmitterSubscription } from 'react-native';
import { Registered, RegistrationError, RegisteredPushKit } from '../interfaces/NotificationEvents';
import { Notification } from '../DTO/Notification';
import { NotificationActionResponse } from '../interfaces/NotificationActionResponse';
export declare class NativeEventsReceiver {
private emitter;
constructor();
registerRemoteNotificationsRegistered(callback: (event: Registered) => void): EmitterSubscription;
registerPushKitRegistered(callback: (event: RegisteredPushKit) => void): EmitterSubscription;
registerRemoteNotificationReceived(callback: (notification: Notification) => void): EmitterSubscription;
registerPushKitNotificationReceived(callback: (event: object) => void): EmitterSubscription;
registerRemoteNotificationOpened(callback: (notification: Notification, completion: () => void, actionResponse?: NotificationActionResponse) => void): EmitterSubscription;
registerRemoteNotificationsRegistrationFailed(callback: (event: RegistrationError) => void): EmitterSubscription;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
const Notification_1 = require("../DTO/Notification");
const NotificationActionResponse_1 = require("../interfaces/NotificationActionResponse");
class NativeEventsReceiver {
constructor() {
this.emitter = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.RNEventEmitter);
}
registerRemoteNotificationsRegistered(callback) {
return this.emitter.addListener('remoteNotificationsRegistered', callback);
}
registerPushKitRegistered(callback) {
return this.emitter.addListener('pushKitRegistered', callback);
}
registerRemoteNotificationReceived(callback) {
return this.emitter.addListener('notificationReceived', (payload) => {
callback(new Notification_1.Notification(payload));
});
}
registerPushKitNotificationReceived(callback) {
return this.emitter.addListener('pushKitNotificationReceived', callback);
}
registerRemoteNotificationOpened(callback) {
return this.emitter.addListener('notificationOpened', (response, completion) => {
const action = response.action ? new NotificationActionResponse_1.NotificationActionResponse(response.action) : undefined;
callback(new Notification_1.Notification(response.notification), completion, action);
});
}
registerRemoteNotificationsRegistrationFailed(callback) {
return this.emitter.addListener('remoteNotificationsRegistrationFailed', callback);
}
}
exports.NativeEventsReceiver = NativeEventsReceiver;
export declare const NativeEventsReceiver: any;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NativeEventsReceiver = jest.genMockFromModule('./NativeEventsReceiver').NativeEventsReceiver;
export declare class UniqueIdProvider {
generate(): number;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
class UniqueIdProvider {
generate() {
return parseInt(_.uniqueId());
}
}
exports.UniqueIdProvider = UniqueIdProvider;
import { NativeCommandsSender } from '../adapters/NativeCommandsSender';
import { Notification } from '../DTO/Notification';
import { NotificationCategory } from '../interfaces/NotificationCategory';
import { NotificationPermissions } from '../interfaces/NotificationPermissions';
import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
export declare class Commands {
private readonly nativeCommandsSender;
private readonly uniqueIdProvider;
constructor(nativeCommandsSender: NativeCommandsSender, uniqueIdProvider: UniqueIdProvider);
postLocalNotification(notification: Notification, id?: number): void;
getInitialNotification(): Promise<Notification | undefined>;
requestPermissions(): void;
abandonPermissions(): void;
registerPushKit(): void;
setCategories(categories: [NotificationCategory?]): void;
getBadgeCount(): Promise<number>;
setBadgeCount(count: number): void;
cancelLocalNotification(notificationId: string): void;
cancelAllLocalNotifications(): void;
isRegisteredForRemoteNotifications(): Promise<boolean>;
checkPermissions(): Promise<NotificationPermissions>;
removeAllDeliveredNotifications(): void;
removeDeliveredNotifications(identifiers: Array<string>): void;
getDeliveredNotifications(): Array<Notification>;
refreshToken(): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Notification_1 = require("../DTO/Notification");
class Commands {
constructor(nativeCommandsSender, uniqueIdProvider) {
this.nativeCommandsSender = nativeCommandsSender;
this.uniqueIdProvider = uniqueIdProvider;
}
postLocalNotification(notification, id) {
const notificationId = id ? id : this.uniqueIdProvider.generate();
const result = this.nativeCommandsSender.postLocalNotification(notification, notificationId);
return result;
}
async getInitialNotification() {
return this.nativeCommandsSender.getInitialNotification().then((payload) => {
if (payload) {
return new Notification_1.Notification(payload);
}
return undefined;
});
}
requestPermissions() {
const result = this.nativeCommandsSender.requestPermissions();
return result;
}
abandonPermissions() {
const result = this.nativeCommandsSender.abandonPermissions();
return result;
}
registerPushKit() {
this.nativeCommandsSender.registerPushKit();
}
setCategories(categories) {
this.nativeCommandsSender.setCategories(categories);
}
getBadgeCount() {
return this.nativeCommandsSender.getBadgeCount();
}
setBadgeCount(count) {
this.nativeCommandsSender.setBadgeCount(count);
}
cancelLocalNotification(notificationId) {
this.nativeCommandsSender.cancelLocalNotification(notificationId);
}
cancelAllLocalNotifications() {
this.nativeCommandsSender.cancelAllLocalNotifications();
}
isRegisteredForRemoteNotifications() {
return this.nativeCommandsSender.isRegisteredForRemoteNotifications();
}
checkPermissions() {
return this.nativeCommandsSender.checkPermissions();
}
removeAllDeliveredNotifications() {
this.nativeCommandsSender.removeAllDeliveredNotifications();
}
removeDeliveredNotifications(identifiers) {
return this.nativeCommandsSender.removeDeliveredNotifications(identifiers);
}
getDeliveredNotifications() {
return this.nativeCommandsSender.getDeliveredNotifications();
}
refreshToken() {
this.nativeCommandsSender.refreshToken();
}
}
exports.Commands = Commands;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ts_mockito_1 = require("ts-mockito");
const Commands_1 = require("./Commands");
const NativeCommandsSender_1 = require("../adapters/NativeCommandsSender");
const Notification_1 = require("../DTO/Notification");
const UniqueIdProvider_1 = require("../adapters/UniqueIdProvider");
describe('Commands', () => {
let uut;
let mockedNativeCommandsSender;
let mockedUniqueIdProvider;
beforeEach(() => {
mockedNativeCommandsSender = ts_mockito_1.mock(NativeCommandsSender_1.NativeCommandsSender);
mockedUniqueIdProvider = ts_mockito_1.mock(UniqueIdProvider_1.UniqueIdProvider);
ts_mockito_1.when(mockedUniqueIdProvider.generate()).thenCall(() => 12);
uut = new Commands_1.Commands(ts_mockito_1.instance(mockedNativeCommandsSender), ts_mockito_1.instance(mockedUniqueIdProvider));
});
describe('getInitialNotification', () => {
it('sends to native', () => {
uut.getInitialNotification();
ts_mockito_1.verify(mockedNativeCommandsSender.getInitialNotification()).called();
});
it('returns a promise with the initial notification', async () => {
const expectedNotification = new Notification_1.Notification({ identifier: 'id' });
ts_mockito_1.when(mockedNativeCommandsSender.getInitialNotification()).thenResolve({ identifier: 'id' });
const result = await uut.getInitialNotification();
expect(result).toEqual(expectedNotification);
});
});
describe('requestPermissions', () => {
it('sends to native', () => {
uut.requestPermissions();
ts_mockito_1.verify(mockedNativeCommandsSender.requestPermissions()).called();
});
});
describe('registerPushKit', () => {
it('sends to native', () => {
uut.registerPushKit();
ts_mockito_1.verify(mockedNativeCommandsSender.registerPushKit()).called();
});
});
describe('setCategories', () => {
it('sends to native', () => {
const emptyCategoriesArray = [];
uut.setCategories(emptyCategoriesArray);
ts_mockito_1.verify(mockedNativeCommandsSender.setCategories(emptyCategoriesArray)).called();
});
it('sends to native with categories', () => {
const category = { identifier: 'id', actions: [] };
const categoriesArray = [category];
uut.setCategories(categoriesArray);
ts_mockito_1.verify(mockedNativeCommandsSender.setCategories(categoriesArray)).called();
});
});
describe('abandonPermissions', () => {
it('sends to native', () => {
uut.abandonPermissions();
ts_mockito_1.verify(mockedNativeCommandsSender.abandonPermissions()).called();
});
});
describe('postLocalNotification', () => {
it('sends to native', () => {
const notification = new Notification_1.Notification({ identifier: 'id' });
uut.postLocalNotification(notification);
ts_mockito_1.verify(mockedNativeCommandsSender.postLocalNotification(notification, ts_mockito_1.anyNumber())).called();
});
it('generates unique identifier', () => {
const notification = new Notification_1.Notification({ identifier: 'id' });
uut.postLocalNotification(notification);
ts_mockito_1.verify(mockedNativeCommandsSender.postLocalNotification(notification, ts_mockito_1.anyNumber())).called();
});
it('use passed notification id', () => {
const notification = new Notification_1.Notification({ identifier: 'id' });
const passedId = 2;
uut.postLocalNotification(notification, passedId);
ts_mockito_1.verify(mockedNativeCommandsSender.postLocalNotification(notification, passedId)).called();
});
});
describe('getBadgeCount', () => {
it('sends to native', () => {
uut.getBadgeCount();
ts_mockito_1.verify(mockedNativeCommandsSender.getBadgeCount()).called();
});
});
describe('setBadgeCount', () => {
it('sends to native', () => {
uut.setBadgeCount(10);
ts_mockito_1.verify(mockedNativeCommandsSender.setBadgeCount(10)).called();
});
});
describe('cancelLocalNotification', () => {
it('sends to native', () => {
uut.cancelLocalNotification("notificationId");
ts_mockito_1.verify(mockedNativeCommandsSender.cancelLocalNotification("notificationId")).called();
});
});
describe('cancelAllLocalNotifications', () => {
it('sends to native', () => {
uut.cancelAllLocalNotifications();
ts_mockito_1.verify(mockedNativeCommandsSender.cancelAllLocalNotifications()).called();
});
});
describe('isRegisteredForRemoteNotifications', () => {
it('sends to native', () => {
uut.isRegisteredForRemoteNotifications();
ts_mockito_1.verify(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).called();
});
it('return positive response from native', async () => {
ts_mockito_1.when(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).thenResolve(true);
const isRegistered = await uut.isRegisteredForRemoteNotifications();
ts_mockito_1.verify(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).called();
expect(isRegistered).toEqual(true);
});
it('return negative response from native', async () => {
ts_mockito_1.when(mockedNativeCommandsSender.isRegisteredForRemoteNotifications()).thenResolve(false);
const isRegistered = await uut.isRegisteredForRemoteNotifications();
expect(isRegistered).toEqual(false);
});
});
describe('checkPermissions', () => {
it('sends to native', () => {
uut.checkPermissions();
ts_mockito_1.verify(mockedNativeCommandsSender.checkPermissions()).called();
});
it('return negative response from native', async () => {
const expectedPermissions = { badge: false, alert: true, sound: false };
ts_mockito_1.when(mockedNativeCommandsSender.checkPermissions()).thenResolve(expectedPermissions);
const permissions = await uut.checkPermissions();
expect(permissions).toEqual(expectedPermissions);
});
});
describe('removeAllDeliveredNotifications', () => {
it('sends to native', () => {
uut.removeAllDeliveredNotifications();
ts_mockito_1.verify(mockedNativeCommandsSender.removeAllDeliveredNotifications()).called();
});
});
describe('removeDeliveredNotifications', async () => {
it('sends to native', () => {
const identifiers = ["id1", "id2"];
uut.removeDeliveredNotifications(identifiers);
ts_mockito_1.verify(mockedNativeCommandsSender.removeDeliveredNotifications(identifiers)).called();
});
});
describe('getDeliveredNotifications', () => {
it('sends to native', () => {
uut.getDeliveredNotifications();
ts_mockito_1.verify(mockedNativeCommandsSender.getDeliveredNotifications()).called();
});
});
describe('refreshToken', () => {
it('sends to native', () => {
uut.refreshToken();
ts_mockito_1.verify(mockedNativeCommandsSender.refreshToken()).called();
});
});
});
import { EmitterSubscription } from 'react-native';
import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
import { Registered, RegistrationError, NotificationResponse } from '../interfaces/NotificationEvents';
import { CompletionCallbackWrapper } from '../adapters/CompletionCallbackWrapper';
import { Notification } from '../DTO/Notification';
import { NotificationCompletion } from '../interfaces/NotificationCompletion';
export declare class EventsRegistry {
private nativeEventsReceiver;
private completionCallbackWrapper;
constructor(nativeEventsReceiver: NativeEventsReceiver, completionCallbackWrapper: CompletionCallbackWrapper);
registerRemoteNotificationsRegistered(callback: (event: Registered) => void): EmitterSubscription;
registerNotificationReceived(callback: (notification: Notification, completion: (response: NotificationCompletion) => void) => void): EmitterSubscription;
registerRemoteNotificationOpened(callback: (response: NotificationResponse, completion: () => void) => void): EmitterSubscription;
registerRemoteNotificationsRegistrationFailed(callback: (event: RegistrationError) => void): EmitterSubscription;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class EventsRegistry {
constructor(nativeEventsReceiver, completionCallbackWrapper) {
this.nativeEventsReceiver = nativeEventsReceiver;
this.completionCallbackWrapper = completionCallbackWrapper;
}
registerRemoteNotificationsRegistered(callback) {
return this.nativeEventsReceiver.registerRemoteNotificationsRegistered(callback);
}
registerNotificationReceived(callback) {
return this.nativeEventsReceiver.registerRemoteNotificationReceived(this.completionCallbackWrapper.wrapReceivedCallback(callback));
}
registerRemoteNotificationOpened(callback) {
return this.nativeEventsReceiver.registerRemoteNotificationOpened(this.completionCallbackWrapper.wrapOpenedCallback(callback));
}
registerRemoteNotificationsRegistrationFailed(callback) {
return this.nativeEventsReceiver.registerRemoteNotificationsRegistrationFailed(callback);
}
}
exports.EventsRegistry = EventsRegistry;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const EventsRegistry_1 = require("./EventsRegistry");
const NativeEventsReceiver_mock_1 = require("../adapters/NativeEventsReceiver.mock");
const Notification_1 = require("../DTO/Notification");
const CompletionCallbackWrapper_1 = require("../adapters/CompletionCallbackWrapper");
const NativeCommandsSender_mock_1 = require("../adapters/NativeCommandsSender.mock");
const react_native_1 = require("react-native");
describe('EventsRegistry', () => {
let uut;
const mockNativeEventsReceiver = new NativeEventsReceiver_mock_1.NativeEventsReceiver();
const mockNativeCommandsSender = new NativeCommandsSender_mock_1.NativeCommandsSender();
const completionCallbackWrapper = new CompletionCallbackWrapper_1.CompletionCallbackWrapper(mockNativeCommandsSender);
beforeEach(() => {
uut = new EventsRegistry_1.EventsRegistry(mockNativeEventsReceiver, completionCallbackWrapper);
});
describe('registerRemoteNotificationsReceived', () => {
it('delegates to nativeEventsReceiver', () => {
const cb = jest.fn();
uut.registerNotificationReceived(cb);
expect(mockNativeEventsReceiver.registerRemoteNotificationReceived).toHaveBeenCalledTimes(1);
expect(mockNativeEventsReceiver.registerRemoteNotificationReceived).toHaveBeenCalledWith(expect.any(Function));
});
it('should wrap callback with completion block', () => {
const wrappedCallback = jest.fn();
const notification = new Notification_1.Notification({ identifier: 'identifier' });
uut.registerNotificationReceived(wrappedCallback);
const call = mockNativeEventsReceiver.registerRemoteNotificationReceived.mock.calls[0][0];
call(notification);
expect(wrappedCallback).toBeCalledWith(notification, expect.any(Function));
expect(wrappedCallback).toBeCalledTimes(1);
});
it('should wrap callback with completion block', () => {
const expectedNotification = new Notification_1.Notification({ identifier: 'identifier' });
uut.registerNotificationReceived((notification) => {
expect(notification).toEqual(expectedNotification);
});
const call = mockNativeEventsReceiver.registerRemoteNotificationReceived.mock.calls[0][0];
call(expectedNotification);
});
it('should invoke finishPresentingNotification', () => {
const notification = new Notification_1.Notification({ identifier: 'notificationId' });
const response = { alert: true };
uut.registerNotificationReceived((notification, completion) => {
completion(response);
expect(mockNativeCommandsSender.finishPresentingNotification).toBeCalledWith(notification.identifier, response);
});
const call = mockNativeEventsReceiver.registerRemoteNotificationReceived.mock.calls[0][0];
call(notification);
});
it('should not invoke finishPresentingNotification on Android', () => {
react_native_1.Platform.OS = 'android';
const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' });
const response = { alert: true };
uut.registerNotificationReceived((notification, completion) => {
completion(response);
expect(expectedNotification).toEqual(notification);
expect(mockNativeCommandsSender.finishPresentingNotification).toBeCalledTimes(0);
});
const call = mockNativeEventsReceiver.registerRemoteNotificationReceived.mock.calls[0][0];
call(expectedNotification);
});
});
describe('', () => {
it('delegates to nativeEventsReceiver', () => {
const cb = jest.fn();
uut.registerRemoteNotificationOpened(cb);
expect(mockNativeEventsReceiver.registerRemoteNotificationOpened).toHaveBeenCalledTimes(1);
expect(mockNativeEventsReceiver.registerRemoteNotificationOpened).toHaveBeenCalledWith(expect.any(Function));
});
it('should wrap callback with completion block', () => {
const wrappedCallback = jest.fn();
const notification = new Notification_1.Notification({ identifier: 'identifier' });
const response = { notification, identifier: 'responseId' };
uut.registerRemoteNotificationOpened(wrappedCallback);
const call = mockNativeEventsReceiver.registerRemoteNotificationOpened.mock.calls[0][0];
call(response);
expect(wrappedCallback).toBeCalledWith(response, expect.any(Function));
expect(wrappedCallback).toBeCalledTimes(1);
});
it('should wrap callback with completion block', () => {
const notification = new Notification_1.Notification({ identifier: 'identifier' });
const expectedResponse = { notification, identifier: 'responseId' };
uut.registerRemoteNotificationOpened((response) => {
expect(response).toEqual(expectedResponse);
});
const call = mockNativeEventsReceiver.registerRemoteNotificationOpened.mock.calls[0][0];
call(expectedResponse);
});
it('calling completion should invoke finishHandlingAction', () => {
const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' });
uut.registerRemoteNotificationOpened((notification, completion) => {
completion();
expect(expectedNotification).toEqual(notification);
expect(mockNativeCommandsSender.finishHandlingAction).toBeCalledWith(notification.identifier);
});
const call = mockNativeEventsReceiver.registerRemoteNotificationOpened.mock.calls[0][0];
call(expectedNotification);
});
it('should not invoke finishHandlingAction on Android', () => {
react_native_1.Platform.OS = 'android';
const expectedNotification = new Notification_1.Notification({ identifier: 'notificationId' });
uut.registerRemoteNotificationOpened((notification, completion) => {
completion();
expect(expectedNotification).toEqual(notification);
expect(mockNativeCommandsSender.finishHandlingAction).toBeCalledTimes(0);
});
const call = mockNativeEventsReceiver.registerRemoteNotificationOpened.mock.calls[0][0];
call(expectedNotification);
});
});
it('delegates registerRemoteNotificationsRegistered to nativeEventsReceiver', () => {
const cb = jest.fn();
uut.registerRemoteNotificationsRegistered(cb);
expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistered).toHaveBeenCalledTimes(1);
expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistered).toHaveBeenCalledWith(cb);
});
it('delegates registerRemoteNotificationsRegistrationFailed to nativeEventsReceiver', () => {
const cb = jest.fn();
uut.registerRemoteNotificationsRegistrationFailed(cb);
expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistrationFailed).toHaveBeenCalledTimes(1);
expect(mockNativeEventsReceiver.registerRemoteNotificationsRegistrationFailed).toHaveBeenCalledWith(cb);
});
});
import { EmitterSubscription } from 'react-native';
import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
import { RegisteredPushKit } from '../interfaces/NotificationEvents';
export declare class EventsRegistryIOS {
private nativeEventsReceiver;
constructor(nativeEventsReceiver: NativeEventsReceiver);
registerPushKitRegistered(callback: (event: RegisteredPushKit) => void): EmitterSubscription;
registerPushKitNotificationReceived(callback: (event: object) => void): EmitterSubscription;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class EventsRegistryIOS {
constructor(nativeEventsReceiver) {
this.nativeEventsReceiver = nativeEventsReceiver;
}
registerPushKitRegistered(callback) {
return this.nativeEventsReceiver.registerPushKitRegistered(callback);
}
registerPushKitNotificationReceived(callback) {
return this.nativeEventsReceiver.registerPushKitNotificationReceived(callback);
}
}
exports.EventsRegistryIOS = EventsRegistryIOS;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const EventsRegistryIOS_1 = require("./EventsRegistryIOS");
const NativeEventsReceiver_mock_1 = require("../adapters/NativeEventsReceiver.mock");
describe('EventsRegistryIOS', () => {
let uut;
const mockNativeEventsReceiver = new NativeEventsReceiver_mock_1.NativeEventsReceiver();
beforeEach(() => {
uut = new EventsRegistryIOS_1.EventsRegistryIOS(mockNativeEventsReceiver);
});
it('delegates registerPushKitRegistered to nativeEventsReceiver', () => {
const cb = jest.fn();
uut.registerPushKitRegistered(cb);
expect(mockNativeEventsReceiver.registerPushKitRegistered).toHaveBeenCalledTimes(1);
expect(mockNativeEventsReceiver.registerPushKitRegistered).toHaveBeenCalledWith(cb);
});
it('delegates registerPushKitNotificationReceived to nativeEventsReceiver', () => {
const cb = jest.fn();
uut.registerPushKitNotificationReceived(cb);
expect(mockNativeEventsReceiver.registerPushKitNotificationReceived).toHaveBeenCalledTimes(1);
expect(mockNativeEventsReceiver.registerPushKitNotificationReceived).toHaveBeenCalledWith(cb);
});
});
import { NotificationsRoot } from './Notifications';
export declare const Notifications: NotificationsRoot;
export * from './interfaces/EventSubscription';
export * from './DTO/Notification';
export * from './interfaces/NotificationEvents';
export * from './interfaces/NotificationCategory';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Notifications_1 = require("./Notifications");
const notificationsSingleton = new Notifications_1.NotificationsRoot();
exports.Notifications = notificationsSingleton;
tslib_1.__exportStar(require("./DTO/Notification"), exports);
tslib_1.__exportStar(require("./interfaces/NotificationCategory"), exports);
export interface EventSubscription {
remove(): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export declare class NotificationActionResponse {
identifier: string;
text?: string;
constructor(response: any);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class NotificationActionResponse {
constructor(response) {
this.identifier = response.identifier;
this.text = response.text;
}
}
exports.NotificationActionResponse = NotificationActionResponse;
export declare class NotificationCategory {
identifier: string;
actions: [NotificationAction?];
constructor(identifier: string, actions: [NotificationAction?]);
}
export interface NotificationTextInput {
buttonTitle: string;
placeholder: string;
}
export declare class NotificationAction {
identifier: string;
activationMode: 'foreground' | 'authenticationRequired' | 'destructive';
title: string;
authenticationRequired: boolean;
textInput: NotificationTextInput;
constructor(identifier: string, activationMode: 'foreground' | 'authenticationRequired' | 'destructive', title: string, authenticationRequired: boolean, textInput: NotificationTextInput);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class NotificationCategory {
constructor(identifier, actions) {
this.identifier = identifier;
this.actions = actions;
}
}
exports.NotificationCategory = NotificationCategory;
class NotificationAction {
constructor(identifier, activationMode, title, authenticationRequired, textInput) {
this.identifier = identifier;
this.activationMode = activationMode;
this.title = title;
this.authenticationRequired = authenticationRequired;
this.textInput = textInput;
}
}
exports.NotificationAction = NotificationAction;
export interface NotificationCompletion {
badge?: boolean;
alert?: boolean;
sound?: boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
import { Notification } from '../DTO/Notification';
import { NotificationActionResponse } from './NotificationActionResponse';
export interface Registered {
deviceToken: string;
}
export interface RegistrationError {
code: string;
domain: string;
localizedDescription: string;
}
export interface RegisteredPushKit {
pushKitToken: string;
}
export interface NotificationResponse {
identifier: string;
notification: Notification;
action?: NotificationActionResponse;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export interface NotificationPermissions {
badge: boolean;
alert: boolean;
sound: boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
......@@ -140,4 +140,4 @@
"html"
]
}
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment