Notifications.test.js 1.69 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', () => {
5 6 7 8 9 10 11 12 13 14
  describe('Foreground', () => {
    beforeEach(async () => {
      await device.relaunchApp({permissions: {notifications: 'YES'}});
    });

    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', () => {
    beforeEach(async () => {
23
      await device.launchApp({newInstance: true, permissions: {notifications: 'YES'}});
24 25 26 27 28 29 30
    });

    it('Receive notification', async () => {
      device.sendToHome();
      device.launchApp({newInstance: false, userNotification: createNotification({link: 'background/notification'})});
      await expect(elementByLabel('background/notification')).toBeVisible();
    });
yogevbd's avatar
WIP  
yogevbd committed
31 32
  });

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

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