client/src/reducers/__tests__/notesReducer.test.js
changeset 3 3b5d37d84cfe
child 168 ea92f4fe783d
equal deleted inserted replaced
2:b52921a63e77 3:3b5d37d84cfe
       
     1 // cf http://redux.js.org/docs/recipes/WritingTests.html
       
     2 
       
     3 import Immutable from 'immutable';
       
     4 
       
     5 import uuidV1 from 'uuid/v1';
       
     6 
       
     7 import reducer from '../notesReducer'
       
     8 import * as types from '../../constants/ActionTypes'
       
     9 import noteRecord from '../../store/noteRecord';
       
    10 
       
    11 describe('note reducer', () => {
       
    12   it('should return the initial state', () => {
       
    13     expect(
       
    14       reducer(undefined, {})
       
    15     ).toEqual(Immutable.List([]))
       
    16   });
       
    17 
       
    18   it('should handle ADD_NOTE', () => {
       
    19 
       
    20     const newId = uuidV1();
       
    21     expect(
       
    22       reducer(Immutable.List([]), {
       
    23         type: types.ADD_NOTE,
       
    24         note: {
       
    25           id: newId,
       
    26           text: 'Run the tests'
       
    27         }
       
    28       })
       
    29     ).toEqual(
       
    30       Immutable.List([
       
    31         new noteRecord({
       
    32           id: newId,
       
    33           text: 'Run the tests',
       
    34         })
       
    35       ])
       
    36     );
       
    37 
       
    38     const initialStore = Immutable.List([
       
    39         new noteRecord({
       
    40           id: uuidV1(),
       
    41           text: 'origial note',
       
    42         })
       
    43     ]);
       
    44     expect(
       
    45       reducer(initialStore, {
       
    46         type: types.ADD_NOTE,
       
    47         note: {
       
    48           id: newId,
       
    49           text: 'Run the tests'
       
    50         }
       
    51       })
       
    52     ).toEqual(
       
    53       initialStore.push(
       
    54         new noteRecord({
       
    55           id: newId,
       
    56           text: 'Run the tests',
       
    57         })
       
    58       )
       
    59     );
       
    60 
       
    61   });
       
    62 
       
    63 
       
    64 
       
    65 });
       
    66 
       
    67 //     expect(
       
    68 //       reducer(
       
    69 //         [
       
    70 //           {
       
    71 //             text: 'Use Redux',
       
    72 //             completed: false,
       
    73 //             id: 0
       
    74 //           }
       
    75 //         ],
       
    76 //         {
       
    77 //           type: types.ADD_TODO,
       
    78 //           text: 'Run the tests'
       
    79 //         }
       
    80 //       )
       
    81 //     ).toEqual(
       
    82 //       [
       
    83 //         {
       
    84 //           text: 'Run the tests',
       
    85 //           completed: false,
       
    86 //           id: 1
       
    87 //         },
       
    88 //         {
       
    89 //           text: 'Use Redux',
       
    90 //           completed: false,
       
    91 //           id: 0
       
    92 //         }
       
    93 //       ]
       
    94 //     )