diff options
Diffstat (limited to 'spec/javascript/journey_patterns')
6 files changed, 503 insertions, 3 deletions
diff --git a/spec/javascript/journey_patterns/actions_spec.js b/spec/javascript/journey_patterns/actions_spec.js index 2542fa2f4..60d6d88bb 100644 --- a/spec/javascript/journey_patterns/actions_spec.js +++ b/spec/javascript/journey_patterns/actions_spec.js @@ -112,6 +112,22 @@ describe('when clicking on a journey pattern delete button', () => { expect(actions.deleteJourneyPattern(index)).toEqual(expectedAction) }) }) +describe('when changing on a journey pattern costs', () => { + it('should create an action to update journey pattern', () => { + const index = 1 + const costs = { + "1-2": { + distance: 1 + } + } + const expectedAction = { + type: 'UPDATE_JOURNEYPATTERN_COSTS', + index, + costs + } + expect(actions.updateJourneyPatternCosts(index, costs)).toEqual(expectedAction) + }) +}) describe('when clicking on validate button inside edit modal', () => { it('should create an action to save journey pattern modifications', () => { const index = 1 diff --git a/spec/javascript/journey_patterns/components/JourneyPattern_spec.js b/spec/javascript/journey_patterns/components/JourneyPattern_spec.js new file mode 100644 index 000000000..0da75ad47 --- /dev/null +++ b/spec/javascript/journey_patterns/components/JourneyPattern_spec.js @@ -0,0 +1,63 @@ +import React, { Component } from 'react' +import JourneyPattern from '../../../../app/javascript/journey_patterns/components/JourneyPattern' +import renderer from 'react-test-renderer' + +describe('the edit button', () => { + set('policy', () => { + return {} + }) + set('features', () => { + return [] + }) + set('editMode', () => { + return false + }) + set('component', () => { + let props = { + status: { + policy: policy, + features: features + }, + onCheckboxChange: ()=>{}, + onDeleteJourneyPattern: ()=>{}, + onOpenEditModal: ()=>{}, + journeyPatterns: {}, + value: { + stop_points: [] + }, + index: 0, + editMode: editMode + } + let list = renderer.create( + <JourneyPattern + status={props.status} + journeyPatterns={props.journeyPatterns} + value={props.value} + index={props.index} + onCheckboxChange={props.onCheckboxChange} + onDeleteJourneyPattern={props.onDeleteJourneyPattern} + onOpenEditModal={props.onOpenEditModal} + editMode={props.editMode} + /> + ) + + return list + }) + + + it('should display the show link', () => { + expect(component.toJSON()).toMatchSnapshot() + expect(component.root.findByProps({"data-target": "#JourneyPatternModal"})._fiber.stateNode.children[0].text).toEqual("Consulter") + }) + + context('in edit mode', () => { + set('editMode', () => { + return true + }) + + it('should display the edit link', () => { + expect(component.toJSON()).toMatchSnapshot() + expect(component.root.findByProps({"data-target": "#JourneyPatternModal"})._fiber.stateNode.children[0].text).toEqual("Editer") + }) + }) +}) diff --git a/spec/javascript/journey_patterns/components/JourneyPatterns_spec.js b/spec/javascript/journey_patterns/components/JourneyPatterns_spec.js new file mode 100644 index 000000000..0c852deff --- /dev/null +++ b/spec/javascript/journey_patterns/components/JourneyPatterns_spec.js @@ -0,0 +1,77 @@ +import React, { Component } from 'react' +import JourneyPatterns from '../../../../app/javascript/journey_patterns/components/JourneyPatterns' +import renderer from 'react-test-renderer' + +describe('stopPointHeader', () => { + set('features', () => { + return {} + }) + set('component', () => { + let props = { + status: { + features: features + }, + onCheckboxChange: ()=>{}, + onLoadFirstPage: ()=>{}, + onOpenEditModal: ()=>{}, + stopPointsList: [stop_point, same_city_stop_point, other_country_stop_point], + journeyPatterns: [] + } + let list = renderer.create( + <JourneyPatterns + status={props.status} + journeyPatterns={props.journeyPatterns} + stopPointsList={props.stopPointsList} + onCheckboxChange={props.onCheckboxChange} + onLoadFirstPage={props.onLoadFirstPage} + onOpenEditModal={props.onOpenEditModal} + /> + ).toJSON() + + return list + }) + + set('stop_point', () => { + return { + name: "Stop point", + city_name: "City Name", + zip_code: "12345", + country_code: "FR", + country_name: "france", + object_id: "sp-FR" + } + }) + + set('same_city_stop_point', () => { + return { + name: "Antother stop point", + city_name: stop_point.city_name, + zip_code: stop_point.zip_code, + country_code: stop_point.country_code, + country_name: stop_point.country_name, + object_id: stop_point.object_id + "-2" + } + }) + + set('other_country_stop_point', () => { + return { + name: "Antother stop point", + city_name: "New York", + zip_code: "232323", + country_code: "US", + country_name: "USA", + object_id: "sp-USA" + } + }) + it('should display the city name', () => { + expect(component).toMatchSnapshot() + }) + context('with the "long_distance_routes" feature', () => { + set('features', () => { + return { long_distance_routes: true } + }) + it('should display the country name', () => { + expect(component).toMatchSnapshot() + }) + }) +}) diff --git a/spec/javascript/journey_patterns/components/__snapshots__/JourneyPattern_spec.js.snap b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPattern_spec.js.snap new file mode 100644 index 000000000..0bedd8d69 --- /dev/null +++ b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPattern_spec.js.snap @@ -0,0 +1,143 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`the edit button in edit mode should display the edit link 1`] = ` +<div + className="t2e-item to_record" +> + <div + className="th" + > + <div + className="strong mb-xs" + > + - + </div> + <div /> + <div> + 0 + arrêt(s) + </div> + <div + className="btn-group" + > + <div + className="btn dropdown-toggle" + data-toggle="dropdown" + > + <span + className="fa fa-cog" + /> + </div> + <ul + className="dropdown-menu" + > + <li> + <button + data-target="#JourneyPatternModal" + data-toggle="modal" + onClick={[Function]} + type="button" + > + Editer + </button> + </li> + <li + className="disabled" + > + <a + href="blank/vehicle_journeys?jp=undefined" + > + Horaires des courses + </a> + </li> + <li + className="delete-action disabled" + > + <button + className="disabled" + disabled={true} + onClick={[Function]} + type="button" + > + <span + className="fa fa-trash" + /> + Supprimer + </button> + </li> + </ul> + </div> + </div> +</div> +`; + +exports[`the edit button should display the show link 1`] = ` +<div + className="t2e-item to_record" +> + <div + className="th" + > + <div + className="strong mb-xs" + > + - + </div> + <div /> + <div> + 0 + arrêt(s) + </div> + <div + className="btn-group" + > + <div + className="btn dropdown-toggle" + data-toggle="dropdown" + > + <span + className="fa fa-cog" + /> + </div> + <ul + className="dropdown-menu" + > + <li> + <button + data-target="#JourneyPatternModal" + data-toggle="modal" + onClick={[Function]} + type="button" + > + Consulter + </button> + </li> + <li + className="disabled" + > + <a + href="blank/vehicle_journeys?jp=undefined" + > + Horaires des courses + </a> + </li> + <li + className="delete-action disabled" + > + <button + className="disabled" + disabled={true} + onClick={[Function]} + type="button" + > + <span + className="fa fa-trash" + /> + Supprimer + </button> + </li> + </ul> + </div> + </div> +</div> +`; diff --git a/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap new file mode 100644 index 000000000..a332e7d80 --- /dev/null +++ b/spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap @@ -0,0 +1,169 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`stopPointHeader should display the city name 1`] = ` +<div + className="row" +> + <div + className="col-lg-12" + > + <div + className="table table-2entries mt-sm mb-sm no_result" + > + <div + className="t2e-head w20" + > + <div + className="th" + > + <div + className="strong mb-xs" + > + ID Mission + </div> + <div> + Code mission + </div> + <div> + Nb arrêts + </div> + </div> + <div + className="td" + > + <div + className="headlined" + data-headline="City Name" + title="City Name (12345)" + > + <span> + <span> + Stop point + </span> + </span> + </div> + </div> + <div + className="td" + > + <div + className="" + data-headline="" + title="City Name (12345)" + > + <span> + <span> + Antother stop point + </span> + </span> + </div> + </div> + <div + className="td" + > + <div + className="headlined" + data-headline="New York" + title="New York (232323)" + > + <span> + <span> + Antother stop point + </span> + </span> + </div> + </div> + </div> + <div + className="t2e-item-list w80" + > + <div /> + </div> + </div> + </div> +</div> +`; + +exports[`stopPointHeader with the "long_distance_routes" feature should display the country name 1`] = ` +<div + className="row" +> + <div + className="col-lg-12" + > + <div + className="table table-2entries mt-sm mb-sm no_result" + > + <div + className="t2e-head w20" + > + <div + className="th" + > + <div + className="strong mb-xs" + > + ID Mission + </div> + <div> + Code mission + </div> + <div> + Nb arrêts + </div> + </div> + <div + className="td" + > + <div + className="headlined" + data-headline="france" + title="City Name (12345)" + > + <span> + <span> + Stop point + </span> + </span> + </div> + </div> + <div + className="td" + > + <div + className="" + data-headline="" + title="City Name (12345)" + > + <span> + <span> + Antother stop point + </span> + </span> + </div> + </div> + <div + className="td" + > + <div + className="headlined" + data-headline="USA" + title="New York (232323)" + > + <span> + <span> + Antother stop point + </span> + </span> + </div> + </div> + </div> + <div + className="t2e-item-list w80" + > + <div /> + </div> + </div> + </div> +</div> +`; diff --git a/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js index 24780ab5a..bfa87d24a 100644 --- a/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js +++ b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js @@ -47,7 +47,10 @@ describe('journeyPatterns reducer', () => { object_id : 'o1', published_name: 'M1', registration_number: '', - stop_points: fakeStopPoints + stop_points: fakeStopPoints, + costs: { + + } }, { deletable: false, @@ -55,7 +58,13 @@ describe('journeyPatterns reducer', () => { object_id : 'o2', published_name: 'M2', registration_number: '', - stop_points: fakeStopPoints + stop_points: fakeStopPoints, + costs: { + "1-2": { + distance: 0, + time: 10, + } + } } ] }) @@ -83,7 +92,8 @@ describe('journeyPatterns reducer', () => { published_name: 'M3', registration_number: '', deletable: false, - stop_points: stopPoints + stop_points: stopPoints, + costs: {} }, ...state]) }) @@ -100,6 +110,28 @@ describe('journeyPatterns reducer', () => { ).toEqual([newState, state[1]]) }) + it('should handle UPDATE_JOURNEYPATTERN_COSTS', () => { + const costs = { + "1-2": { + distance: 1 + } + } + const new_costs = { + "1-2": { + distance: 1, + time: 10, + } + } + const new_state = Object.assign({}, state[1], {costs: new_costs}) + expect( + jpReducer(state, { + type: 'UPDATE_JOURNEYPATTERN_COSTS', + index: 1, + costs + }) + ).toEqual([state[0], new_state]) + }) + it('should handle DELETE_JOURNEYPATTERN', () => { expect( jpReducer(state, { |
