client/src/reducers/__tests__/notesReducer.test.js
author ymh <ymh.work@gmail.com>
Tue, 23 May 2017 13:15:34 +0200
changeset 3 3b5d37d84cfe
child 168 ea92f4fe783d
permissions -rw-r--r--
Some code rename and reorg + basic tests

// cf http://redux.js.org/docs/recipes/WritingTests.html

import Immutable from 'immutable';

import uuidV1 from 'uuid/v1';

import reducer from '../notesReducer'
import * as types from '../../constants/ActionTypes'
import noteRecord from '../../store/noteRecord';

describe('note reducer', () => {
  it('should return the initial state', () => {
    expect(
      reducer(undefined, {})
    ).toEqual(Immutable.List([]))
  });

  it('should handle ADD_NOTE', () => {

    const newId = uuidV1();
    expect(
      reducer(Immutable.List([]), {
        type: types.ADD_NOTE,
        note: {
          id: newId,
          text: 'Run the tests'
        }
      })
    ).toEqual(
      Immutable.List([
        new noteRecord({
          id: newId,
          text: 'Run the tests',
        })
      ])
    );

    const initialStore = Immutable.List([
        new noteRecord({
          id: uuidV1(),
          text: 'origial note',
        })
    ]);
    expect(
      reducer(initialStore, {
        type: types.ADD_NOTE,
        note: {
          id: newId,
          text: 'Run the tests'
        }
      })
    ).toEqual(
      initialStore.push(
        new noteRecord({
          id: newId,
          text: 'Run the tests',
        })
      )
    );

  });



});

//     expect(
//       reducer(
//         [
//           {
//             text: 'Use Redux',
//             completed: false,
//             id: 0
//           }
//         ],
//         {
//           type: types.ADD_TODO,
//           text: 'Run the tests'
//         }
//       )
//     ).toEqual(
//       [
//         {
//           text: 'Run the tests',
//           completed: false,
//           id: 1
//         },
//         {
//           text: 'Use Redux',
//           completed: false,
//           id: 0
//         }
//       ]
//     )