import {expect} from 'chai';
import reducer, {types, actions} from '../../src/redux/modules/notifications';

const notification = {
  id: 1234567899874,
  message: 'message',
  type: 'error',
  dismissible: false,
  dismissAfter: 4000
};

describe('actions', () => {
  it('should create an action to add a notification', () => {
    const expectedAction = {
      type: types.ADD_NOTIFICATION,
      payload: notification
    };
    expect(actions.pushNotification(notification)).to.deep.equal(expectedAction)
  });
});

describe('reducers', () => {
  it('should return the initial state', () => {
    expect(reducer(undefined, {})).to.deep.equal([])
  });
  
  it('should handle ADD_NOTIFICATION', () => {
    expect(
      reducer([], {
        type: types.ADD_NOTIFICATION,
        payload: notification
      })
    ).to.deep.equal([notification])
  });

  it('should handle UPDATE_NOTIFICATION', () => {
    const newNotification = {
      id: notification.id,
      message: 'message updated',
      type:'error',
      dismissible:true,
      dismissAfter: 10000
    };
    expect(
      reducer([notification],{
        type: types.UPDATE_NOTIFICATION,
        payload: newNotification
      })
    ).to.deep.equal([newNotification])
  });

  it('should handle REMOVE_NOTIFICATION', () => {
    expect(
      reducer([notification],{
        type: types.REMOVE_NOTIFICATION,
        payload: notification.id
      })
    ).to.deep.equal([])
  });
});
@@ -22,16 +22,98 @@
 'chai';%0A
+import configureMockStore from 'redux-mock-store'%0Aimport thunk from 'redux-thunk'%0A
 import r
@@ -135,16 +135,33 @@
  actions
+, addNotification
 %7D from '
@@ -513,32 +513,32 @@
 fication%0A    %7D;%0A
-
     expect(actio
@@ -603,24 +603,1227 @@
 ction)%0A  %7D);
+%0A%0A  it('should create an action to add a notification and return a notification object ', () =%3E %7B%0A    const middlewares = %5Bthunk%5D;%0A    const mockStore = configureMockStore(middlewares);%0A    const notification = %7B%0A      message: 'message',%0A      type: 'error',%0A      dismissible: false,%0A      dismissAfter: 4000%0A    %7D;%0A    const store = mockStore(%7Bnotifications: %5B%5D%7D);%0A    const notificationAdded = store.dispatch(addNotification(notification));%0A    const expectedAction = %5B%7B%0A      type: types.ADD_NOTIFICATION,%0A      payload: Object.assign(%7B%7D, notification, %7B%0A        id:notificationAdded.id%0A      %7D)%0A    %7D%5D;%0A    expect(store.getActions()).to.deep.equal(expectedAction)%0A  %7D);%0A%0A  it('should create an action to update a notification', () =%3E %7B%0A    const expectedAction = %7B%0A      type: types.UPDATE_NOTIFICATION,%0A      payload: notification%0A    %7D;%0A    expect(actions.updateNotification(notification)).to.deep.equal(expectedAction)%0A  %7D);%0A%0A  it('should create an action to remove a notification', () =%3E %7B%0A    const id = notification.id;%0A    const expectedAction = %7B%0A      type: types.REMOVE_NOTIFICATION,%0A      payload: id%0A    %7D;%0A    expect(actions.removeNotification(id)).to.deep.equal(expectedAction)%0A  %7D);
 %0A%7D);%0A%0Adescri

add tests for actions