From 1636f74a4cd87cacd8c95be22ec767da6bc5db3f Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 6 Jan 2017 18:07:02 +0100 Subject: Add journey patterns reducers specs and switch from toString to String method when updating checkbox value Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/journey_patterns/reducers_spec.js | 111 ++++++++++++++------- 1 file changed, 76 insertions(+), 35 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/journey_patterns/reducers_spec.js b/spec/javascripts/journey_patterns/reducers_spec.js index ba519dcf4..422c97fee 100644 --- a/spec/javascripts/journey_patterns/reducers_spec.js +++ b/spec/javascripts/journey_patterns/reducers_spec.js @@ -1,5 +1,23 @@ var jpReducer = require('es6_browserified/journey_patterns/reducers/journeyPatterns') let state = [] +let fakeStopPoints = [{ + area_type : "lda", + checked : false, + id : 45289, + name : "Clichy Levallois", + object_id : "FR:92044:LDA:72073:STIF", + object_version : 1, + position : 0, +},{ + area_type : "lda", + checked : false, + id : 40534, + name : "Thomas Lemaître", + object_id : "FR:92050:LDA:70915:STIF", + object_version : 1, + position : 1, +}] + describe('journeyPatterns reducer', () => { beforeEach(()=>{ state = [ @@ -9,23 +27,7 @@ describe('journeyPatterns reducer', () => { object_id : 'o1', published_name: 'M1', registration_number: '', - stop_points: [{ - area_type : "lda", - checked : false, - id : 45289, - name : "Clichy Levallois", - object_id : "FR:92044:LDA:72073:STIF", - object_version : 1, - position : 0, - },{ - area_type : "lda", - checked : false, - id : 40534, - name : "Thomas Lemaître", - object_id : "FR:92050:LDA:70915:STIF", - object_version : 1, - position : 1, - }] + stop_points: fakeStopPoints }, { deletable: false, @@ -33,24 +35,8 @@ describe('journeyPatterns reducer', () => { object_id : 'o2', published_name: 'M2', registration_number: '', - stop_points: [{ - area_type : "lda", - checked : false, - id : 45289, - name : "Clichy Levallois", - object_id : "FR:92044:LDA:72073:STIF", - object_version : 1, - position : 0, - },{ - area_type : "lda", - checked : false, - id : 40534, - name : "Thomas Lemaître", - object_id : "FR:92050:LDA:70915:STIF", - object_version : 1, - position : 1, - }] - }, + stop_points: fakeStopPoints + } ] }) @@ -60,4 +46,59 @@ describe('journeyPatterns reducer', () => { ).toEqual([]) }) + it('should handle ADD_JOURNEYPATTERN', () => { + let fakeData = { + name: {value : 'm3'}, + published_name: {value: 'M3'}, + registration_number: {value: ''} + } + expect( + jpReducer(state, { + type: 'ADD_JOURNEYPATTERN', + data: fakeData + }) + ).toEqual([...state, { + name : 'm3', + published_name: 'M3', + registration_number: '', + deletable: false, + stop_points: fakeStopPoints + }]) + }) + + it('should handle UPDATE_CHECKBOX_VALUE', () => { + let newFirstStopPoint = Object.assign({}, fakeStopPoints[0], {checked: !fakeStopPoints[0].checked} ) + let newStopPoints = [newFirstStopPoint, fakeStopPoints[1]] + let newState = Object.assign({}, state[0], {stop_points: newStopPoints}) + expect( + jpReducer(state, { + type: 'UPDATE_CHECKBOX_VALUE', + id: 45289, + index: 0 + }) + ).toEqual([newState, state[1]]) + }) + + it('should handle DELETE_JOURNEYPATTERN', () => { + expect( + jpReducer(state, { + type: 'DELETE_JOURNEYPATTERN', + index: 1 + }) + ).toEqual([state[0], Object.assign({}, state[1], {deletable: true})]) + }) + it('should handle SAVE_MODAL', () => { + let newState = Object.assign({}, state[0], {name: 'p1', published_name: 'P1', registration_number: 'PP11'}) + expect( + jpReducer(state, { + type: 'SAVE_MODAL', + data: { + name: {value: 'p1'}, + published_name: {value: 'P1'}, + registration_number: {value: 'PP11'} + }, + index: 0 + }) + ).toEqual([newState, state[1]]) + }) }) -- cgit v1.2.3