client/src/reducers/__tests__/notesReducer.test.js
changeset 3 3b5d37d84cfe
child 168 ea92f4fe783d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/reducers/__tests__/notesReducer.test.js	Tue May 23 13:15:34 2017 +0200
@@ -0,0 +1,94 @@
+// 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
+//         }
+//       ]
+//     )