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