influxdb/ui/test/shared/reducers/notifications.test.ts

59 lines
1.6 KiB
TypeScript
Raw Normal View History

import {initialState, notifications} from 'src/shared/reducers/notifications'
import {notify, dismissNotification} from 'src/shared/actions/notifications'
2018-03-14 02:00:35 +00:00
import {FIVE_SECONDS} from 'src/shared/constants/index'
const notificationID = '000'
const exampleNotification = {
id: notificationID,
type: 'success',
message: 'Hell yeah you are a real notification!',
2018-03-14 02:00:35 +00:00
duration: FIVE_SECONDS,
icon: 'zap',
}
2018-03-14 02:00:35 +00:00
const exampleNotifications = [exampleNotification]
describe('Shared.Reducers.notifications', () => {
it('should publish a notification', () => {
2018-03-14 22:26:09 +00:00
const [actual] = notifications(initialState, notify(exampleNotification))
2018-03-14 19:33:23 +00:00
const [expected] = [exampleNotification, ...initialState]
expect(actual.type).toEqual(expected.type)
expect(actual.icon).toEqual(expected.icon)
expect(actual.message).toEqual(expected.message)
expect(actual.duration).toEqual(expected.duration)
})
describe('adding more than one notification', () => {
it('should put the new notification at the beggining of the list', () => {
const newNotification = {
type: 'error',
message: 'new notification',
duration: FIVE_SECONDS,
icon: 'zap',
}
const actual = notifications(
exampleNotifications,
2018-03-14 22:26:09 +00:00
notify(newNotification)
2018-03-14 19:33:23 +00:00
)
expect(actual.length).toBe(2)
expect(actual[0].message).toEqual(newNotification.message)
})
})
it('should dismiss a notification', () => {
2018-03-14 19:33:23 +00:00
const actual = notifications(
exampleNotifications,
dismissNotification(notificationID)
)
2018-03-02 20:26:46 +00:00
expect(actual.length).toBe(0)
})
})