aboutsummaryrefslogtreecommitdiffstats
path: root/spec/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascript')
-rw-r--r--spec/javascript/journey_patterns/actions_spec.js16
-rw-r--r--spec/javascript/journey_patterns/components/JourneyPattern_spec.js63
-rw-r--r--spec/javascript/journey_patterns/components/JourneyPatterns_spec.js77
-rw-r--r--spec/javascript/journey_patterns/components/__snapshots__/JourneyPattern_spec.js.snap143
-rw-r--r--spec/javascript/journey_patterns/components/__snapshots__/JourneyPatterns_spec.js.snap169
-rw-r--r--spec/javascript/journey_patterns/reducers/journey_patterns_spec.js38
-rw-r--r--spec/javascript/preprocessor.js15
-rw-r--r--spec/javascript/routes/reducers/stop_points_spec.js588
-rw-r--r--spec/javascript/time_table/reducers/timetable_spec.js3
-rw-r--r--spec/javascript/vehicle_journeys/actions_spec.js274
-rw-r--r--spec/javascript/vehicle_journeys/components/CustomFieldsInputs_spec.js41
-rw-r--r--spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js87
-rw-r--r--spec/javascript/vehicle_journeys/components/__snapshots__/CustomFieldsInputs_spec.js.snap3
-rw-r--r--spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap181
-rw-r--r--spec/javascript/vehicle_journeys/reducers/modal_spec.js91
-rw-r--r--spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js (renamed from spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js)233
16 files changed, 1554 insertions, 468 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, {
diff --git a/spec/javascript/preprocessor.js b/spec/javascript/preprocessor.js
new file mode 100644
index 000000000..a2de8e4be
--- /dev/null
+++ b/spec/javascript/preprocessor.js
@@ -0,0 +1,15 @@
+'use strict';
+
+var coffee = require('coffeescript');
+
+module.exports = {
+ process: function(src, filename) {
+ if (coffee.helpers.isCoffee(filename)) {
+ return coffee.compile(src, {
+ 'bare': false,
+ 'inlineMap': true
+ })
+ }
+ return src;
+ }
+};
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/time_table/reducers/timetable_spec.js b/spec/javascript/time_table/reducers/timetable_spec.js
index f0f9eaa8c..926fb2687 100644
--- a/spec/javascript/time_table/reducers/timetable_spec.js
+++ b/spec/javascript/time_table/reducers/timetable_spec.js
@@ -22,8 +22,6 @@ let json = {
time_table_dates: time_table_dates
}
-
-
describe('timetable reducer with empty state', () => {
beforeEach(() => {
state = {
@@ -87,6 +85,7 @@ describe('timetable reducer with filled state', () => {
periode_range: periode_range,
currentPage: current_periode_range
}
+ jsdom.reconfigure({url: "http://example.com/foo/bar"})
expect(
timetableReducer(state, {
type: 'GO_TO_PREVIOUS_PAGE',
diff --git a/spec/javascript/vehicle_journeys/actions_spec.js b/spec/javascript/vehicle_journeys/actions_spec.js
index 74765a7ef..9710d833c 100644
--- a/spec/javascript/vehicle_journeys/actions_spec.js
+++ b/spec/javascript/vehicle_journeys/actions_spec.js
@@ -1,6 +1,7 @@
import actions from '../../../app/javascript/vehicle_journeys/actions/index'
const dispatch = function(){}
+window.fetch = function(){return Promise.resolve()}
const currentPage = 1
describe('when cannot fetch api', () => {
@@ -37,11 +38,53 @@ describe('when clicking on add button', () => {
expect(actions.openCreateModal()).toEqual(expectedAction)
})
})
+describe('when validating the form', () => {
+ it('should check that non-commercial stops have passing time', () => {
+ let state = [{
+ vehicle_journey_at_stops: [{
+ area_kind: "non_commercial",
+ departure_time: {
+ hour: "00",
+ minute: "00"
+ }
+ }]
+ }]
+
+ expect(actions.validate(dispatch, state)).toEqual(true)
+
+ state = [{
+ vehicle_journey_at_stops: [{
+ area_kind: "non_commercial",
+ departure_time: {
+ hour: "00",
+ minute: "01"
+ }
+ }]
+ }]
+
+ expect(actions.validate(dispatch, state)).toEqual(true)
+ })
+
+ it('should not check that commercial stops', () => {
+ let state = [{
+ vehicle_journey_at_stops: [{
+ area_kind: "commercial",
+ departure_time: {
+ hour: "00",
+ minute: "00"
+ }
+ }]
+ }]
+
+ expect(actions.validate(dispatch, state)).toEqual(true)
+ })
+})
describe('when using select2 to pick a journey pattern', () => {
it('should create an action to select a journey pattern inside modal', () => {
let selectedJP = {
id: 1,
object_id: 2,
+ short_id: 2,
name: 'test',
published_name: 'test',
stop_area_short_descriptions: ['test']
@@ -51,6 +94,7 @@ describe('when using select2 to pick a journey pattern', () => {
selectedItem:{
id: selectedJP.id,
objectid: selectedJP.object_id,
+ short_id: selectedJP.object_id,
name: selectedJP.name,
published_name: selectedJP.published_name,
stop_areas: selectedJP.stop_area_short_descriptions
@@ -174,15 +218,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 +293,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 +321,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 +386,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 +622,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/components/CustomFieldsInputs_spec.js b/spec/javascript/vehicle_journeys/components/CustomFieldsInputs_spec.js
new file mode 100644
index 000000000..4f8d42d2d
--- /dev/null
+++ b/spec/javascript/vehicle_journeys/components/CustomFieldsInputs_spec.js
@@ -0,0 +1,41 @@
+import React, { Component } from 'react'
+import CustomFieldsInputs from '../../../../app/javascript/vehicle_journeys/components/tools/CustomFieldsInputs'
+import renderer from 'react-test-renderer'
+require('select2')
+
+describe('CustomFieldsInputs', () => {
+ set('values', () => {
+ return {}
+ })
+
+ set('component', () => {
+ let inputs = renderer.create(
+ <CustomFieldsInputs
+ values={values}
+ disabled={false}
+ onUpdate={()=>{}}
+ />
+ ).toJSON()
+
+ return inputs
+ })
+
+ it('should match the snapshot', () => {
+ expect(component).toMatchSnapshot()
+ })
+
+ // context('with fields', () => {
+ // set('values', () => {
+ // return {
+ // foo: {
+ // options: { list_values: ["", "1", "2"] },
+ // field_type: "list",
+ // name: "test"
+ // }
+ // }
+ // })
+ // it('should match the snapshot', () => {
+ // expect(component).toMatchSnapshot()
+ // })
+ // })
+})
diff --git a/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js
new file mode 100644
index 000000000..2a84cb9ca
--- /dev/null
+++ b/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js
@@ -0,0 +1,87 @@
+import React, { Component } from 'react'
+import VehicleJourneys from '../../../../app/javascript/vehicle_journeys/components/VehicleJourneys'
+import renderer from 'react-test-renderer'
+import fs from 'fs'
+
+import I18n from '../../../../public/javascripts/i18n'
+import decorateI18n from '../../../../app/assets/javascripts/i18n/extended.coffee'
+window.I18n = decorateI18n(I18n)
+I18n.locale = "fr"
+eval(fs.readFileSync('./public/javascripts/translations.js')+'')
+
+describe('stopPointHeader', () => {
+ set('features', () => {
+ return {}
+ })
+ set('component', () => {
+ let props = {
+ status: {},
+ filters: {
+ permissions: {},
+ features: features
+ },
+ onLoadFirstPage: ()=>{},
+ onUpdateTime: ()=>{},
+ onSelectVehicleJourney: ()=>{},
+ stopPointsList: [stop_point, same_city_stop_point, other_country_stop_point],
+ vehicleJourneys: []
+ }
+ let list = renderer.create(
+ <VehicleJourneys
+ status={props.status}
+ filters={props.filters}
+ onLoadFirstPage={props.onLoadFirstPage}
+ onUpdateTime={props.onUpdateTime}
+ onSelectVehicleJourney={props.onSelectVehicleJourney}
+ stopPointsList={props.stopPointsList}
+ vehicleJourneys={props.vehicleJourneys}
+ />
+ ).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/vehicle_journeys/components/__snapshots__/CustomFieldsInputs_spec.js.snap b/spec/javascript/vehicle_journeys/components/__snapshots__/CustomFieldsInputs_spec.js.snap
new file mode 100644
index 000000000..c93ec0097
--- /dev/null
+++ b/spec/javascript/vehicle_journeys/components/__snapshots__/CustomFieldsInputs_spec.js.snap
@@ -0,0 +1,3 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`CustomFieldsInputs should match the snapshot 1`] = `<div />`;
diff --git a/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap b/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap
new file mode 100644
index 000000000..cdd34cbbd
--- /dev/null
+++ b/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap
@@ -0,0 +1,181 @@
+// 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 Course
+ </div>
+ <div>
+ Nom Course
+ </div>
+ <div>
+ ID Mission
+ </div>
+ <div>
+ transporteur
+ </div>
+ <div>
+ calendrier
+ </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 Course
+ </div>
+ <div>
+ Nom Course
+ </div>
+ <div>
+ ID Mission
+ </div>
+ <div>
+ transporteur
+ </div>
+ <div>
+ calendrier
+ </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/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 1c2cc1577..0d7612a80 100644
--- a/spec/javascript/vehicle_journeys/reducers/vehicle_journeys_spec.js
+++ b/spec/javascript/vehicle_journeys/reducers/vehicleJourneys_spec.js
@@ -76,12 +76,12 @@ describe('vehicleJourneys reducer', () => {
let pristineVjasList = [{
delta : 0,
arrival_time : {
- hour: '00',
- minute: '00'
+ hour: "00",
+ minute: "00"
},
departure_time : {
- hour: '00',
- minute: '00'
+ hour: "00",
+ minute: "00"
},
stop_point_objectid: 'test',
stop_area_cityname: 'city',
@@ -89,7 +89,12 @@ describe('vehicleJourneys reducer', () => {
}]
let fakeData = {
published_journey_name: {value: 'test'},
- published_journey_identifier: {value : ''}
+ published_journey_identifier: {value : ''},
+ custom_fields: {
+ foo: {
+ value: 12
+ }
+ }
}
let fakeSelectedJourneyPattern = {id: "1"}
let fakeSelectedCompany = {name: "ALBATRANS"}
@@ -110,10 +115,205 @@ describe('vehicleJourneys reducer', () => {
objectid: '',
footnotes: [],
time_tables: [],
+ purchase_windows: [],
vehicle_journey_at_stops: pristineVjasList,
selected: false,
deletable: false,
transport_mode: 'undefined',
+ transport_submode: 'undefined',
+ custom_fields: {
+ foo: {
+ value: 12
+ }
+ }
+ }, ...state])
+ })
+
+ it('should handle ADD_VEHICLEJOURNEY with a start time and a fully timed JP', () => {
+ let pristineVjasList = [{
+ delta : 0,
+ arrival_time : {
+ hour: 22,
+ minute: 59
+ },
+ departure_time : {
+ hour: 22,
+ minute: 59
+ },
+ stop_point_objectid: 'test-1',
+ stop_area_cityname: 'city',
+ dummy: false
+ },
+ {
+ delta : 0,
+ arrival_time : {
+ hour: 23,
+ minute: 2
+ },
+ departure_time : {
+ hour: 23,
+ minute: 2
+ },
+ departure_day_offset: -1,
+ arrival_day_offset: -1,
+ stop_point_objectid: 'test-2',
+ stop_area_cityname: 'city',
+ dummy: false
+ },
+ {
+ delta : 0,
+ arrival_time : {
+ hour: "00",
+ minute: "00"
+ },
+ departure_time : {
+ hour: "00",
+ minute: "00"
+ },
+ stop_point_objectid: 'test-3',
+ stop_area_cityname: 'city',
+ dummy: true
+ },
+ {
+ delta : 0,
+ arrival_time : {
+ hour: 0,
+ minute: 32
+ },
+ departure_time : {
+ hour: 0,
+ minute: 32
+ },
+ stop_point_objectid: 'test-4',
+ stop_area_cityname: 'city',
+ dummy: false
+ }]
+ let fakeData = {
+ published_journey_name: {value: 'test'},
+ published_journey_identifier: {value : ''},
+ "start_time.hour": {value : '22'},
+ "start_time.minute": {value : '59'}
+ }
+ let fakeSelectedJourneyPattern = {
+ id: "1",
+ full_schedule: true,
+ stop_areas: [
+ {stop_area_short_description: {id: 1}},
+ {stop_area_short_description: {id: 2}},
+ {stop_area_short_description: {id: 4}},
+ ],
+ costs: {
+ "1-2": {
+ distance: 10,
+ time: 63
+ },
+ "2-4": {
+ distance: 10,
+ time: 30
+ }
+ }
+ }
+ let fakeSelectedCompany = {name: "ALBATRANS"}
+ expect(
+ vjReducer(state, {
+ type: 'ADD_VEHICLEJOURNEY',
+ data: fakeData,
+ selectedJourneyPattern: fakeSelectedJourneyPattern,
+ stopPointsList: [{object_id: 'test-1', city_name: 'city', stop_area_id: 1, id: 1, time_zone_offset: 0}, {object_id: 'test-2', city_name: 'city', stop_area_id: 2, id: 2, time_zone_offset: -3600}, {object_id: 'test-3', city_name: 'city', stop_area_id: 3, id: 3, time_zone_offset: 0}, {object_id: 'test-4', city_name: 'city', stop_area_id: 4, id: 4, time_zone_offset: 0}],
+ selectedCompany: fakeSelectedCompany
+ })
+ ).toEqual([{
+ journey_pattern: fakeSelectedJourneyPattern,
+ company: fakeSelectedCompany,
+ published_journey_name: 'test',
+ published_journey_identifier: '',
+ short_id: '',
+ objectid: '',
+ footnotes: [],
+ time_tables: [],
+ purchase_windows: [],
+ vehicle_journey_at_stops: pristineVjasList,
+ selected: false,
+ custom_fields: undefined,
+ deletable: false,
+ transport_mode: 'undefined',
+ transport_submode: 'undefined'
+ }, ...state])
+ })
+
+ it('should handle ADD_VEHICLEJOURNEY with a start time and a fully timed JP but the minutes are not set', () => {
+ let pristineVjasList = [{
+ delta : 0,
+ arrival_time : {
+ hour: 22,
+ minute: 0
+ },
+ departure_time : {
+ hour: 22,
+ minute: 0
+ },
+ stop_point_objectid: 'test-1',
+ stop_area_cityname: 'city',
+ dummy: false
+ },
+ {
+ delta : 0,
+ arrival_time : {
+ hour: 22,
+ minute: 3
+ },
+ departure_time : {
+ hour: 22,
+ minute: 3
+ },
+ stop_point_objectid: 'test-2',
+ stop_area_cityname: 'city',
+ dummy: false
+ }]
+ let fakeData = {
+ published_journey_name: {value: 'test'},
+ published_journey_identifier: {value : ''},
+ "start_time.hour": {value : '22'},
+ "start_time.minute": {value : ''}
+ }
+ let fakeSelectedJourneyPattern = {
+ id: "1",
+ full_schedule: true,
+ stop_areas: [
+ {stop_area_short_description: {id: 1}},
+ {stop_area_short_description: {id: 2}},
+ ],
+ costs: {
+ "1-2": {
+ distance: 10,
+ time: 63
+ },
+ }
+ }
+ let fakeSelectedCompany = {name: "ALBATRANS"}
+ expect(
+ vjReducer(state, {
+ type: 'ADD_VEHICLEJOURNEY',
+ data: fakeData,
+ selectedJourneyPattern: fakeSelectedJourneyPattern,
+ stopPointsList: [{object_id: 'test-1', city_name: 'city', stop_area_id: 1, id: 1, time_zone_offset: 0}, {object_id: 'test-2', city_name: 'city', stop_area_id: 2, id: 2, time_zone_offset: -3600}],
+ selectedCompany: fakeSelectedCompany
+ })
+ ).toEqual([{
+ journey_pattern: fakeSelectedJourneyPattern,
+ company: fakeSelectedCompany,
+ published_journey_name: 'test',
+ published_journey_identifier: '',
+ short_id: '',
+ objectid: '',
+ footnotes: [],
+ time_tables: [],
+ purchase_windows: [],
+ vehicle_journey_at_stops: pristineVjasList,
+ selected: false,
+ custom_fields: undefined,
+ deletable: false,
+ transport_mode: 'undefined',
transport_submode: 'undefined'
}, ...state])
})
@@ -240,12 +440,18 @@ describe('vehicleJourneys reducer', () => {
})
it('should handle EDIT_VEHICLEJOURNEY', () => {
+ let custom_fields = {
+ foo: {
+ value: 12
+ }
+ }
let fakeData = {
published_journey_name: {value : 'test'},
- published_journey_identifier: {value: 'test'}
+ published_journey_identifier: {value: 'test'},
+ custom_fields: {foo: {value: 12}}
}
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})
+ let newVJ = Object.assign({}, state[0], {company: fakeSelectedCompany, published_journey_name: fakeData.published_journey_name.value, published_journey_identifier: fakeData.published_journey_identifier.value, custom_fields})
expect(
vjReducer(state, {
type: 'EDIT_VEHICLEJOURNEY',
@@ -254,7 +460,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 +471,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)
+ })
})