diff options
| author | Alban Peignier | 2018-01-02 09:47:55 +0100 |
|---|---|---|
| committer | GitHub | 2018-01-02 09:47:55 +0100 |
| commit | 2d904d7394854ec2cdf1320c06364dbb3e1c6394 (patch) | |
| tree | 7eb87364b429bda8d79f880a4b422ff294b58d47 | |
| parent | d54e2bb4997d4d283ad81e86c2d00ae349b2fa05 (diff) | |
| parent | 60afea86d7644e513d3359cfdaa9c2fe201ad68e (diff) | |
| download | chouette-core-2d904d7394854ec2cdf1320c06364dbb3e1c6394.tar.bz2 | |
Merge pull request #189 from af83/5435-fix-journey-edition-from-editor
Fix journey edition from editor. Refs #5435
6 files changed, 73 insertions, 40 deletions
diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js index 8dcae271b..40c8006f1 100644 --- a/app/javascript/vehicle_journeys/actions/index.js +++ b/app/javascript/vehicle_journeys/actions/index.js @@ -188,26 +188,18 @@ const actions = { resetValidation: (target) => { $(target).parent().removeClass('has-error').children('.help-block').remove() }, - validateFields : (...fields) => { - const test = [] - - Object.keys(fields).map(function(key) { - test.push(fields[key].validity.valid) + validateFields : (fields) => { + let valid = true + Object.keys(fields).forEach((key) => { + let field = fields[key] + if(field.validity && !field.validity.valid){ + valid = false + $(field).parent().addClass('has-error').children('.help-block').remove() + $(field).parent().append("<span class='small help-block'>" + field.validationMessage + "</span>") + } }) - if(test.indexOf(false) >= 0) { - // Form is invalid - test.map(function(item, i) { - if(item == false) { - const k = Object.keys(fields)[i] - $(fields[k]).parent().addClass('has-error').children('.help-block').remove() - $(fields[k]).parent().append("<span class='small help-block'>" + fields[k].validationMessage + "</span>") - } - }) - return false - } else { - // Form is valid - return true - } + + return valid }, toggleArrivals : () => ({ type: 'TOGGLE_ARRIVALS', @@ -373,7 +365,7 @@ const actions = { selected: false, published_journey_name: val.published_journey_name || 'non renseigné', published_journey_identifier: val.published_journey_identifier || 'non renseigné', - company: val.company || 'non renseigné', + company: val.company || {name: 'non renseigné'}, transport_mode: val.route.line.transport_mode || 'undefined', transport_submode: val.route.line.transport_submode || 'undefined' }) diff --git a/app/javascript/vehicle_journeys/components/VehicleJourney.js b/app/javascript/vehicle_journeys/components/VehicleJourney.js index 30b329896..5f6281487 100644 --- a/app/javascript/vehicle_journeys/components/VehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/VehicleJourney.js @@ -64,7 +64,7 @@ export default class VehicleJourney extends Component { <div className='th' onClick={(e) => - ($(e.target).parents("a").length == 0) && this.props.editMode && this.props.onSelectVehicleJourney(this.props.index) + ($(e.target).parents("a").length == 0) && this.props.onSelectVehicleJourney(this.props.index) } > <div className='strong mb-xs'>{this.props.value.short_id || '-'}</div> diff --git a/app/javascript/vehicle_journeys/components/tools/CreateModal.js b/app/javascript/vehicle_journeys/components/tools/CreateModal.js index 33873219c..cd593cdff 100644 --- a/app/javascript/vehicle_journeys/components/tools/CreateModal.js +++ b/app/javascript/vehicle_journeys/components/tools/CreateModal.js @@ -61,7 +61,7 @@ export default class CreateModal extends Component { <div className='form-group'> <label className='control-label'>Nom du transporteur</label> <CompanySelect2 - company = {undefined} + company = {this.props.modal.modalProps.vehicleJourney && this.props.modal.modalProps.vehicleJourney.company || undefined} onSelect2Company = {(e) => this.props.onSelect2Company(e)} /> </div> @@ -130,4 +130,4 @@ CreateModal.propTypes = { onAddVehicleJourney: PropTypes.func.isRequired, onSelect2JourneyPattern: PropTypes.func.isRequired, disabled: PropTypes.bool.isRequired -}
\ No newline at end of file +} diff --git a/app/javascript/vehicle_journeys/reducers/modal.js b/app/javascript/vehicle_journeys/reducers/modal.js index 862e27e1b..eae3314e8 100644 --- a/app/javascript/vehicle_journeys/reducers/modal.js +++ b/app/javascript/vehicle_journeys/reducers/modal.js @@ -1,6 +1,6 @@ import _ from 'lodash' -let vehicleJourneysModal, newModalProps +let vehicleJourneysModal, newModalProps, vehicleJourney export default function modal(state = {}, action) { switch (action.type) { @@ -74,10 +74,12 @@ export default function modal(state = {}, action) { confirmModal: {} } case 'SELECT_CP_EDIT_MODAL': - newModalProps = _.assign({}, state.modalProps, {selectedCompany : action.selectedItem}) + vehicleJourney = _.assign({}, state.modalProps.vehicleJourney, {company: action.selectedItem}) + newModalProps = _.assign({}, state.modalProps, {vehicleJourney}) return _.assign({}, state, {modalProps: newModalProps}) case 'UNSELECT_CP_EDIT_MODAL': - newModalProps = _.assign({}, state.modalProps, {selectedCompany : undefined}) + vehicleJourney = _.assign({}, state.modalProps.vehicleJourney, {company: undefined}) + newModalProps = _.assign({}, state.modalProps, {vehicleJourney}) return _.assign({}, state, {modalProps: newModalProps}) case 'SELECT_TT_CALENDAR_MODAL': newModalProps = _.assign({}, state.modalProps, {selectedTimetable : action.selectedItem}) 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', () => { 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) }) }) |
