Skip to content

Commit e48dd02

Browse files
committed
Add tests coverage
1 parent 3d62e3e commit e48dd02

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { NotificationAndroid } from "./NotificationAndroid";
2+
3+
describe('Notification', () => {
4+
it('Should create notification with payload', () => {
5+
const payload = { p: 'p' };
6+
const notification = new NotificationAndroid(payload);
7+
expect(notification.payload).toEqual(payload);
8+
});
9+
10+
it('Should return title from payload', () => {
11+
const payload = { title: 'title', body: 'body' };
12+
const notification = new NotificationAndroid(payload);
13+
expect(notification.title).toEqual('title');
14+
});
15+
16+
it('Should return body from payload', () => {
17+
const payload = { title: 'title', body: 'body' };
18+
const notification = new NotificationAndroid(payload);
19+
expect(notification.body).toEqual('body');
20+
});
21+
22+
it('Should return sound from payload', () => {
23+
const payload = { title: 'title', sound: 'sound.wav' };
24+
const notification = new NotificationAndroid(payload);
25+
expect(notification.sound).toEqual('sound.wav');
26+
});
27+
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { NotificationIOS } from "./NotificationIOS";
2+
3+
describe('Notification', () => {
4+
it('Should create notification with payload', () => {
5+
const payload = { p: 'p' };
6+
const notification = new NotificationIOS(payload);
7+
expect(notification.payload).toEqual(payload);
8+
});
9+
10+
it('Should create notification with valid aps', () => {
11+
const aps = { alert: {} };
12+
const payload = { aps };
13+
const notification = new NotificationIOS(payload);
14+
expect(notification.aps).toEqual(aps);
15+
});
16+
17+
it('Should create notification with empy aps', () => {
18+
const payload = { aps: undefined };
19+
const notification = new NotificationIOS(payload);
20+
expect(notification.aps).toEqual({});
21+
});
22+
23+
it('Should return alert object', () => {
24+
const payload = { aps: { alert: { title: 'title' } } };
25+
const notification = new NotificationIOS(payload);
26+
expect(notification.alert).toEqual(payload.aps.alert);
27+
});
28+
29+
it('Should return alert object when alert is string', () => {
30+
const payload = { aps: { alert: 'title' } };
31+
const notification = new NotificationIOS(payload);
32+
expect(notification.alert).toEqual({
33+
body: 'title'
34+
});
35+
});
36+
37+
it('Should return title from alert', () => {
38+
const payload = { aps: { alert: { title: 'title' } } };
39+
const notification = new NotificationIOS(payload);
40+
expect(notification.title).toEqual('title');
41+
});
42+
43+
it('Should return body from alert', () => {
44+
const payload = { aps: { alert: { title: 'title', body: 'body' } } };
45+
const notification = new NotificationIOS(payload);
46+
expect(notification.body).toEqual('body');
47+
});
48+
49+
it('Should return badge from aps', () => {
50+
const payload = { aps: { badge: 0 } };
51+
const notification = new NotificationIOS(payload);
52+
expect(notification.badge).toEqual(0);
53+
});
54+
55+
it('Should return sound from aps', () => {
56+
const payload = { aps: { sound: 'sound.wav' } };
57+
const notification = new NotificationIOS(payload);
58+
expect(notification.sound).toEqual('sound.wav');
59+
});
60+
61+
it('Should return thread from aps', () => {
62+
const payload = { aps: { thread: 'thread' } };
63+
const notification = new NotificationIOS(payload);
64+
expect(notification.thread).toEqual('thread');
65+
});
66+
});

lib/src/commands/Commands.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Commands', () => {
3636
verify(mockedNativeCommandsSender.getInitialNotification()).called();
3737
});
3838

39-
it('android - returns a promise with the initial notification', async () => {
39+
it('Android - returns a promise with the initial notification', async () => {
4040
Platform.OS = 'android';
4141
const expectedNotification: Notification = new NotificationAndroid({'google.message_id': 'id'});
4242
when(mockedNativeCommandsSender.getInitialNotification()).thenResolve(
@@ -46,6 +46,13 @@ describe('Commands', () => {
4646
expect(result).toEqual(expectedNotification);
4747
});
4848

49+
it('Should return undefined initial notification', async () => {
50+
Platform.OS = 'android';
51+
when(mockedNativeCommandsSender.getInitialNotification()).thenResolve();
52+
const result = await uut.getInitialNotification();
53+
expect(result).toEqual(undefined);
54+
});
55+
4956
it('iOS - returns a promise with the initial notification', async () => {
5057
Platform.OS = 'ios';
5158
const expectedNotification: Notification = new NotificationIOS({identifier: 'id'});

lib/src/events/EventsRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EmitterSubscription, AppState } from 'react-native';
1+
import { EmitterSubscription } from 'react-native';
22
import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
33
import {
44
Registered,

0 commit comments

Comments
 (0)