Notifications.test.js 1.66 KB
Newer Older
yogevbd's avatar
WIP  
yogevbd committed
1
const Utils = require('./Utils');
yogevbd's avatar
yogevbd committed
2
const {elementByLabel} = Utils;
yogevbd's avatar
WIP  
yogevbd committed
3 4

describe('Notifications', () => {
yogevbd's avatar
yogevbd committed
5 6 7
  beforeEach(async () => {
    await device.relaunchApp({delete: true, permissions: {notifications: 'YES'}});
  });
8

yogevbd's avatar
yogevbd committed
9
  describe('Foreground', () => {
10 11 12 13 14
    it('Receive notification', async () => {
      await device.sendUserNotification(createNotification({link: 'foreground/notification'}));
      await expect(elementByLabel('foreground/notification')).toBeVisible();
    });

15
    it('Click notification', async () => {
16 17 18 19 20 21 22
      await device.sendUserNotification(createNotification({link: 'foreground/notification/click', showAlert: true}));
      await expect(elementByLabel('Notification Clicked: foreground/notification/click')).toBeVisible();
    });
  });

  describe('Background', () => {
    it('Receive notification', async () => {
yogevbd's avatar
yogevbd committed
23
      await device.sendToHome();
yogevbd's avatar
yogevbd committed
24
      await expect(elementByLabel('background/notification')).toBeNotVisible();
yogevbd's avatar
yogevbd committed
25
      await device.launchApp({newInstance: false, userNotification: createNotification({link: 'background/notification'})});
26 27
      await expect(elementByLabel('background/notification')).toBeVisible();
    });
yogevbd's avatar
WIP  
yogevbd committed
28 29
  });

30 31
  describe('Dead state', () => {
    it('Receive notification', async () => {
yogevbd's avatar
yogevbd committed
32
      await device.launchApp({newInstance: true, userNotification: createNotification({link: 'deadState/notification'})});
33 34
      await expect(elementByLabel('deadState/notification')).toBeVisible();
    });
yogevbd's avatar
WIP  
yogevbd committed
35 36 37
  });
});

38
function createNotification({link, showAlert}) {
yogevbd's avatar
WIP  
yogevbd committed
39 40 41 42 43 44 45 46 47
  return {
    trigger: {
      type: 'push'
    },
    title: 'From push',
    subtitle: 'Subtitle',
    body: 'Body',
    badge: 1,
    payload: {
48 49 50
      link,
      showAlert
    }
yogevbd's avatar
WIP  
yogevbd committed
51
  };
52
}