diff options
| author | Thomas Haddad | 2017-01-06 18:07:02 +0100 |
|---|---|---|
| committer | Thomas Haddad | 2017-01-06 18:08:28 +0100 |
| commit | 1636f74a4cd87cacd8c95be22ec767da6bc5db3f (patch) | |
| tree | 5f7ed35dc3f84e180ec25ced1853156a2aa80bb9 | |
| parent | 51534c59d3ddebf72a186cfc120d0481fab95d78 (diff) | |
| download | chouette-core-1636f74a4cd87cacd8c95be22ec767da6bc5db3f.tar.bz2 | |
Add journey patterns reducers specs and switch from toString to String method when updating checkbox value
Signed-off-by: Thomas Shawarma Haddad <thomas.haddad@af83.com>
| -rw-r--r-- | app/assets/javascripts/es6_browserified/journey_patterns/reducers/journeyPatterns.js | 2 | ||||
| -rw-r--r-- | spec/javascripts/journey_patterns/reducers_spec.js | 111 |
2 files changed, 77 insertions, 36 deletions
diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/reducers/journeyPatterns.js b/app/assets/javascripts/es6_browserified/journey_patterns/reducers/journeyPatterns.js index 4c1b637b3..96f6bd8c2 100644 --- a/app/assets/javascripts/es6_browserified/journey_patterns/reducers/journeyPatterns.js +++ b/app/assets/javascripts/es6_browserified/journey_patterns/reducers/journeyPatterns.js @@ -16,7 +16,7 @@ const journeyPattern = (state = {}, action) => { } case 'UPDATE_CHECKBOX_VALUE': var updatedStopPoints = state.stop_points.map((s) => { - if (s.id.toString() == action.id) { + if (String(s.id) == action.id) { return Object.assign({}, s, {checked : !s.checked}) }else { return s 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]]) + }) }) |
