diff options
| author | Luc Donnet | 2018-01-03 11:57:42 +0100 |
|---|---|---|
| committer | Luc Donnet | 2018-01-03 11:57:42 +0100 |
| commit | 7cce4762c11e7d1e78433f6f88d2e12928c398dc (patch) | |
| tree | 3084d95692a70f9c5d5a842aae6f4ec0ea07a1c3 /spec/javascript | |
| parent | 6497b23e18385121974f6cbf56d48caf897e69b1 (diff) | |
| parent | 414d0f6c4dd992696354757c4ae700952a7e4dd9 (diff) | |
| download | chouette-core-7cce4762c11e7d1e78433f6f88d2e12928c398dc.tar.bz2 | |
Merge branch 'master' into 5024-prevent-duplicate-referentials-from-being-created-during-parallel-db-transactions--rb201711271659
Diffstat (limited to 'spec/javascript')
| -rw-r--r-- | spec/javascript/routes/reducers/stop_points_spec.js | 588 | ||||
| -rw-r--r-- | spec/javascript/vehicle_journeys/actions_spec.js | 230 | ||||
| -rw-r--r-- | spec/javascript/vehicle_journeys/reducers/modal_spec.js | 91 | ||||
| -rw-r--r-- | spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js (renamed from spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js) | 15 |
4 files changed, 468 insertions, 456 deletions
diff --git a/spec/javascript/routes/reducers/stop_points_spec.js b/spec/javascript/routes/reducers/stop_points_spec.js index b375cdc2c..124618f9d 100644 --- a/spec/javascript/routes/reducers/stop_points_spec.js +++ b/spec/javascript/routes/reducers/stop_points_spec.js @@ -1,7 +1,17 @@ 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 +20,47 @@ 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 +69,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, {index: 0}), update_stop_point(stop_point_1, {index: 1}), 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, {index: 0}), update_stop_point(stop_point_1, {index: 1}), 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 + ) }) diff --git a/spec/javascript/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js index 74765a7ef..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', () => { @@ -209,6 +249,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 +277,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 +342,83 @@ 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, purchase_windows)).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, + name: 'test', + color: 'color', + } + const expectedAction = { + type: 'SELECT_PURCHASE_WINDOW_MODAL', + selectedItem:{ + id: selectedTT.id, + objectid: selectedTT.objectid, + name: selectedTT.name, + color: "color" + } + } + 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 = { @@ -447,3 +578,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/modal_spec.js b/spec/javascript/vehicle_journeys/reducers/modal_spec.js index 69de9168b..ee50f091b 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,14 +164,89 @@ 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( 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', () => { @@ -173,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) }) }) diff --git a/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js index c02ab3398..28de241ee 100644 --- a/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js +++ b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js @@ -106,9 +106,11 @@ describe('vehicleJourneys reducer', () => { company: fakeSelectedCompany, published_journey_name: 'test', published_journey_identifier: '', + short_id: '', objectid: '', footnotes: [], time_tables: [], + purchase_windows: [], vehicle_journey_at_stops: pristineVjasList, selected: false, deletable: false, @@ -253,7 +255,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]] @@ -265,4 +266,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) + }) }) |
