Commit 97803877 authored by yogevbd's avatar yogevbd

Fix e2e

parent c4fa09da
...@@ -9,7 +9,7 @@ describe('Notifications', () => { ...@@ -9,7 +9,7 @@ describe('Notifications', () => {
describe('Foreground', () => { describe('Foreground', () => {
it('Should receive notification', async () => { it('Should receive notification', async () => {
await device.sendUserNotification(createNotification({link: 'foreground/notification'})); await device.sendUserNotification(createNotification({link: 'foreground/notification'}));
await expect(elementByLabel('foreground/notification')).toBeVisible(); await linkShouldBeVisible('foreground/notification');
}); });
it('Should open notification', async () => { it('Should open notification', async () => {
...@@ -28,13 +28,19 @@ describe('Notifications', () => { ...@@ -28,13 +28,19 @@ describe('Notifications', () => {
}); });
describe('Dead state', () => { 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 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}) { function createNotification({link, showAlert}) {
return { return {
trigger: { trigger: {
......
...@@ -12,7 +12,8 @@ class NotificationsExampleApp extends Component { ...@@ -12,7 +12,8 @@ class NotificationsExampleApp extends Component {
constructor() { constructor() {
super(); super();
this.state = { this.state = {
notifications: [] notifications: [],
openedNotifications: [],
}; };
this.registerNotificationEvents(); this.registerNotificationEvents();
...@@ -25,28 +26,18 @@ class NotificationsExampleApp extends Component { ...@@ -25,28 +26,18 @@ class NotificationsExampleApp extends Component {
notifications: [...this.state.notifications, notification] 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) => { Notifications.events().registerRemoteNotificationOpened((notification, completion) => {
this.setState({ this.setState({
notifications: [...this.state.notifications, notification] openedNotifications: [...this.state.openedNotifications, notification]
}); });
completion(); completion();
}); });
} }
renderNotification(notification) {
return (
<View style={{backgroundColor: 'lightgray', margin: 10}}>
<Text>{`Title: ${notification.title}`}</Text>
<Text>{`Body: ${notification.body}`}</Text>
<Text>{`Extra Link Param: ${notification.data.link}`}</Text>
</View>
);
}
requestPermissions() { requestPermissions() {
Notifications.ios.requestPermissions(); Notifications.ios.requestPermissions();
} }
...@@ -98,6 +89,26 @@ class NotificationsExampleApp extends Component { ...@@ -98,6 +89,26 @@ class NotificationsExampleApp extends Component {
} }
} }
renderNotification(notification) {
return (
<View style={{backgroundColor: 'lightgray', margin: 10}}>
<Text>{`Title: ${notification.title}`}</Text>
<Text>{`Body: ${notification.body}`}</Text>
<Text>{`Extra Link Param: ${notification.data.link}`}</Text>
</View>
);
}
renderOpenedNotification(notification) {
return (
<View style={{backgroundColor: 'lightgray', margin: 10}}>
<Text>{`Title: ${notification.title}`}</Text>
<Text>{`Body: ${notification.body}`}</Text>
<Text>{`Notification Clicked: ${notification.data.link}`}</Text>
</View>
);
}
render() { render() {
const notifications = this.state.notifications.map((notification, idx) => const notifications = this.state.notifications.map((notification, idx) =>
( (
...@@ -105,13 +116,19 @@ class NotificationsExampleApp extends Component { ...@@ -105,13 +116,19 @@ class NotificationsExampleApp extends Component {
{this.renderNotification(notification)} {this.renderNotification(notification)}
</View> </View>
)); ));
const openedNotifications = this.state.openedNotifications.map((notification, idx) =>
(
<View key={`notification_${idx}`}>
{this.renderOpenedNotification(notification)}
</View>
));
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Button title={'Request permissions'} onPress={this.requestPermissions} testID={'requestPermissions'} /> <Button title={'Request permissions'} onPress={this.requestPermissions} testID={'requestPermissions'} />
<Button title={'Send local notification'} onPress={this.sendLocalNotification} testID={'sendLocalNotification'} /> <Button title={'Send local notification'} onPress={this.sendLocalNotification} testID={'sendLocalNotification'} />
<Button title={'Remove all delivered notifications'} onPress={this.removeAllDeliveredNotifications} /> <Button title={'Remove all delivered notifications'} onPress={this.removeAllDeliveredNotifications} />
{notifications} {notifications}
{openedNotifications}
</View> </View>
); );
} }
......
...@@ -5,7 +5,7 @@ import { NotificationPermissions } from '../interfaces/NotificationPermissions'; ...@@ -5,7 +5,7 @@ import { NotificationPermissions } from '../interfaces/NotificationPermissions';
import { NotificationCategory } from '../interfaces/NotificationCategory'; import { NotificationCategory } from '../interfaces/NotificationCategory';
interface NativeCommandsModule { interface NativeCommandsModule {
getInitialNotification(): Promise<Notification>; getInitialNotification(): Promise<Object>;
postLocalNotification(notification: Notification, id: number): void; postLocalNotification(notification: Notification, id: number): void;
requestPermissions(): void; requestPermissions(): void;
abandonPermissions(): void; abandonPermissions(): void;
...@@ -35,7 +35,7 @@ export class NativeCommandsSender { ...@@ -35,7 +35,7 @@ export class NativeCommandsSender {
return this.nativeCommandsModule.postLocalNotification(notification, id); return this.nativeCommandsModule.postLocalNotification(notification, id);
} }
getInitialNotification(): Promise<Notification> { getInitialNotification(): Promise<Object> {
return this.nativeCommandsModule.getInitialNotification(); return this.nativeCommandsModule.getInitialNotification();
} }
......
...@@ -32,7 +32,7 @@ describe('Commands', () => { ...@@ -32,7 +32,7 @@ describe('Commands', () => {
it('returns a promise with the initial notification', async () => { it('returns a promise with the initial notification', async () => {
const expectedNotification: Notification = new Notification({identifier: 'id'}); const expectedNotification: Notification = new Notification({identifier: 'id'});
when(mockedNativeCommandsSender.getInitialNotification()).thenResolve( when(mockedNativeCommandsSender.getInitialNotification()).thenResolve(
expectedNotification {identifier: 'id'}
); );
const result = await uut.getInitialNotification(); const result = await uut.getInitialNotification();
expect(result).toEqual(expectedNotification); expect(result).toEqual(expectedNotification);
......
...@@ -17,11 +17,12 @@ export class Commands { ...@@ -17,11 +17,12 @@ export class Commands {
return result; return result;
} }
public getInitialNotification(): Promise<Notification> { public async getInitialNotification(): Promise<Notification> {
const result = this.nativeCommandsSender.getInitialNotification(); return this.nativeCommandsSender.getInitialNotification().then((payload) => {
return result; return new Notification(payload);
});
} }
public requestPermissions() { public requestPermissions() {
const result = this.nativeCommandsSender.requestPermissions(); const result = this.nativeCommandsSender.requestPermissions();
return result; return result;
......
...@@ -37,9 +37,6 @@ ...@@ -37,9 +37,6 @@
"androidStudio": "open -a /Applications/Android\\ Studio.app ./example/android" "androidStudio": "open -a /Applications/Android\\ Studio.app ./example/android"
}, },
"nativePackage": true, "nativePackage": true,
"dependencies": {
"uuid": "^2.0.3"
},
"peerDependencies": { "peerDependencies": {
"react": ">=0.14.5", "react": ">=0.14.5",
"react-native": ">=0.25.1" "react-native": ">=0.25.1"
......
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