From b603312ddf55899e8a75522d407c40474948ae0b Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Tue, 13 Aug 2019 23:10:40 -0400 Subject: [PATCH] Copy tests to todos slice --- src/features/todos/todosSlice.spec.js | 123 ++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/features/todos/todosSlice.spec.js diff --git a/src/features/todos/todosSlice.spec.js b/src/features/todos/todosSlice.spec.js new file mode 100644 index 0000000..1c4e73c --- /dev/null +++ b/src/features/todos/todosSlice.spec.js @@ -0,0 +1,123 @@ +import todos from './todosSlice' + +describe('todos reducer', () => { + it('should handle initial state', () => { + expect(todos(undefined, {})).toEqual([]) + }) + + it('should handle ADD_TODO', () => { + expect( + todos([], { + type: 'ADD_TODO', + text: 'Run the tests', + id: 0 + }) + ).toEqual([ + { + text: 'Run the tests', + completed: false, + id: 0 + } + ]) + + expect( + todos( + [ + { + text: 'Run the tests', + completed: false, + id: 0 + } + ], + { + type: 'ADD_TODO', + text: 'Use Redux', + id: 1 + } + ) + ).toEqual([ + { + text: 'Run the tests', + completed: false, + id: 0 + }, + { + text: 'Use Redux', + completed: false, + id: 1 + } + ]) + + expect( + todos( + [ + { + text: 'Run the tests', + completed: false, + id: 0 + }, + { + text: 'Use Redux', + completed: false, + id: 1 + } + ], + { + type: 'ADD_TODO', + text: 'Fix the tests', + id: 2 + } + ) + ).toEqual([ + { + text: 'Run the tests', + completed: false, + id: 0 + }, + { + text: 'Use Redux', + completed: false, + id: 1 + }, + { + text: 'Fix the tests', + completed: false, + id: 2 + } + ]) + }) + + it('should handle TOGGLE_TODO', () => { + expect( + todos( + [ + { + text: 'Run the tests', + completed: false, + id: 1 + }, + { + text: 'Use Redux', + completed: false, + id: 0 + } + ], + { + type: 'TOGGLE_TODO', + id: 1 + } + ) + ).toEqual([ + { + text: 'Run the tests', + completed: true, + id: 1 + }, + { + text: 'Use Redux', + completed: false, + id: 0 + } + ]) + }) +})