Commit 97803877 authored by yogevbd's avatar yogevbd

Fix e2e

parent c4fa09da
......@@ -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: {
......
......@@ -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 (
<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() {
Notifications.ios.requestPermissions();
}
......@@ -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() {
const notifications = this.state.notifications.map((notification, idx) =>
(
......@@ -105,13 +116,19 @@ class NotificationsExampleApp extends Component {
{this.renderNotification(notification)}
</View>
));
const openedNotifications = this.state.openedNotifications.map((notification, idx) =>
(
<View key={`notification_${idx}`}>
{this.renderOpenedNotification(notification)}
</View>
));
return (
<View style={styles.container}>
<Button title={'Request permissions'} onPress={this.requestPermissions} testID={'requestPermissions'} />
<Button title={'Send local notification'} onPress={this.sendLocalNotification} testID={'sendLocalNotification'} />
<Button title={'Remove all delivered notifications'} onPress={this.removeAllDeliveredNotifications} />
{notifications}
{openedNotifications}
</View>
);
}
......
......@@ -5,7 +5,7 @@ import { NotificationPermissions } from '../interfaces/NotificationPermissions';
import { NotificationCategory } from '../interfaces/NotificationCategory';
interface NativeCommandsModule {
getInitialNotification(): Promise<Notification>;
getInitialNotification(): Promise<Object>;
postLocalNotification(notification: Notification, id: number): void;
requestPermissions(): void;
abandonPermissions(): void;
......@@ -35,7 +35,7 @@ export class NativeCommandsSender {
return this.nativeCommandsModule.postLocalNotification(notification, id);
}
getInitialNotification(): Promise<Notification> {
getInitialNotification(): Promise<Object> {
return this.nativeCommandsModule.getInitialNotification();
}
......
......@@ -32,7 +32,7 @@ describe('Commands', () => {
it('returns a promise with the initial notification', async () => {
const expectedNotification: Notification = new Notification({identifier: 'id'});
when(mockedNativeCommandsSender.getInitialNotification()).thenResolve(
expectedNotification
{identifier: 'id'}
);
const result = await uut.getInitialNotification();
expect(result).toEqual(expectedNotification);
......
......@@ -17,9 +17,10 @@ export class Commands {
return result;
}
public getInitialNotification(): Promise<Notification> {
const result = this.nativeCommandsSender.getInitialNotification();
return result;
public async getInitialNotification(): Promise<Notification> {
return this.nativeCommandsSender.getInitialNotification().then((payload) => {
return new Notification(payload);
});
}
public requestPermissions() {
......
......@@ -37,9 +37,6 @@
"androidStudio": "open -a /Applications/Android\\ Studio.app ./example/android"
},
"nativePackage": true,
"dependencies": {
"uuid": "^2.0.3"
},
"peerDependencies": {
"react": ">=0.14.5",
"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