123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- import { AppNotificationSeverity, AppNotificationsState } from 'app/types/';
- import { appNotificationsReducer, clearNotification, notifyApp } from './appNotification';
- const timestamp = 1649849468889;
- describe('clear alert', () => {
- it('should filter alert', () => {
- const id1 = '1767d3d9-4b99-40eb-ab46-de734a66f21d';
- const id2 = '4767b3de-12dd-40e7-b58c-f778bd59d675';
- const initialState: AppNotificationsState = {
- byId: {
- [id1]: {
- id: id1,
- severity: AppNotificationSeverity.Success,
- icon: 'success',
- title: 'test',
- text: 'test alert',
- showing: true,
- timestamp,
- },
- [id2]: {
- id: id2,
- severity: AppNotificationSeverity.Warning,
- icon: 'warning',
- title: 'test2',
- text: 'test alert fail 2',
- showing: true,
- timestamp,
- },
- },
- lastRead: timestamp - 10,
- };
- const result = appNotificationsReducer(initialState, clearNotification(id2));
- const expectedResult: AppNotificationsState = {
- byId: {
- [id1]: {
- id: id1,
- severity: AppNotificationSeverity.Success,
- icon: 'success',
- title: 'test',
- text: 'test alert',
- showing: true,
- timestamp,
- },
- },
- lastRead: timestamp - 10,
- };
- expect(result).toEqual(expectedResult);
- });
- });
- describe('notify', () => {
- it('create notify message', () => {
- const id1 = '696da53b-6ae7-4824-9e0e-d6a3b54a2c74';
- const id2 = '4477fcd9-246c-45a5-8818-e22a16683dae';
- const id3 = '55be87a8-bbab-45c7-b481-1f9d46f0d2ee';
- const initialState: AppNotificationsState = {
- byId: {
- [id1]: {
- id: id1,
- severity: AppNotificationSeverity.Success,
- icon: 'success',
- title: 'test',
- text: 'test alert',
- showing: true,
- timestamp,
- },
- [id2]: {
- id: id2,
- severity: AppNotificationSeverity.Warning,
- icon: 'warning',
- title: 'test2',
- text: 'test alert fail 2',
- showing: true,
- timestamp,
- },
- },
- lastRead: timestamp - 10,
- };
- const result = appNotificationsReducer(
- initialState,
- notifyApp({
- id: id3,
- severity: AppNotificationSeverity.Info,
- icon: 'info',
- title: 'test3',
- text: 'test alert info 3',
- showing: true,
- timestamp: 1649802870373,
- })
- );
- const expectedResult: AppNotificationsState = {
- byId: {
- [id1]: {
- id: id1,
- severity: AppNotificationSeverity.Success,
- icon: 'success',
- title: 'test',
- text: 'test alert',
- timestamp,
- showing: true,
- },
- [id2]: {
- id: id2,
- severity: AppNotificationSeverity.Warning,
- icon: 'warning',
- title: 'test2',
- text: 'test alert fail 2',
- timestamp,
- showing: true,
- },
- [id3]: {
- id: id3,
- severity: AppNotificationSeverity.Info,
- icon: 'info',
- title: 'test3',
- text: 'test alert info 3',
- timestamp: 1649802870373,
- showing: true,
- },
- },
- lastRead: timestamp - 10,
- };
- expect(result).toEqual(expectedResult);
- });
- it('Dedupe identical alerts', () => {
- const initialState: AppNotificationsState = {
- byId: {
- id1: {
- id: 'id1',
- severity: AppNotificationSeverity.Success,
- icon: 'success',
- title: 'test',
- text: 'test alert',
- showing: true,
- timestamp,
- },
- },
- lastRead: timestamp - 10,
- };
- const result = appNotificationsReducer(
- initialState,
- notifyApp({
- id: 'id2',
- severity: AppNotificationSeverity.Success,
- icon: 'success',
- title: 'test',
- text: 'test alert',
- showing: true,
- timestamp,
- })
- );
- const expectedResult: AppNotificationsState = {
- byId: {
- id1: {
- id: 'id1',
- severity: AppNotificationSeverity.Success,
- icon: 'success',
- title: 'test',
- text: 'test alert',
- showing: true,
- timestamp,
- },
- },
- lastRead: timestamp - 10,
- };
- expect(result).toEqual(expectedResult);
- });
- });
|