grafana/public/app/core/reducers/appNotification.test.ts

120 lines
3.0 KiB
TypeScript
Raw Normal View History

import { appNotificationsReducer, clearAppNotification, notifyApp } from './appNotification';
2018-10-24 07:33:53 -05:00
import { AppNotificationSeverity, AppNotificationTimeout } from 'app/types/';
2018-10-22 07:22:40 -05:00
describe('clear alert', () => {
it('should filter alert', () => {
2018-10-23 09:00:04 -05:00
const id1 = 1540301236048;
const id2 = 1540301248293;
2018-10-22 07:22:40 -05:00
const initialState = {
2018-10-23 09:00:04 -05:00
appNotifications: [
2018-10-22 07:22:40 -05:00
{
2018-10-23 09:00:04 -05:00
id: id1,
2018-10-24 03:18:28 -05:00
severity: AppNotificationSeverity.Success,
2018-10-22 07:22:40 -05:00
icon: 'success',
title: 'test',
text: 'test alert',
2018-10-24 07:33:53 -05:00
timeout: AppNotificationTimeout.Success,
2018-10-22 07:22:40 -05:00
},
{
2018-10-23 09:00:04 -05:00
id: id2,
2018-10-24 03:18:28 -05:00
severity: AppNotificationSeverity.Warning,
2018-10-22 07:22:40 -05:00
icon: 'warning',
title: 'test2',
text: 'test alert fail 2',
2018-10-24 07:33:53 -05:00
timeout: AppNotificationTimeout.Warning,
2018-10-22 07:22:40 -05:00
},
],
};
const result = appNotificationsReducer(initialState, clearAppNotification(id2));
2018-10-22 07:22:40 -05:00
const expectedResult = {
2018-10-23 09:00:04 -05:00
appNotifications: [
2018-10-22 07:22:40 -05:00
{
2018-10-23 09:00:04 -05:00
id: id1,
2018-10-24 03:18:28 -05:00
severity: AppNotificationSeverity.Success,
2018-10-22 07:22:40 -05:00
icon: 'success',
title: 'test',
text: 'test alert',
2018-10-24 07:33:53 -05:00
timeout: AppNotificationTimeout.Success,
2018-10-22 07:22:40 -05:00
},
],
};
expect(result).toEqual(expectedResult);
});
});
describe('notify', () => {
it('create notify message', () => {
const id1 = 1540301236048;
const id2 = 1540301248293;
const id3 = 1540301248203;
const initialState = {
appNotifications: [
{
id: id1,
severity: AppNotificationSeverity.Success,
icon: 'success',
title: 'test',
text: 'test alert',
timeout: AppNotificationTimeout.Success,
},
{
id: id2,
severity: AppNotificationSeverity.Warning,
icon: 'warning',
title: 'test2',
text: 'test alert fail 2',
timeout: AppNotificationTimeout.Warning,
},
],
};
const result = appNotificationsReducer(
initialState,
notifyApp({
id: id3,
severity: AppNotificationSeverity.Info,
icon: 'info',
title: 'test3',
text: 'test alert info 3',
timeout: AppNotificationTimeout.Success,
})
);
const expectedResult = {
appNotifications: [
{
id: id1,
severity: AppNotificationSeverity.Success,
icon: 'success',
title: 'test',
text: 'test alert',
timeout: AppNotificationTimeout.Success,
},
{
id: id2,
severity: AppNotificationSeverity.Warning,
icon: 'warning',
title: 'test2',
text: 'test alert fail 2',
timeout: AppNotificationTimeout.Warning,
},
{
id: id3,
severity: AppNotificationSeverity.Info,
icon: 'info',
title: 'test3',
text: 'test alert info 3',
timeout: AppNotificationTimeout.Success,
},
],
};
expect(result).toEqual(expectedResult);
});
});