From 3fb20fcc5ca5c39fae2c793e822eac1a2b2f6cb7 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 17 Nov 2016 17:42:29 +0100 Subject: Add reducers tests, some skipped until better es6 support while testing Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/reducers_spec.js | 178 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 spec/javascripts/reducers_spec.js (limited to 'spec/javascripts') diff --git a/spec/javascripts/reducers_spec.js b/spec/javascripts/reducers_spec.js new file mode 100644 index 000000000..a4880e73e --- /dev/null +++ b/spec/javascripts/reducers_spec.js @@ -0,0 +1,178 @@ +var reducer = require('es6_browserified/reducers/todos') +let state = [] +describe('stops reducer', () => { + beforeEach(()=>{ + state = [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + }) + + it('should return the initial state', () => { + expect( + reducer(undefined, {}) + ).toEqual([]) + }) + + it('should handle ADD_STOP', () => { + expect( + reducer(state, { + type: 'ADD_STOP' + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: '', + index: 2, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle MOVE_UP_STOP', () => { + expect( + reducer(state, { + type: 'MOVE_STOP_UP', + index: 1 + }) + ).toEqual( + [ + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle MOVE_DOWN_STOP', () => { + expect( + reducer(state, { + type: 'MOVE_STOP_DOWN', + index: 0 + }) + ).toEqual( + [ + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + it('should handle DELETE_STOP', () => { + expect( + reducer(state, { + type: 'DELETE_STOP', + index: 1 + }) + ).toEqual( + [ + { + text: 'first', + index: 0, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + //TODO unskip when es6 is properly functionnal + xit('should handle UPDATE_INPUT_VALUE', () => { + expect( + reducer(state, { + type: 'UPDATE_INPUT_VALUE', + index: 0, + text: { + text: "new value", + stoparea_id: 1 + } + }) + ).toEqual( + [ + { + text: 'new value', + index: 0, + stoparea_id: 1, + for_boarding: 'normal', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) + + xit('should handle UPDATE_SELECT_VALUE', () => { + expect( + reducer(state, { + type :'UPDATE_SELECT_VALUE', + select_id: 'for_boarding', + select_value: 'prohibited', + index: 0 + }) + ).toEqual( + [ + { + text: 'new value', + index: 0, + stoparea_id: 1, + for_boarding: 'prohibited', + for_alighting: 'normal' + }, + { + text: 'second', + index: 1, + for_boarding: 'normal', + for_alighting: 'normal' + } + ] + ) + }) +}) -- cgit v1.2.3