From 978038775ce7751655214fa41db4c981b728dcde Mon Sep 17 00:00:00 2001 From: yogevbd Date: Thu, 12 Sep 2019 11:01:17 +0300 Subject: [PATCH] Fix e2e --- e2e/Notifications.test.js | 12 +++++-- example/index.js | 45 ++++++++++++++++-------- lib/src/adapters/NativeCommandsSender.ts | 4 +-- lib/src/commands/Commands.test.ts | 2 +- lib/src/commands/Commands.ts | 9 ++--- package.json | 3 -- 6 files changed, 48 insertions(+), 27 deletions(-) diff --git a/e2e/Notifications.test.js b/e2e/Notifications.test.js index d6ede11..cc954c1 100644 --- a/e2e/Notifications.test.js +++ b/e2e/Notifications.test.js @@ -9,7 +9,7 @@ describe('Notifications', () => { describe('Foreground', () => { it('Should receive notification', async () => { await device.sendUserNotification(createNotification({link: 'foreground/notification'})); - await expect(elementByLabel('foreground/notification')).toBeVisible(); + await linkShouldBeVisible('foreground/notification'); }); it('Should open notification', async () => { @@ -28,13 +28,19 @@ describe('Notifications', () => { }); describe('Dead state', () => { - it('Should receive notification', async () => { + it.only('Should receive notification', async () => { await device.launchApp({newInstance: true, userNotification: createNotification({link: 'deadState/notification'})}); - await expect(elementByLabel('deadState/notification')).toBeVisible(); + await linkShouldBeVisible('deadState/notification'); }); }); + + + async function linkShouldBeVisible(link) { + return await expect(elementByLabel(`Extra Link Param: ${link}`)).toBeVisible(); + } }); + function createNotification({link, showAlert}) { return { trigger: { diff --git a/example/index.js b/example/index.js index 8ab1e41..4dbd7d0 100644 --- a/example/index.js +++ b/example/index.js @@ -12,7 +12,8 @@ class NotificationsExampleApp extends Component { constructor() { super(); this.state = { - notifications: [] + notifications: [], + openedNotifications: [], }; this.registerNotificationEvents(); @@ -25,28 +26,18 @@ class NotificationsExampleApp extends Component { notifications: [...this.state.notifications, notification] }); - completion({alert: true, sound: false, badge: false}); + completion({alert: notification.data.showAlert, sound: false, badge: false}); }); Notifications.events().registerRemoteNotificationOpened((notification, completion) => { this.setState({ - notifications: [...this.state.notifications, notification] + openedNotifications: [...this.state.openedNotifications, notification] }); completion(); }); } - renderNotification(notification) { - return ( - - {`Title: ${notification.title}`} - {`Body: ${notification.body}`} - {`Extra Link Param: ${notification.data.link}`} - - ); - } - requestPermissions() { Notifications.ios.requestPermissions(); } @@ -98,6 +89,26 @@ class NotificationsExampleApp extends Component { } } + renderNotification(notification) { + return ( + + {`Title: ${notification.title}`} + {`Body: ${notification.body}`} + {`Extra Link Param: ${notification.data.link}`} + + ); + } + + renderOpenedNotification(notification) { + return ( + + {`Title: ${notification.title}`} + {`Body: ${notification.body}`} + {`Notification Clicked: ${notification.data.link}`} + + ); + } + render() { const notifications = this.state.notifications.map((notification, idx) => ( @@ -105,13 +116,19 @@ class NotificationsExampleApp extends Component { {this.renderNotification(notification)} )); - + const openedNotifications = this.state.openedNotifications.map((notification, idx) => + ( + + {this.renderOpenedNotification(notification)} + + )); return (