From 5763693705265982ad569739ce076052a91fb6bd Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 13 Dec 2017 12:33:31 +0100 Subject: Fix VJ spec --- spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/javascript') diff --git a/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js index c02ab3398..1c2cc1577 100644 --- a/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js @@ -106,6 +106,7 @@ describe('vehicleJourneys reducer', () => { company: fakeSelectedCompany, published_journey_name: 'test', published_journey_identifier: '', + short_id: '', objectid: '', footnotes: [], time_tables: [], -- cgit v1.2.3 From b1068fb08a20a0502ba3654d38207a99e5c756d9 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 22 Dec 2017 12:23:28 +0100 Subject: Refactor stopPointsReducer spec; For now no bug has been fixed :-) --- .../javascript/routes/reducers/stop_points_spec.js | 574 +++++---------------- 1 file changed, 133 insertions(+), 441 deletions(-) (limited to 'spec/javascript') diff --git a/spec/javascript/routes/reducers/stop_points_spec.js b/spec/javascript/routes/reducers/stop_points_spec.js index b375cdc2c..b812fbb71 100644 --- a/spec/javascript/routes/reducers/stop_points_spec.js +++ b/spec/javascript/routes/reducers/stop_points_spec.js @@ -1,7 +1,11 @@ import stopPointsReducer from '../../../../app/javascript/routes/reducers/stopPoints' +import formHelper from '../../../../app/javascript/routes/form_helper' +import _ from 'lodash' let state = [] +formHelper.addInput = (...args)=>{} + let fakeData = { geometry: undefined, registration_number: 'rn_test', @@ -10,34 +14,39 @@ let fakeData = { user_objectid: 'uoid_test' } +let update_stop_point = (stop_point, opts) => { + return _.assign({}, stop_point, opts) +} + +let stop_point = (opts) => { + return _.assign({}, + { + text: "", + index: 0, + edit: false, + for_boarding: 'normal', + for_alighting: 'normal', + olMap: { isOpened: false, json: {} } + }, + opts + ) +} + +let stop_point_1 = stop_point({text: 'first', index: 0, stoppoint_id: 72 }) +let stop_point_2 = stop_point({text: 'second', index: 1, stoppoint_id: 73 }) +let stop_point_3 = stop_point({text: 'third', index: 2, stoppoint_id: 74 }) + +let it_should_handle = (action, final_state, custom_state=null) => { + it("should handle "+ action.type, () => { + expect( + stopPointsReducer(custom_state || state, action) + ).toEqual( final_state ) + }) +} + describe('stops reducer', () => { beforeEach(()=>{ - state = [ - { - text: 'first', - index: 0, - stoppoint_id: 72, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - }, - { - text: 'second', - index: 1, - stoppoint_id: 73, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - } - ] + state = [ stop_point_1, stop_point_2, stop_point_3 ] }) it('should return the initial state', () => { @@ -46,441 +55,124 @@ describe('stops reducer', () => { ).toEqual([]) }) - it('should handle ADD_STOP', () => { - expect( - stopPointsReducer(state, { - type: 'ADD_STOP' - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - stoppoint_id: 72, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - }, - { - text: 'second', - index: 1, - stoppoint_id: 73, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - }, - { - text: '', - index: 2, - edit: true, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - } - ] - ) - }) + it_should_handle( + {type: "ADD_STOP"}, + [stop_point_1, stop_point_2, stop_point_3, stop_point({index: 3, edit: true})] + ) - it('should handle MOVE_UP_STOP', () => { - expect( - stopPointsReducer(state, { - type: 'MOVE_STOP_UP', - index: 1 - }) - ).toEqual( - [ - { - text: 'second', - index: 1, - stoppoint_id: 72, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - }, - { - text: 'first', - index: 0, - stoppoint_id: 73, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - } - ] - ) - }) + it_should_handle( + {type: 'MOVE_STOP_UP', index: 1}, + [ update_stop_point(stop_point_2, {stoppoint_id: 72}), update_stop_point(stop_point_1, {stoppoint_id: 73}), stop_point_3 ] + ) - it('should handle MOVE_DOWN_STOP', () => { - expect( - stopPointsReducer(state, { - type: 'MOVE_STOP_DOWN', - index: 0 - }) - ).toEqual( - [ - { - text: 'second', - index: 1, - stoppoint_id: 72, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - }, - { - text: 'first', - index: 0, - stoppoint_id: 73, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - } - ] - ) - }) + it_should_handle( + {type: 'MOVE_STOP_DOWN', index: 0}, + [ update_stop_point(stop_point_2, {stoppoint_id: 72}), update_stop_point(stop_point_1, {stoppoint_id: 73}), stop_point_3 ] + ) - // it('should handle DELETE_STOP', () => { - // expect( - // stopPointsReducer(state, { - // type: 'DELETE_STOP', - // index: 1 - // }) - // ).toEqual( - // [ - // { - // text: 'first', - // index: 0, - // stoppoint_id: 72, - // edit: false, - // for_boarding: 'normal', - // for_alighting: 'normal', - // olMap: { - // isOpened: false, - // json: {} - // } - // } - // ] - // ) - // }) + it_should_handle( + {type: 'DELETE_STOP', index: 1}, + [stop_point_1, stop_point_3] + ) - it('should handle UPDATE_INPUT_VALUE', () => { - expect( - stopPointsReducer(state, { - type: 'UPDATE_INPUT_VALUE', - index: 0, - edit: false, - text: { - text: "new value", - name: 'new', - stoparea_id: 1, - user_objectid: "1234", - longitude: 123, - latitude: 123, - registration_number: '0', - city_name: 'city', - area_type: 'area', - short_name: 'new', - comment: 'newcomment' - } - }) - ).toEqual( - [ - { - text: 'new value', - name: 'new', - index: 0, - stoppoint_id: 72, - edit: false, - stoparea_id: 1, - for_boarding: 'normal', - for_alighting: 'normal', - user_objectid: "1234", - longitude: 123, - latitude: 123, - registration_number: '0', - city_name: 'city', - area_type: 'area', - short_name: 'new', - comment: 'newcomment', - olMap: { - isOpened: false, - json: {} - } - }, - { - text: 'second', - index: 1, - stoppoint_id: 73, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - } - ] - ) - }) + let text = { + text: "new value", + name: 'new', + stoparea_id: 1, + user_objectid: "1234", + longitude: 123, + latitude: 123, + registration_number: '0', + city_name: 'city', + area_type: 'area', + short_name: 'new', + comment: 'newcomment' + } + it_should_handle( + {type: 'UPDATE_INPUT_VALUE', index: 0, text: text}, + [ + update_stop_point(stop_point_1, text), + stop_point_2, + stop_point_3 + ] + ) - it('should handle UPDATE_SELECT_VALUE', () => { - expect( - stopPointsReducer(state, { - type :'UPDATE_SELECT_VALUE', - select_id: 'for_boarding', - select_value: 'prohibited', - index: 0 - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - stoppoint_id: 72, - edit: false, - for_boarding: 'prohibited', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - }, - { - text: 'second', - index: 1, - stoppoint_id: 73, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - } - ] - ) - }) + it_should_handle( + {type: 'UPDATE_SELECT_VALUE', index: 0, select_id: 'for_boarding', select_value: 'prohibited'}, + [ + update_stop_point(stop_point_1, {for_boarding: 'prohibited'}), + stop_point_2, + stop_point_3 + ] + ) - it('should handle TOGGLE_MAP', () => { - expect( - stopPointsReducer(state, { - type: 'TOGGLE_MAP', - index: 0 - }) - ).toEqual( - [ - { + it_should_handle( + {type: 'TOGGLE_MAP', index: 0}, + [ + update_stop_point(stop_point_1, {olMap: { + isOpened: true, + json: { text: 'first', index: 0, stoppoint_id: 72, edit: false, for_boarding: 'normal', for_alighting: 'normal', - olMap: { - isOpened: true, - json: { - text: 'first', - index: 0, - stoppoint_id: 72, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: undefined - } - } - }, - { - text: 'second', - index: 1, - stoppoint_id: 73, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } + olMap: undefined } - ] - ) - }) + }}), + stop_point_2, + stop_point_3 + ] + ) - it('should handle TOGGLE_EDIT', () => { - expect( - stopPointsReducer(state, { - type: 'TOGGLE_EDIT', - index: 0 - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - stoppoint_id: 72, - edit: true, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - }, - { - text: 'second', - index: 1, - stoppoint_id: 73, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - } - ] - ) - }) + it_should_handle( + {type: 'TOGGLE_EDIT', index: 0}, + [ + update_stop_point(stop_point_1, {edit: true}), + stop_point_2, + stop_point_3 + ] + ) - it('should handle SELECT_MARKER', () => { - let openedMapState = [ - { - text: 'first', - index: 0, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: true, - json: {} - } - }, - { - text: 'second', - index: 1, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } + let openedMapState = [ + update_stop_point(stop_point_1, { + olMap: { + isOpened: true, + json: {} } - ] - expect( - stopPointsReducer(openedMapState, { - type: 'SELECT_MARKER', - index: 0, - data: fakeData - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: true, - json: fakeData - } - }, - { - text: 'second', - index: 1, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - } - ] - ) - }) + }), + stop_point_2, + stop_point_3 + ] - it('should handle UNSELECT_MARKER', () => { - let openedMapState = [ - { - text: 'first', - index: 0, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', + it_should_handle( + {type: 'SELECT_MARKER', index: 0, data: fakeData}, + [ + update_stop_point(stop_point_1, { olMap: { isOpened: true, - json: {} - } - }, - { - text: 'second', - index: 1, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', + json: fakeData + } + }), + stop_point_2, + stop_point_3 + ], + openedMapState + ) + + it_should_handle( + {type: 'UNSELECT_MARKER', index: 0}, + [ + update_stop_point(stop_point_1, { olMap: { - isOpened: false, + isOpened: true, json: {} } - } - ] - - expect( - stopPointsReducer(openedMapState, { - type: 'UNSELECT_MARKER', - index: 0 - }) - ).toEqual( - [ - { - text: 'first', - index: 0, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: true, - json: {} - } - }, - { - text: 'second', - index: 1, - edit: false, - for_boarding: 'normal', - for_alighting: 'normal', - olMap: { - isOpened: false, - json: {} - } - } - ] - ) - }) + }), + stop_point_2, + stop_point_3 + ], + openedMapState + ) }) -- cgit v1.2.3 From f9978a2cde70f378ec1d8afa34f086ad78a0e1be Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 22 Dec 2017 13:56:48 +0100 Subject: Update Specs to what should be the correct behaviour --- spec/javascript/routes/reducers/stop_points_spec.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'spec/javascript') diff --git a/spec/javascript/routes/reducers/stop_points_spec.js b/spec/javascript/routes/reducers/stop_points_spec.js index b812fbb71..124618f9d 100644 --- a/spec/javascript/routes/reducers/stop_points_spec.js +++ b/spec/javascript/routes/reducers/stop_points_spec.js @@ -2,6 +2,12 @@ import stopPointsReducer from '../../../../app/javascript/routes/reducers/stopPo import formHelper from '../../../../app/javascript/routes/form_helper' import _ from 'lodash' + // _ _ ___ _ ___ ___ ___ ___ + // | || | __| | | _ \ __| _ \/ __| + // | __ | _|| |__| _/ _|| /\__ \ + // |_||_|___|____|_| |___|_|_\|___/ + // + let state = [] formHelper.addInput = (...args)=>{} @@ -44,6 +50,14 @@ let it_should_handle = (action, final_state, custom_state=null) => { }) } + + // ___ ___ ___ ___ ___ + // / __| _ \ __/ __/ __| + // \__ \ _/ _| (__\__ \ + // |___/_| |___\___|___/ + // + + describe('stops reducer', () => { beforeEach(()=>{ state = [ stop_point_1, stop_point_2, stop_point_3 ] @@ -62,12 +76,12 @@ describe('stops reducer', () => { it_should_handle( {type: 'MOVE_STOP_UP', index: 1}, - [ update_stop_point(stop_point_2, {stoppoint_id: 72}), update_stop_point(stop_point_1, {stoppoint_id: 73}), stop_point_3 ] + [ update_stop_point(stop_point_2, {index: 0}), update_stop_point(stop_point_1, {index: 1}), stop_point_3 ] ) it_should_handle( {type: 'MOVE_STOP_DOWN', index: 0}, - [ update_stop_point(stop_point_2, {stoppoint_id: 72}), update_stop_point(stop_point_1, {stoppoint_id: 73}), stop_point_3 ] + [ update_stop_point(stop_point_2, {index: 0}), update_stop_point(stop_point_1, {index: 1}), stop_point_3 ] ) it_should_handle( -- cgit v1.2.3 From 344c7f884f4c25ece7490c94dfcb82e66bff0b2d Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 26 Dec 2017 09:57:34 +0100 Subject: Refs #5376 @1h; Change the behaviour of the inputs on VehicleJourney#index We don't block user actions anymore. Instead, when the departure time is set prior to the arrival time, we shift the arrival time accordingly (and reversed when the user sets the arrival time) --- spec/javascript/vehicle_journeys/actions_spec.js | 81 +++++++ .../reducers/vehicleJourneys_spec.js | 269 +++++++++++++++++++++ .../reducers/vehicle_journeys_spec.js | 269 --------------------- 3 files changed, 350 insertions(+), 269 deletions(-) create mode 100644 spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js delete mode 100644 spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js (limited to 'spec/javascript') diff --git a/spec/javascript/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js index 74765a7ef..789507482 100644 --- a/spec/javascript/vehicle_journeys/actions_spec.js +++ b/spec/javascript/vehicle_journeys/actions_spec.js @@ -447,3 +447,84 @@ describe('when using select2 to unselect a company', () => { expect(actions.unselect2Company()).toEqual(expectedAction) }) }) + +describe('actions.adjustSchedule', () => { + set('time', () => { + return { + hour: 9, + minute: 30 + } + }) + context('when editing the departure time', () => { + set('action', () => { return { isDeparture: true } }) + context('with a positive delta', () => { + set('schedule', () => { + return { + departure_time: time, + arrival_time: time + } + }) + it('should do nothing', () => { + expect(actions.adjustSchedule(action, schedule)).toEqual(schedule) + }) + }), + context('with a delta < 0', () => { + set('departure_time', () => { + return { + hour: time.hour, + minute: time.minute - 1 + } + }) + set('schedule', () => { + return { + departure_time: departure_time, + arrival_time: time + } + }) + it('should adjust arrival time', () => { + let expected = { + departure_time: departure_time, + arrival_time: departure_time, + delta: 0 + } + expect(actions.adjustSchedule(action, schedule)).toEqual(expected) + }) + }) + }), + context('when editing the arrival time', () => { + set('action', () => { return { isDeparture: false } }) + context('with a positive delta', () => { + set('schedule', () => { + return { + departure_time: time, + arrival_time: time + } + }) + it('should do nothing', () => { + expect(actions.adjustSchedule(action, schedule)).toEqual(schedule) + }) + }), + context('with a delta < 0', () => { + set('arrival_time', () => { + return { + hour: time.hour, + minute: time.minute + 1 + } + }) + set('schedule', () => { + return { + departure_time: time, + arrival_time: arrival_time + } + }) + it('should adjust departure time', () => { + let expected = { + departure_time: arrival_time, + arrival_time: arrival_time, + delta: 0 + } + expect(actions.adjustSchedule(action, schedule)).toEqual(expected) + }) + }) + }) +}) diff --git a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js new file mode 100644 index 000000000..1c2cc1577 --- /dev/null +++ b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js @@ -0,0 +1,269 @@ +import vjReducer from '../../../../app/javascript/vehicle_journeys/reducers/vehicleJourneys' + +let state = [] +let stateModal = { + type: '', + modalProps: {}, + confirmModal: {} +} +let fakeFootnotes = [{ + id: 1, + code: 1, + label: "1" +},{ + id: 2, + code: 2, + label: "2" +}] + +let fakeTimeTables = [{ + published_journey_name: 'test 1', + objectid: '1' +},{ + published_journey_name: 'test 2', + objectid: '2' +},{ + published_journey_name: 'test 3', + objectid: '3' +}] +let fakeVJAS = [{ + delta : 627, + arrival_time : { + hour: '11', + minute: '55' + }, + departure_time : { + hour: '22', + minute: '22' + }, + stop_area_object_id : "FR:92024:ZDE:420553:STIF" +}] + +describe('vehicleJourneys reducer', () => { + beforeEach(()=>{ + state = [ + { + journey_pattern_id: 1, + published_journey_name: "vj1", + objectid: '11', + deletable: false, + selected: true, + footnotes: fakeFootnotes, + time_tables: fakeTimeTables, + vehicle_journey_at_stops: fakeVJAS + }, + { + journey_pattern_id: 2, + published_journey_name: "vj2", + objectid: '22', + selected: false, + deletable: false, + footnotes: fakeFootnotes, + time_tables: fakeTimeTables, + vehicle_journey_at_stops: fakeVJAS + } + ] + }) + + it('should return the initial state', () => { + expect( + vjReducer(undefined, {}) + ).toEqual([]) + }) + + + it('should handle ADD_VEHICLEJOURNEY', () => { + let pristineVjasList = [{ + delta : 0, + arrival_time : { + hour: '00', + minute: '00' + }, + departure_time : { + hour: '00', + minute: '00' + }, + stop_point_objectid: 'test', + stop_area_cityname: 'city', + dummy: true + }] + let fakeData = { + published_journey_name: {value: 'test'}, + published_journey_identifier: {value : ''} + } + let fakeSelectedJourneyPattern = {id: "1"} + let fakeSelectedCompany = {name: "ALBATRANS"} + expect( + vjReducer(state, { + type: 'ADD_VEHICLEJOURNEY', + data: fakeData, + selectedJourneyPattern: fakeSelectedJourneyPattern, + stopPointsList: [{object_id: 'test', city_name: 'city'}], + selectedCompany: fakeSelectedCompany + }) + ).toEqual([{ + journey_pattern: fakeSelectedJourneyPattern, + company: fakeSelectedCompany, + published_journey_name: 'test', + published_journey_identifier: '', + short_id: '', + objectid: '', + footnotes: [], + time_tables: [], + vehicle_journey_at_stops: pristineVjasList, + selected: false, + deletable: false, + transport_mode: 'undefined', + transport_submode: 'undefined' + }, ...state]) + }) + + it('should handle RECEIVE_VEHICLE_JOURNEYS', () => { + expect( + vjReducer(state, { + type: 'RECEIVE_VEHICLE_JOURNEYS', + json: state + }) + ).toEqual(state) + }) + + it('should handle UPDATE_TIME', () => { + const val = '33', subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true + let newVJAS = [{ + delta: 638, + arrival_time : { + hour: '11', + minute: '55' + }, + departure_time : { + hour: '22', + minute: '33' + }, + stop_area_object_id : "FR:92024:ZDE:420553:STIF" + }] + let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS}) + expect( + vjReducer(state, { + type: 'UPDATE_TIME', + val, + subIndex, + index, + timeUnit, + isDeparture, + isArrivalsToggled + }) + ).toEqual([newVJ, state[1]]) + }) + + it('should handle SELECT_VEHICLEJOURNEY', () => { + const index = 1 + const newVJ = Object.assign({}, state[1], {selected: true}) + expect( + vjReducer(state, { + type: 'SELECT_VEHICLEJOURNEY', + index + }) + ).toEqual([state[0], newVJ]) + }) + + it('should handle CANCEL_SELECTION', () => { + const index = 1 + const newVJ = Object.assign({}, state[0], {selected: false}) + expect( + vjReducer(state, { + type: 'CANCEL_SELECTION', + index + }) + ).toEqual([newVJ, state[1]]) + }) + + it('should handle DELETE_VEHICLEJOURNEYS', () => { + const newVJ = Object.assign({}, state[0], {deletable: true, selected: false}) + expect( + vjReducer(state, { + type: 'DELETE_VEHICLEJOURNEYS' + }) + ).toEqual([newVJ, state[1]]) + }) + + it('should handle SHIFT_VEHICLEJOURNEY', () => { + let newVJAS = [{ + delta: 627, + arrival_time : { + hour: '12', + minute: '00' + }, + departure_time : { + hour: '22', + minute: '27' + }, + stop_area_object_id : "FR:92024:ZDE:420553:STIF" + }] + let addtionalTime = 5 + let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS}) + expect( + vjReducer(state, { + type: 'SHIFT_VEHICLEJOURNEY', + addtionalTime + }) + ).toEqual([newVJ, state[1]]) + }) + + it('should handle DUPLICATE_VEHICLEJOURNEY', () => { + let newVJAS = [{ + delta: 627, + arrival_time : { + hour: '12', + minute: '01' + }, + departure_time : { + hour: '22', + minute: '28' + }, + stop_area_object_id : "FR:92024:ZDE:420553:STIF" + }] + let departureDelta = 1 + let addtionalTime = 5 + let duplicateNumber = 1 + + let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS, selected: false}) + newVJ.published_journey_name = state[0].published_journey_name + '-0' + delete newVJ['objectid'] + expect( + vjReducer(state, { + type: 'DUPLICATE_VEHICLEJOURNEY', + addtionalTime, + duplicateNumber, + departureDelta + }) + ).toEqual([state[0], newVJ, state[1]]) + }) + + it('should handle EDIT_VEHICLEJOURNEY', () => { + let fakeData = { + published_journey_name: {value : 'test'}, + published_journey_identifier: {value: 'test'} + } + let fakeSelectedCompany : {name : 'ALBATRANS'} + let newVJ = Object.assign({}, state[0], {company: fakeSelectedCompany, published_journey_name: fakeData.published_journey_name.value, published_journey_identifier: fakeData.published_journey_identifier.value}) + expect( + vjReducer(state, { + type: 'EDIT_VEHICLEJOURNEY', + data: fakeData + }) + ).toEqual([newVJ, state[1]]) + }) + + + it('should handle EDIT_VEHICLEJOURNEYS_TIMETABLES', () => { + let newState = JSON.parse(JSON.stringify(state)) + newState[0].time_tables = [fakeTimeTables[0]] + expect( + vjReducer(state, { + type: 'EDIT_VEHICLEJOURNEYS_TIMETABLES', + vehicleJourneys: state, + timetables: [fakeTimeTables[0]] + }) + ).toEqual(newState) + }) +}) diff --git a/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js deleted file mode 100644 index 1c2cc1577..000000000 --- a/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ /dev/null @@ -1,269 +0,0 @@ -import vjReducer from '../../../../app/javascript/vehicle_journeys/reducers/vehicleJourneys' - -let state = [] -let stateModal = { - type: '', - modalProps: {}, - confirmModal: {} -} -let fakeFootnotes = [{ - id: 1, - code: 1, - label: "1" -},{ - id: 2, - code: 2, - label: "2" -}] - -let fakeTimeTables = [{ - published_journey_name: 'test 1', - objectid: '1' -},{ - published_journey_name: 'test 2', - objectid: '2' -},{ - published_journey_name: 'test 3', - objectid: '3' -}] -let fakeVJAS = [{ - delta : 627, - arrival_time : { - hour: '11', - minute: '55' - }, - departure_time : { - hour: '22', - minute: '22' - }, - stop_area_object_id : "FR:92024:ZDE:420553:STIF" -}] - -describe('vehicleJourneys reducer', () => { - beforeEach(()=>{ - state = [ - { - journey_pattern_id: 1, - published_journey_name: "vj1", - objectid: '11', - deletable: false, - selected: true, - footnotes: fakeFootnotes, - time_tables: fakeTimeTables, - vehicle_journey_at_stops: fakeVJAS - }, - { - journey_pattern_id: 2, - published_journey_name: "vj2", - objectid: '22', - selected: false, - deletable: false, - footnotes: fakeFootnotes, - time_tables: fakeTimeTables, - vehicle_journey_at_stops: fakeVJAS - } - ] - }) - - it('should return the initial state', () => { - expect( - vjReducer(undefined, {}) - ).toEqual([]) - }) - - - it('should handle ADD_VEHICLEJOURNEY', () => { - let pristineVjasList = [{ - delta : 0, - arrival_time : { - hour: '00', - minute: '00' - }, - departure_time : { - hour: '00', - minute: '00' - }, - stop_point_objectid: 'test', - stop_area_cityname: 'city', - dummy: true - }] - let fakeData = { - published_journey_name: {value: 'test'}, - published_journey_identifier: {value : ''} - } - let fakeSelectedJourneyPattern = {id: "1"} - let fakeSelectedCompany = {name: "ALBATRANS"} - expect( - vjReducer(state, { - type: 'ADD_VEHICLEJOURNEY', - data: fakeData, - selectedJourneyPattern: fakeSelectedJourneyPattern, - stopPointsList: [{object_id: 'test', city_name: 'city'}], - selectedCompany: fakeSelectedCompany - }) - ).toEqual([{ - journey_pattern: fakeSelectedJourneyPattern, - company: fakeSelectedCompany, - published_journey_name: 'test', - published_journey_identifier: '', - short_id: '', - objectid: '', - footnotes: [], - time_tables: [], - vehicle_journey_at_stops: pristineVjasList, - selected: false, - deletable: false, - transport_mode: 'undefined', - transport_submode: 'undefined' - }, ...state]) - }) - - it('should handle RECEIVE_VEHICLE_JOURNEYS', () => { - expect( - vjReducer(state, { - type: 'RECEIVE_VEHICLE_JOURNEYS', - json: state - }) - ).toEqual(state) - }) - - it('should handle UPDATE_TIME', () => { - const val = '33', subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true - let newVJAS = [{ - delta: 638, - arrival_time : { - hour: '11', - minute: '55' - }, - departure_time : { - hour: '22', - minute: '33' - }, - stop_area_object_id : "FR:92024:ZDE:420553:STIF" - }] - let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS}) - expect( - vjReducer(state, { - type: 'UPDATE_TIME', - val, - subIndex, - index, - timeUnit, - isDeparture, - isArrivalsToggled - }) - ).toEqual([newVJ, state[1]]) - }) - - it('should handle SELECT_VEHICLEJOURNEY', () => { - const index = 1 - const newVJ = Object.assign({}, state[1], {selected: true}) - expect( - vjReducer(state, { - type: 'SELECT_VEHICLEJOURNEY', - index - }) - ).toEqual([state[0], newVJ]) - }) - - it('should handle CANCEL_SELECTION', () => { - const index = 1 - const newVJ = Object.assign({}, state[0], {selected: false}) - expect( - vjReducer(state, { - type: 'CANCEL_SELECTION', - index - }) - ).toEqual([newVJ, state[1]]) - }) - - it('should handle DELETE_VEHICLEJOURNEYS', () => { - const newVJ = Object.assign({}, state[0], {deletable: true, selected: false}) - expect( - vjReducer(state, { - type: 'DELETE_VEHICLEJOURNEYS' - }) - ).toEqual([newVJ, state[1]]) - }) - - it('should handle SHIFT_VEHICLEJOURNEY', () => { - let newVJAS = [{ - delta: 627, - arrival_time : { - hour: '12', - minute: '00' - }, - departure_time : { - hour: '22', - minute: '27' - }, - stop_area_object_id : "FR:92024:ZDE:420553:STIF" - }] - let addtionalTime = 5 - let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS}) - expect( - vjReducer(state, { - type: 'SHIFT_VEHICLEJOURNEY', - addtionalTime - }) - ).toEqual([newVJ, state[1]]) - }) - - it('should handle DUPLICATE_VEHICLEJOURNEY', () => { - let newVJAS = [{ - delta: 627, - arrival_time : { - hour: '12', - minute: '01' - }, - departure_time : { - hour: '22', - minute: '28' - }, - stop_area_object_id : "FR:92024:ZDE:420553:STIF" - }] - let departureDelta = 1 - let addtionalTime = 5 - let duplicateNumber = 1 - - let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS, selected: false}) - newVJ.published_journey_name = state[0].published_journey_name + '-0' - delete newVJ['objectid'] - expect( - vjReducer(state, { - type: 'DUPLICATE_VEHICLEJOURNEY', - addtionalTime, - duplicateNumber, - departureDelta - }) - ).toEqual([state[0], newVJ, state[1]]) - }) - - it('should handle EDIT_VEHICLEJOURNEY', () => { - let fakeData = { - published_journey_name: {value : 'test'}, - published_journey_identifier: {value: 'test'} - } - let fakeSelectedCompany : {name : 'ALBATRANS'} - let newVJ = Object.assign({}, state[0], {company: fakeSelectedCompany, published_journey_name: fakeData.published_journey_name.value, published_journey_identifier: fakeData.published_journey_identifier.value}) - expect( - vjReducer(state, { - type: 'EDIT_VEHICLEJOURNEY', - data: fakeData - }) - ).toEqual([newVJ, state[1]]) - }) - - - it('should handle EDIT_VEHICLEJOURNEYS_TIMETABLES', () => { - let newState = JSON.parse(JSON.stringify(state)) - newState[0].time_tables = [fakeTimeTables[0]] - expect( - vjReducer(state, { - type: 'EDIT_VEHICLEJOURNEYS_TIMETABLES', - vehicleJourneys: state, - timetables: [fakeTimeTables[0]] - }) - ).toEqual(newState) - }) -}) -- cgit v1.2.3 From 78e2d256f895c1014a3def5f2ef6509086755215 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 27 Dec 2017 09:10:56 +0100 Subject: Refs #5407 @4h; First UI implementation - Add most of the react code - And the specs where possible Still remains: - Link PurchaseWindows to VehicleJourneys in the model - Add an autocompletion endpoint --- spec/javascript/vehicle_journeys/actions_spec.js | 89 ++++++++++++++++++++++ .../vehicle_journeys/reducers/modal_spec.js | 82 ++++++++++++++++++++ .../reducers/vehicleJourneys_spec.js | 13 +++- 3 files changed, 183 insertions(+), 1 deletion(-) (limited to 'spec/javascript') diff --git a/spec/javascript/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js index 789507482..683b64505 100644 --- a/spec/javascript/vehicle_journeys/actions_spec.js +++ b/spec/javascript/vehicle_journeys/actions_spec.js @@ -209,6 +209,13 @@ describe('when clicking on edit notes modal', () => { expect(actions.openNotesEditModal(vehicleJourney)).toEqual(expectedAction) }) }) + + // ___ ___ ___ _____ _ _ ___ _____ ___ ___ + // | __/ _ \ / _ \_ _| \| |/ _ \_ _| __/ __| + // | _| (_) | (_) || | | .` | (_) || | | _|\__ \ + // |_| \___/ \___/ |_| |_|\_|\___/ |_| |___|___/ + // + describe('when clicking on a footnote button inside footnote modal', () => { it('should create an action to toggle this footnote', () => { const footnote = {}, isShown = true @@ -230,6 +237,13 @@ describe('when clicking on validate button inside footnote modal', () => { expect(actions.editVehicleJourneyNotes(footnotes)).toEqual(expectedAction) }) }) + + // _____ ___ __ __ ___ _____ _ ___ _ ___ ___ + // |_ _|_ _| \/ | __|_ _/_\ | _ ) | | __/ __| + // | | | || |\/| | _| | |/ _ \| _ \ |__| _|\__ \ + // |_| |___|_| |_|___| |_/_/ \_\___/____|___|___/ + // + describe('when clicking on calendar button in toolbox', () => { it('should create an action to open calendar modal', () => { const vehicleJourneys = [] @@ -288,6 +302,81 @@ describe('when using select2 to pick a timetable', () => { expect(actions.selectTTCalendarsModal(selectedTT)).toEqual(expectedAction) }) }) + + // ___ _ _ ___ ___ _ _ _ ___ ___ + // | _ \ | | | _ \/ __| || | /_\ / __| __| + // | _/ |_| | / (__| __ |/ _ \\__ \ _| + // |_| \___/|_|_\\___|_||_/_/_\_\___/___|__ + // \ \ / /_ _| \| | \ / _ \ \ / / __| + // \ \/\/ / | || .` | |) | (_) \ \/\/ /\__ \ + // \_/\_/ |___|_|\_|___/ \___/ \_/\_/ |___/ + // + +describe('when clicking on purchase window button in toolbox', () => { + it('should create an action to open purchase window modal', () => { + const vehicleJourneys = [] + const expectedAction = { + type: 'EDIT_PURCHASE_WINDOWS_VEHICLEJOURNEY_MODAL', + vehicleJourneys + } + expect(actions.openPurchaseWindowsEditModal(vehicleJourneys)).toEqual(expectedAction) + }) +}) +describe('when clicking on delete button next to a purchase window inside modal', () => { + it('should create an action to delete purchase window from selected vehicle journeys', () => { + const purchaseWindow = {} + const expectedAction = { + type: 'DELETE_PURCHASE_WINDOW_MODAL', + purchaseWindow + } + expect(actions.deletePurchaseWindowsModal(purchaseWindow)).toEqual(expectedAction) + }) +}) +describe('when clicking on validate button inside purchase windows modal', () => { + it('should create an action to update vj purchase windows', () => { + const vehicleJourneys = [] + const purchase_windows = [] + const expectedAction = { + type: 'EDIT_VEHICLEJOURNEYS_PURCHASE_WINDOWS', + vehicleJourneys, + purchase_windows + } + expect(actions.editVehicleJourneyPurchaseWindows(vehicleJourneys, timetables)).toEqual(expectedAction) + }) +}) +describe('when clicking on add button inside purchase windows modal', () => { + it('should create an action to add the selected purchase window to preselected vjs', () => { + const expectedAction = { + type: 'ADD_SELECTED_PURCHASE_WINDOW', + } + expect(actions.addSelectedPurchaseWindow()).toEqual(expectedAction) + }) +}) +describe('when using select2 to pick a purchase window', () => { + it('should create an action to select a purchase window inside modal', () => { + let selectedTT = { + id: 1, + objectid: 2, + comment: 'test', + } + const expectedAction = { + type: 'SELECT_PURCHASE_WINDOW_MODAL', + selectedItem:{ + id: selectedTT.id, + objectid: selectedTT.objectid, + comment: selectedTT.comment, + } + } + expect(actions.selectPurchaseWindowsModal(selectedTT)).toEqual(expectedAction) + }) +}) + + // ___ ___ _ _____ ___ ___ ___ + // | __|_ _| ||_ _| __| _ \/ __| + // | _| | || |__| | | _|| /\__ \ + // |_| |___|____|_| |___|_|_\|___/ + // + describe('when clicking on reset button inside query filters', () => { it('should create an action to reset the query filters', () => { const expectedAction = { diff --git a/spec/javascript/vehicle_journeys/reducers/modal_spec.js b/spec/javascript/vehicle_journeys/reducers/modal_spec.js index 69de9168b..ea8a002d2 100644 --- a/spec/javascript/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/modal_spec.js @@ -91,6 +91,12 @@ describe('modal reducer', () => { ).toEqual(newState) }) + // _____ ___ __ __ ___ _____ _ ___ _ ___ ___ + // |_ _|_ _| \/ | __|_ _/_\ | _ ) | | __/ __| + // | | | || |\/| | _| | |/ _ \| _ \ |__| _|\__ \ + // |_| |___|_| |_|___| |_/_/ \_\___/____|___|___/ + // + it('should handle EDIT_CALENDARS_VEHICLEJOURNEY_MODAL', () => { let vehicleJourneys = [] let modalPropsResult = { @@ -158,6 +164,82 @@ describe('modal reducer', () => { ).toEqual(newState) }) + // ___ _ _ ___ ___ _ _ _ ___ ___ + // | _ \ | | | _ \/ __| || | /_\ / __| __| + // | _/ |_| | / (__| __ |/ _ \\__ \ _| + // |_| \___/|_|_\\___|_||_/_/_\_\___/___|__ + // \ \ / /_ _| \| | \ / _ \ \ / / __| + // \ \/\/ / | || .` | |) | (_) \ \/\/ /\__ \ + // \_/\_/ |___|_|\_|___/ \___/ \_/\_/ |___/ + // + + it('should handle EDIT_PURCHASE_WINDOWS_VEHICLEJOURNEY_MODAL', () => { + let vehicleJourneys = [] + let modalPropsResult = { + vehicleJourneys: [], + purchase_windows: [] + } + expect( + modalReducer(state, { + type: 'EDIT_PURCHASE_WINDOWS_VEHICLEJOURNEY_MODAL', + vehicleJourneys + }) + ).toEqual(Object.assign({}, state, {type: 'purchase_windows_edit', modalProps: modalPropsResult})) + }) + + it('should handle SELECT_PURCHASE_WINDOW_MODAL', () => { + let newModalProps = {selectedPurchaseWindow : {id: 1}} + expect( + modalReducer(state, { + type: 'SELECT_PURCHASE_WINDOW_MODAL', + selectedItem: {id: 1} + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) + + it('should handle ADD_SELECTED_PURCHASE_WINDOW', () => { + let fakeWindows = [{'test': 'test'}, {'test 2': 'test 2'}] + let newWindows = [{'test': 'test'}, {'test 2': 'test 2'}, {'add': 'add'}] + let fakeVehicleJourneys= [{purchase_windows: fakeWindows}, {purchase_windows: newWindows}] + state.modalProps.vehicleJourneys = fakeVehicleJourneys + state.modalProps.purchase_windows = fakeWindows + state.modalProps.selectedPurchaseWindow = {'add': 'add'} + let newState = { + type: '', + modalProps:{ + vehicleJourneys: fakeVehicleJourneys, + purchase_windows: [{'test': 'test'},{'test 2': 'test 2'},{'add': 'add'}], + selectedPurchaseWindow: {'add': 'add'} + }, + confirmModal: {} + } + expect( + modalReducer(state, { + type: 'ADD_SELECTED_PURCHASE_WINDOW', + }) + ).toEqual(newState) + }) + + it('should handle DELETE_PURCHASE_WINDOW_MODAL', () => { + let deletableWindow = {'delete': 'delete'} + let fakeWindows = [{'test': 'test'}, {'test 2': 'test 2'}, deletableWindow] + let newWindows = [{'test': 'test'}, {'test 2': 'test 2'}] + let fakeVehicleJourneys= [{purchase_windows: fakeWindows}, {purchase_windows: newWindows}] + state.modalProps = Object.assign({}, state.modalProps,{vehicleJourneys : fakeVehicleJourneys, purchase_windows: fakeWindows }) + let newState = { + // for the sake of the test, no need to specify the type + type: '', + modalProps:{vehicleJourneys: [{purchase_windows: newWindows},{purchase_windows: newWindows}], purchase_windows: newWindows}, + confirmModal: {} + } + expect( + modalReducer(state, { + type: 'DELETE_PURCHASE_WINDOW_MODAL', + purchaseWindow: deletableWindow + }) + ).toEqual(newState) + }) + it('should handle SELECT_CP_EDIT_MODAL', () => { let newModalProps = {selectedCompany : {name: 'ALBATRANS'}} expect( diff --git a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js index 1c2cc1577..c834de1f6 100644 --- a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js @@ -254,7 +254,6 @@ describe('vehicleJourneys reducer', () => { ).toEqual([newVJ, state[1]]) }) - it('should handle EDIT_VEHICLEJOURNEYS_TIMETABLES', () => { let newState = JSON.parse(JSON.stringify(state)) newState[0].time_tables = [fakeTimeTables[0]] @@ -266,4 +265,16 @@ describe('vehicleJourneys reducer', () => { }) ).toEqual(newState) }) + + it('should handle EDIT_VEHICLEJOURNEYS_PURCHASE_WINDOWS', () => { + let newState = JSON.parse(JSON.stringify(state)) + newState[0].purchase_windows = [fakeTimeTables[0]] + expect( + vjReducer(state, { + type: 'EDIT_VEHICLEJOURNEYS_PURCHASE_WINDOWS', + vehicleJourneys: state, + purchase_windows: [fakeTimeTables[0]] + }) + ).toEqual(newState) + }) }) -- cgit v1.2.3 From bd5f7f02e62b397f4c2ddb71f1878ad0c6aba1be Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 27 Dec 2017 16:08:48 +0100 Subject: Refs #5407; Fix CI --- spec/javascript/vehicle_journeys/actions_spec.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'spec/javascript') diff --git a/spec/javascript/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js index 683b64505..3af19ebc3 100644 --- a/spec/javascript/vehicle_journeys/actions_spec.js +++ b/spec/javascript/vehicle_journeys/actions_spec.js @@ -341,7 +341,7 @@ describe('when clicking on validate button inside purchase windows modal', () => vehicleJourneys, purchase_windows } - expect(actions.editVehicleJourneyPurchaseWindows(vehicleJourneys, timetables)).toEqual(expectedAction) + expect(actions.editVehicleJourneyPurchaseWindows(vehicleJourneys, purchase_windows)).toEqual(expectedAction) }) }) describe('when clicking on add button inside purchase windows modal', () => { @@ -357,14 +357,16 @@ describe('when using select2 to pick a purchase window', () => { let selectedTT = { id: 1, objectid: 2, - comment: 'test', + name: 'test', + color: 'color', } const expectedAction = { type: 'SELECT_PURCHASE_WINDOW_MODAL', selectedItem:{ id: selectedTT.id, objectid: selectedTT.objectid, - comment: selectedTT.comment, + name: selectedTT.name, + color: "color" } } expect(actions.selectPurchaseWindowsModal(selectedTT)).toEqual(expectedAction) -- cgit v1.2.3 From 64920d79cdaa358bfe89250b2c66a78779bfc837 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Thu, 28 Dec 2017 09:13:50 +0100 Subject: Fixes vehicleJourneys reducer spec. Refs #5407 --- spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/javascript') diff --git a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js index c834de1f6..28de241ee 100644 --- a/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js @@ -110,6 +110,7 @@ describe('vehicleJourneys reducer', () => { objectid: '', footnotes: [], time_tables: [], + purchase_windows: [], vehicle_journey_at_stops: pristineVjasList, selected: false, deletable: false, -- cgit v1.2.3 From 09dcd818d83a1dddef4e4f2e3fd800fb228c51c0 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 28 Dec 2017 11:22:41 +0100 Subject: Refs #5435 @0.5h; Fix EditModal validation in VehicleJourneys#index --- spec/javascript/vehicle_journeys/actions_spec.js | 58 ++++++++++++++++++++---- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'spec/javascript') diff --git a/spec/javascript/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js index 3af19ebc3..2f1daf0da 100644 --- a/spec/javascript/vehicle_journeys/actions_spec.js +++ b/spec/javascript/vehicle_journeys/actions_spec.js @@ -174,15 +174,55 @@ describe('when clicking on validate button inside shifting modal', () => { }) }) describe('when clicking on validate button inside editing modal', () => { - it('should create an action to update a vehiclejourney', () => { - const data = {} - const selectedCompany = {} - const expectedAction = { - type: 'EDIT_VEHICLEJOURNEY', - data, - selectedCompany - } - expect(actions.editVehicleJourney(data, selectedCompany)).toEqual(expectedAction) + context("with invalid data", () => { + it('should not validate the data', () => { + const data = { + foo: { + validity: { valid: false } + }, + bar: { + validity: { valid: true } + } + } + + expect(actions.validateFields(data)).toBeFalsy + }) + }) + + context("with data not needing validation", () => { + it('should validate the data', () => { + const data = { + foo: {} + } + + expect(actions.validateFields(data)).toBeTruthy + }) + }) + context("with valid data", () => { + it('should validate the data', () => { + const data = { + foo: { + validity: { valid: true } + }, + bar: { + validity: { valid: true } + } + } + + expect(actions.validateFields(data)).toBeTruthy + }) + }) + context("once the data has been validated", () => { + it('should create an action to update a vehiclejourney', () => { + const data = {} + const selectedCompany = {} + const expectedAction = { + type: 'EDIT_VEHICLEJOURNEY', + data, + selectedCompany + } + expect(actions.editVehicleJourney(data, selectedCompany)).toEqual(expectedAction) + }) }) }) describe('when clicking on validate button inside duplicating modal', () => { -- cgit v1.2.3 From a5ac3d72be252e8001b5d823d6c050cf810094f3 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 28 Dec 2017 11:57:12 +0100 Subject: Refs #5435 @0.5h; Fix Company select in VehicleJourney edition modal --- spec/javascript/vehicle_journeys/reducers/modal_spec.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'spec/javascript') diff --git a/spec/javascript/vehicle_journeys/reducers/modal_spec.js b/spec/javascript/vehicle_journeys/reducers/modal_spec.js index ea8a002d2..ee50f091b 100644 --- a/spec/javascript/vehicle_journeys/reducers/modal_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/modal_spec.js @@ -241,13 +241,12 @@ describe('modal reducer', () => { }) it('should handle SELECT_CP_EDIT_MODAL', () => { - let newModalProps = {selectedCompany : {name: 'ALBATRANS'}} expect( modalReducer(state, { type: 'SELECT_CP_EDIT_MODAL', selectedItem: {name: 'ALBATRANS'} - }) - ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }).modalProps.vehicleJourney.company + ).toEqual({name: 'ALBATRANS'}) }) it('should handle UNSELECT_CP_EDIT_MODAL', () => { @@ -255,7 +254,7 @@ describe('modal reducer', () => { expect( modalReducer(state, { type: 'UNSELECT_CP_EDIT_MODAL' - }) - ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }).modalProps.vehicleJourney.company + ).toBe(undefined) }) }) -- cgit v1.2.3