diff --git a/e2e/Notifications.test.js b/e2e/Notifications.test.js index d6ede1100e04d84eff2674f7388cc1dd4f099751..cc954c11c0bfe9e35275254ed6c56b46c9d95047 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 8ab1e4161a407202967ae2aedd0a8d6426300ece..4dbd7d0dc08bac3895745abdfe56546430ed14b6 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 (