Commit cbfbeb77 authored by yogevbd's avatar yogevbd

Fix lint

parent 942d62fa
import {NativeModules, DeviceEventEmitter} from "react-native";
import NotificationAndroid from "./notification";
import {NativeModules, DeviceEventEmitter} from 'react-native';
import NotificationAndroid from './notification';
const RNNotifications = NativeModules.WixRNNotifications;
......@@ -10,7 +10,7 @@ let registrationTokenUpdateListener;
export class NotificationsAndroid {
static setNotificationOpenedListener(listener) {
notificationOpenedListener = DeviceEventEmitter.addListener("notificationOpened", (notification) => listener(new NotificationAndroid(notification)));
notificationOpenedListener = DeviceEventEmitter.addListener('notificationOpened', (notification) => listener(new NotificationAndroid(notification)));
}
static clearNotificationOpenedListener() {
......@@ -21,11 +21,11 @@ export class NotificationsAndroid {
}
static setNotificationReceivedListener(listener) {
notificationReceivedListener = DeviceEventEmitter.addListener("notificationReceived", (notification) => listener(new NotificationAndroid(notification)));
notificationReceivedListener = DeviceEventEmitter.addListener('notificationReceived', (notification) => listener(new NotificationAndroid(notification)));
}
static setNotificationReceivedInForegroundListener(listener) {
notificationReceivedInForegroundListener = DeviceEventEmitter.addListener("notificationReceivedInForeground", (notification) => listener(new NotificationAndroid(notification)));
notificationReceivedInForegroundListener = DeviceEventEmitter.addListener('notificationReceivedInForeground', (notification) => listener(new NotificationAndroid(notification)));
}
static clearNotificationReceivedListener() {
......@@ -43,7 +43,7 @@ export class NotificationsAndroid {
}
static setRegistrationTokenUpdateListener(listener) {
registrationTokenUpdateListener = DeviceEventEmitter.addListener("remoteNotificationsRegistered", listener);
registrationTokenUpdateListener = DeviceEventEmitter.addListener('remoteNotificationsRegistered', listener);
}
static clearRegistrationTokenUpdateListener() {
......
/**
* @flow
*/
"use strict";
import { NativeModules, DeviceEventEmitter, NativeAppEventEmitter } from "react-native";
import Map from "core-js/library/es6/map";
import uuid from "uuid";
'use strict';
import { NativeModules, DeviceEventEmitter, NativeAppEventEmitter } from 'react-native';
import Map from 'core-js/library/es6/map';
import uuid from 'uuid';
const NativeRNNotifications = NativeModules.RNBridgeModule; // eslint-disable-line no-unused-vars
import IOSNotification from "./notification.ios";
import IOSNotification from './notification.ios';
export const DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT = "remoteNotificationsRegistered";
export const DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT = "remoteNotificationsRegistrationFailed";
export const DEVICE_PUSH_KIT_REGISTERED_EVENT = "pushKitRegistered";
export const DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT = "notificationReceivedForeground";
export const DEVICE_NOTIFICATION_RECEIVED_BACKGROUND_EVENT = "notificationReceivedBackground";
export const DEVICE_NOTIFICATION_OPENED_EVENT = "notificationOpened";
export const DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT = 'remoteNotificationsRegistered';
export const DEVICE_REMOTE_NOTIFICATIONS_REGISTRATION_FAILED_EVENT = 'remoteNotificationsRegistrationFailed';
export const DEVICE_PUSH_KIT_REGISTERED_EVENT = 'pushKitRegistered';
export const DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT = 'notificationReceivedForeground';
export const DEVICE_NOTIFICATION_RECEIVED_BACKGROUND_EVENT = 'notificationReceivedBackground';
export const DEVICE_NOTIFICATION_OPENED_EVENT = 'notificationOpened';
const DEVICE_NOTIFICATION_ACTION_RECEIVED = "notificationActionReceived";
const DEVICE_NOTIFICATION_ACTION_RECEIVED = 'notificationActionReceived';
const _exportedEvents = [
DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT,
......@@ -200,7 +200,7 @@ export default class NotificationsIOS {
*
* - `alertBody` : The message displayed in the notification alert.
* - `alertTitle` : The message title displayed in the notification.
* - `alertAction` : The "action" displayed beneath an actionable notification. Defaults to "view";
* - `alertAction` : The 'action' displayed beneath an actionable notification. Defaults to 'view';
* - `soundName` : The sound played when the notification is fired (optional).
* - `silent` : If true, the notification sound will be suppressed (optional).
* - `category` : The category of this notification, required for actionable notifications (optional).
......
......@@ -11,8 +11,8 @@ export default class IOSNotification {
this._data = {};
if (notification.aps &&
notification.aps["content-available"] &&
notification.aps["content-available"] === 1 &&
notification.aps['content-available'] &&
notification.aps['content-available'] === 1 &&
!notification.aps.alert &&
!notification.aps.sound &&
notification.managedAps) {
......@@ -21,8 +21,8 @@ export default class IOSNotification {
this._sound = notification.managedAps.sound;
this._badge = notification.aps.badge;
this._category = notification.managedAps.category;
this._type = "managed";
this._thread = notification.aps["thread-id"];
this._type = 'managed';
this._thread = notification.aps['thread-id'];
} else if (
notification.aps &&
notification.aps.alert) {
......@@ -31,11 +31,11 @@ export default class IOSNotification {
this._sound = notification.aps.sound;
this._badge = notification.aps.badge;
this._category = notification.aps.category;
this._type = "regular";
this._thread = notification.aps["thread-id"];
this._type = 'regular';
this._thread = notification.aps['thread-id'];
}
Object.keys(notification).filter(key => key !== "aps").forEach(key => {
Object.keys(notification).filter(key => key !== 'aps').forEach(key => {
this._data[key] = notification[key];
});
}
......
This diff is collapsed.
"use strict";
let expect = require("chai").use(require("sinon-chai")).expect;
import proxyquire from "proxyquire";
import sinon from "sinon";
'use strict';
let expect = require('chai').use(require('sinon-chai')).expect;
import proxyquire from 'proxyquire';
import sinon from 'sinon';
describe("Notifications-Android > ", () => {
describe('Notifications-Android > ', () => {
proxyquire.noCallThru();
let refreshTokenStub;
......@@ -19,8 +19,8 @@ describe("Notifications-Android > ", () => {
cancelLocalNotificationStub = sinon.stub();
deviceEventEmitterListenerStub = sinon.stub();
libUnderTest = proxyquire("../index.android", {
"react-native": {
libUnderTest = proxyquire('../index.android', {
'react-native': {
NativeModules: {
WixRNNotifications: {
refreshToken: refreshTokenStub,
......@@ -33,22 +33,22 @@ describe("Notifications-Android > ", () => {
addListener: deviceEventEmitterListenerStub
}
},
"./notification": require("../notification.android")
'./notification': require('../notification.android')
});
});
describe("Registration token API", () => {
it("should assign callback to native event upon listener registration", () => {
describe('Registration token API', () => {
it('should assign callback to native event upon listener registration', () => {
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
const userListener = () => {};
libUnderTest.NotificationsAndroid.setRegistrationTokenUpdateListener(userListener);
expect(deviceEventEmitterListenerStub).to.have.been.calledWith("remoteNotificationsRegistered", userListener);
expect(deviceEventEmitterListenerStub).to.have.been.calledWith('remoteNotificationsRegistered', userListener);
expect(deviceEventEmitterListenerStub).to.have.been.calledOnce;
});
it("should clear native event listener upon listener deregister", () => {
it('should clear native event listener upon listener deregister', () => {
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
const userListener = () => {};
const nativeListener = {
......@@ -62,28 +62,28 @@ describe("Notifications-Android > ", () => {
expect(nativeListener.remove).to.have.been.calledOnce;
});
it("shouldn't fail if deregister without registering", () => {
it('shouldn`t fail if deregister without registering', () => {
libUnderTest.NotificationsAndroid.clearRegistrationTokenUpdateListener();
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
});
});
describe("notification-opening API", () => {
it("should assign callback to native event upon registration", () => {
describe('notification-opening API', () => {
it('should assign callback to native event upon registration', () => {
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
const userListenerStub = sinon.stub();
libUnderTest.NotificationsAndroid.setNotificationOpenedListener(userListenerStub);
expect(deviceEventEmitterListenerStub).to.have.been.calledOnce;
expect(deviceEventEmitterListenerStub).to.have.been.calledWith("notificationOpened", sinon.match.func);
expect(deviceEventEmitterListenerStub).to.have.been.calledWith('notificationOpened', sinon.match.func);
});
it("should assign a wrapper-callback upon registration", () => {
it('should assign a wrapper-callback upon registration', () => {
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
const userListenerStub = sinon.stub();
const notification = { foo: "bar" };
const notification = { foo: 'bar' };
libUnderTest.NotificationsAndroid.setNotificationOpenedListener(userListenerStub);
......@@ -93,7 +93,7 @@ describe("Notifications-Android > ", () => {
expect(userListenerStub.args[0][0].getData()).to.equal(notification);
});
it("should clear native event listener upon listener deregister", () => {
it('should clear native event listener upon listener deregister', () => {
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
const userListener = () => {};
const nativeListener = {
......@@ -107,28 +107,28 @@ describe("Notifications-Android > ", () => {
expect(nativeListener.remove).to.have.been.calledOnce;
});
it("shouldn't fail if deregister without registering", () => {
it('shouldnt fail if deregister without registering', () => {
libUnderTest.NotificationsAndroid.clearNotificationOpenedListener();
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
});
});
describe("notification-receive API", () => {
it("should assign callback to native event upon registration", () => {
describe('notification-receive API', () => {
it('should assign callback to native event upon registration', () => {
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
const userListenerStub = sinon.stub();
libUnderTest.NotificationsAndroid.setNotificationReceivedListener(userListenerStub);
expect(deviceEventEmitterListenerStub).to.have.been.calledOnce;
expect(deviceEventEmitterListenerStub).to.have.been.calledWith("notificationReceived", sinon.match.func);
expect(deviceEventEmitterListenerStub).to.have.been.calledWith('notificationReceived', sinon.match.func);
});
it("should assign a wrapper-callback upon registration", () => {
it('should assign a wrapper-callback upon registration', () => {
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
const userListenerStub = sinon.stub();
const notification = { foo: "bar" };
const notification = { foo: 'bar' };
libUnderTest.NotificationsAndroid.setNotificationReceivedListener(userListenerStub);
......@@ -138,7 +138,7 @@ describe("Notifications-Android > ", () => {
expect(userListenerStub.args[0][0].getData()).to.equal(notification);
});
it("should clear native event listener upon listener deregister", () => {
it('should clear native event listener upon listener deregister', () => {
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
const userListener = () => {};
const nativeListener = {
......@@ -152,25 +152,25 @@ describe("Notifications-Android > ", () => {
expect(nativeListener.remove).to.have.been.calledOnce;
});
it("shouldn't fail if deregister without registering", () => {
it('shouldn`t fail if deregister without registering', () => {
libUnderTest.NotificationsAndroid.clearNotificationReceivedListener();
expect(deviceEventEmitterListenerStub).to.not.have.been.called;
});
});
describe("Notification token", () => {
it("should refresh notification token upon refreshing request by the user", () => {
describe('Notification token', () => {
it('should refresh notification token upon refreshing request by the user', () => {
expect(refreshTokenStub).to.not.have.been.called;
libUnderTest.NotificationsAndroid.refreshToken();
expect(refreshTokenStub).to.have.been.calledOnce;
});
});
describe("Initial notification API", () => {
it("should return initial notification data if available", (done) => {
describe('Initial notification API', () => {
it('should return initial notification data if available', (done) => {
expect(getInitialNotificationStub).to.not.have.been.called;
const rawNotification = {foo: "bar"};
const rawNotification = {foo: 'bar'};
getInitialNotificationStub.returns(Promise.resolve(rawNotification));
libUnderTest.PendingNotifications.getInitialNotification()
......@@ -181,7 +181,7 @@ describe("Notifications-Android > ", () => {
.catch((err) => done(err));
});
it("should return empty notification if not available", (done) => {
it('should return empty notification if not available', (done) => {
expect(getInitialNotificationStub).to.not.have.been.called;
getInitialNotificationStub.returns(Promise.resolve(null));
......@@ -195,13 +195,13 @@ describe("Notifications-Android > ", () => {
});
describe("Local notification", () => {
describe('Local notification', () => {
const notification = {
title: "notification-title",
body: "notification-body"
title: 'notification-title',
body: 'notification-body'
};
it("should get published when posted manually", () => {
it('should get published when posted manually', () => {
expect(postLocalNotificationStub).to.not.have.been.called;
const id = libUnderTest.NotificationsAndroid.localNotification(notification);
......@@ -209,7 +209,7 @@ describe("Notifications-Android > ", () => {
expect(postLocalNotificationStub).to.have.been.calledWith(notification, id);
});
it("should be called with a unique ID", () => {
it('should be called with a unique ID', () => {
expect(postLocalNotificationStub).to.not.have.been.called;
const id = libUnderTest.NotificationsAndroid.localNotification(notification);
......@@ -219,7 +219,7 @@ describe("Notifications-Android > ", () => {
expect(id).to.not.equal(id2);
});
it("should be cancellable with an ID", () => {
it('should be cancellable with an ID', () => {
expect(cancelLocalNotificationStub).to.not.have.been.called;
libUnderTest.NotificationsAndroid.cancelLocalNotification(666);
......@@ -227,5 +227,4 @@ describe("Notifications-Android > ", () => {
expect(cancelLocalNotificationStub).to.have.been.calledWith(666);
});
});
});
This diff is collapsed.
"use strict";
import { expect } from "chai";
import IOSNotification from "../notification.ios";
'use strict';
import { expect } from 'chai';
import IOSNotification from '../notification.ios';
describe("iOS Notification Object", () => {
describe('iOS Notification Object', () => {
let notification;
let someBadgeCount = 123, someSound = "someSound", someCategory = "some_notification_category", someThread = "thread-1";
let someBadgeCount = 123, someSound = 'someSound', someCategory = 'some_notification_category', someThread = 'thread-1';
describe("for a regular iOS push notification", () => {
describe('for a regular iOS push notification', () => {
let regularNativeNotifications = [
// basic example, without content-available = 1 (aka silent notification)
{
aps: {
alert: {
title: "some title",
body: "some body"
title: 'some title',
body: 'some body'
},
badge: someBadgeCount,
sound: someSound,
category: someCategory,
"thread-id": someThread
'thread-id': someThread
},
key1: "value1",
key2: "value2"
key1: 'value1',
key2: 'value2'
},
// another example, with content-available but also with alert object (should not be a silent notification)
{
aps: {
"content-available": 1,
'content-available': 1,
alert: {
title: "some title",
body: "some body"
title: 'some title',
body: 'some body'
},
badge: someBadgeCount,
sound: someSound,
category: someCategory,
"thread-id": someThread
'thread-id': someThread
},
key1: "value1",
key2: "value2"
key1: 'value1',
key2: 'value2'
}
];
......@@ -47,82 +47,82 @@ describe("iOS Notification Object", () => {
notification = new IOSNotification(nativeNotification);
});
it("should return 'regular' type", function () {
expect(notification.getType()).to.equal("regular");
it('should return regular type', function () {
expect(notification.getType()).to.equal('regular');
});
it("should return the alert object", () => {
it('should return the alert object', () => {
expect(notification.getMessage()).to.deep.equal(nativeNotification.aps.alert);
});
it("should return the sound", () => {
it('should return the sound', () => {
expect(notification.getSound()).to.equal(someSound);
});
it("should return the badge count", () => {
it('should return the badge count', () => {
expect(notification.getBadgeCount()).to.equal(someBadgeCount);
});
it("should return the category", () => {
it('should return the category', () => {
expect(notification.getCategory()).to.equal(someCategory);
});
it("should return the thread", () => {
expect(notification.getThread()).to.equal("thread-1");
it('should return the thread', () => {
expect(notification.getThread()).to.equal('thread-1');
});
it("should return the custom data", () => {
expect(notification.getData()).to.deep.equal({ key1: "value1", key2: "value2" });
it('should return the custom data', () => {
expect(notification.getData()).to.deep.equal({ key1: 'value1', key2: 'value2' });
});
});
});
describe("for a managed iOS push notification (silent notification, with managedAps key and content-available = 1)", () => {
describe('for a managed iOS push notification (silent notification, with managedAps key and content-available = 1)', () => {
let managedNativeNotification = {
aps: {
"content-available": 1,
'content-available': 1,
badge: someBadgeCount
},
managedAps: {
action: "CREATE",
notificationId: "1",
action: 'CREATE',
notificationId: '1',
alert: {
title: "some title",
body: "some body"
title: 'some title',
body: 'some body'
},
sound: someSound,
category: someCategory
},
key1: "value1",
key2: "value2"
key1: 'value1',
key2: 'value2'
};
beforeEach(() => {
notification = new IOSNotification(managedNativeNotification);
});
it("should return 'managed' type", function () {
expect(notification.getType()).to.equal("managed");
it('should return managed type', function () {
expect(notification.getType()).to.equal('managed');
});
it("should return the alert object", () => {
it('should return the alert object', () => {
expect(notification.getMessage()).to.equal(managedNativeNotification.managedAps.alert);
});
it("should return the sound", () => {
it('should return the sound', () => {
expect(notification.getSound()).to.equal(someSound);
});
it("should return the badge count", () => {
it('should return the badge count', () => {
expect(notification.getBadgeCount()).to.equal(someBadgeCount);
});
it("should return the category", () => {
it('should return the category', () => {
expect(notification.getCategory()).to.equal(someCategory);
});
it("should return the custom data", () => {
expect(notification.getData()).to.deep.equal({ managedAps: managedNativeNotification.managedAps, key1: "value1", key2: "value2" });
it('should return the custom data', () => {
expect(notification.getData()).to.deep.equal({ managedAps: managedNativeNotification.managedAps, key1: 'value1', key2: 'value2' });
});
});
});
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