aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorThomas Haddad2017-03-09 18:06:30 +0100
committerThomas Haddad2017-03-09 18:06:30 +0100
commitf14fbad37c0daa0b79aaf12b234168e917b29cee (patch)
treee5149f670c704b5cc7b11f5063bad16125d8ae5e /spec
parentf4c5751a4037f52ab1d73fc201e81ba07798ecd4 (diff)
parent3ec5c7bf65b267ce96431906feb6025cfbff347a (diff)
downloadchouette-core-f14fbad37c0daa0b79aaf12b234168e917b29cee.tar.bz2
Merge branch '2498_vehicle_journeys'
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/vehicle_journeys_collections_controller_spec.rb5
-rw-r--r--spec/javascripts/journey_patterns/reducers/pagination_spec.js4
-rw-r--r--spec/javascripts/vehicle_journeys/actions_spec.js394
-rw-r--r--spec/javascripts/vehicle_journeys/reducers/filters_spec.js154
-rw-r--r--spec/javascripts/vehicle_journeys/reducers/modal_spec.js160
-rw-r--r--spec/javascripts/vehicle_journeys/reducers/pagination_spec.js114
-rw-r--r--spec/javascripts/vehicle_journeys/reducers/status_spec.js45
-rw-r--r--spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js259
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb49
9 files changed, 1182 insertions, 2 deletions
diff --git a/spec/controllers/vehicle_journeys_collections_controller_spec.rb b/spec/controllers/vehicle_journeys_collections_controller_spec.rb
new file mode 100644
index 000000000..39ea55761
--- /dev/null
+++ b/spec/controllers/vehicle_journeys_collections_controller_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe VehicleJourneysCollectionsController, :type => :controller do
+
+end
diff --git a/spec/javascripts/journey_patterns/reducers/pagination_spec.js b/spec/javascripts/journey_patterns/reducers/pagination_spec.js
index 4800451e9..d0f9fef47 100644
--- a/spec/javascripts/journey_patterns/reducers/pagination_spec.js
+++ b/spec/javascripts/journey_patterns/reducers/pagination_spec.js
@@ -3,9 +3,9 @@ var reducer = require('es6_browserified/journey_patterns/reducers/pagination')
const diff = 1
let state = {
page : 2,
- totalCount : 25,
+ totalCount : 50,
stateChanged: false,
- perPage: 12
+ perPage: 20
}
let pagination = Object.assign({}, state)
const dispatch = function(){}
diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js
new file mode 100644
index 000000000..ec52036d6
--- /dev/null
+++ b/spec/javascripts/vehicle_journeys/actions_spec.js
@@ -0,0 +1,394 @@
+var actions = require('es6_browserified/vehicle_journeys/actions')
+
+const dispatch = function(){}
+const currentPage = 1
+
+describe('when cannot fetch api', () => {
+ it('should create an action to toggle error', () => {
+ const expectedAction = {
+ type: 'UNAVAILABLE_SERVER',
+ }
+ expect(actions.unavailableServer()).toEqual(expectedAction)
+ })
+})
+describe('when fetching api', () => {
+ it('should create an action to fetch api', () => {
+ const expectedAction = {
+ type: 'FETCH_API',
+ }
+ expect(actions.fetchingApi()).toEqual(expectedAction)
+ })
+})
+describe('when receiveJourneyPatterns is triggered', () => {
+ it('should create an action to pass json to reducer', () => {
+ const json = undefined
+ const expectedAction = {
+ type: 'RECEIVE_VEHICLE_JOURNEYS',
+ json
+ }
+ expect(actions.receiveVehicleJourneys()).toEqual(expectedAction)
+ })
+})
+describe('when clicking on add button', () => {
+ it('should create an action to open a create modal', () => {
+ const expectedAction = {
+ type: 'CREATE_VEHICLEJOURNEY_MODAL',
+ }
+ expect(actions.openCreateModal()).toEqual(expectedAction)
+ })
+})
+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,
+ name: 'test',
+ published_name: 'test'
+ }
+ const expectedAction = {
+ type: 'SELECT_JP_CREATE_MODAL',
+ selectedItem:{
+ id: selectedJP.id,
+ objectid: selectedJP.object_id,
+ name: selectedJP.name,
+ published_name: selectedJP.published_name
+ }
+ }
+ expect(actions.selectJPCreateModal(selectedJP)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on validate button inside create modal', () => {
+ it('should create an action to create a new vehicle journey', () => {
+ const data = {}
+ const selectedJourneyPattern = {}
+ const expectedAction = {
+ type: 'ADD_VEHICLEJOURNEY',
+ data,
+ selectedJourneyPattern
+ }
+ expect(actions.addVehicleJourney(data, selectedJourneyPattern)).toEqual(expectedAction)
+ })
+})
+describe('when previous navigation button is clicked', () => {
+ it('should create an action to go to previous page', () => {
+ const nextPage = false
+ const queryString = ''
+ const pagination = {
+ totalCount: 25,
+ perPage: 12,
+ page:1
+ }
+ const expectedAction = {
+ type: 'GO_TO_PREVIOUS_PAGE',
+ dispatch,
+ pagination,
+ nextPage,
+ queryString
+ }
+ expect(actions.goToPreviousPage(dispatch, pagination, queryString)).toEqual(expectedAction)
+ })
+})
+describe('when next navigation button is clicked', () => {
+ it('should create an action to go to next page', () => {
+ const queryString = ''
+ const nextPage = true
+ const pagination = {
+ totalCount: 25,
+ perPage: 12,
+ page:1
+ }
+ const expectedAction = {
+ type: 'GO_TO_NEXT_PAGE',
+ dispatch,
+ pagination,
+ nextPage,
+ queryString
+ }
+ expect(actions.goToNextPage(dispatch, pagination, queryString)).toEqual(expectedAction)
+ })
+})
+describe('when checking a vehicleJourney', () => {
+ it('should create an action to select vj', () => {
+ const index = 1
+ const expectedAction = {
+ type: 'SELECT_VEHICLEJOURNEY',
+ index
+ }
+ expect(actions.selectVehicleJourney(index)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on cancel selection button', () => {
+ it('should create an action to cancel whole selection', () => {
+ const index = 1
+ const expectedAction = {
+ type: 'CANCEL_SELECTION'
+ }
+ expect(actions.cancelSelection()).toEqual(expectedAction)
+ })
+})
+describe('when clicking on delete button', () => {
+ it('should create an action to delete vj', () => {
+ const expectedAction = {
+ type: 'DELETE_VEHICLEJOURNEYS',
+ }
+ expect(actions.deleteVehicleJourneys()).toEqual(expectedAction)
+ })
+})
+describe('when toggling arrivals', () => {
+ it('should create an action to toggleArrivals', () => {
+ const expectedAction = {
+ type: 'TOGGLE_ARRIVALS',
+ }
+ expect(actions.toggleArrivals()).toEqual(expectedAction)
+ })
+})
+describe('when updating vjas time', () => {
+ it('should create an action to update time', () => {
+ const val = 33, subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true
+ const expectedAction = {
+ type: 'UPDATE_TIME',
+ val,
+ subIndex,
+ index,
+ timeUnit,
+ isDeparture,
+ isArrivalsToggled
+ }
+ expect(actions.updateTime(val, subIndex, index, timeUnit, isDeparture, isArrivalsToggled)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on validate button inside shifting modal', () => {
+ it('should create an action to shift a vehiclejourney schedule', () => {
+ const data = {}
+ const expectedAction = {
+ type: 'SHIFT_VEHICLEJOURNEY',
+ data
+ }
+ expect(actions.shiftVehicleJourney(data)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on validate button inside editing modal', () => {
+ it('should create an action to update a vehiclejourney', () => {
+ const data = {}
+ const expectedAction = {
+ type: 'EDIT_VEHICLEJOURNEY',
+ data
+ }
+ expect(actions.editVehicleJourney(data)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on validate button inside duplicating modal', () => {
+ it('should create an action to duplicate a vehiclejourney schedule', () => {
+ const data = {}
+ const expectedAction = {
+ type: 'DUPLICATE_VEHICLEJOURNEY',
+ data
+ }
+ expect(actions.duplicateVehicleJourney(data)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on edit notes modal', () => {
+ it('should create an action to open footnotes modal', () => {
+ const vehicleJourney = {}
+ const expectedAction = {
+ type: 'EDIT_NOTES_VEHICLEJOURNEY_MODAL',
+ vehicleJourney
+ }
+ 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
+ const expectedAction = {
+ type: 'TOGGLE_FOOTNOTE_MODAL',
+ footnote,
+ isShown
+ }
+ expect(actions.toggleFootnoteModal(footnote, isShown)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on validate button inside footnote modal', () => {
+ it('should create an action to update vj footnotes', () => {
+ const footnotes = []
+ const expectedAction = {
+ type: 'EDIT_VEHICLEJOURNEY_NOTES',
+ footnotes
+ }
+ 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 = []
+ const expectedAction = {
+ type: 'EDIT_CALENDARS_VEHICLEJOURNEY_MODAL',
+ vehicleJourneys
+ }
+ expect(actions.openCalendarsEditModal(vehicleJourneys)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on delete button next to a timetable inside modal', () => {
+ it('should create an action to delete timetable from selected vehicle journeys', () => {
+ const timetable = {}
+ const expectedAction = {
+ type: 'DELETE_CALENDAR_MODAL',
+ timetable
+ }
+ expect(actions.deleteCalendarModal(timetable)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on validate button inside calendars modal', () => {
+ it('should create an action to update vj calendars', () => {
+ const vehicleJourneys = []
+ const expectedAction = {
+ type: 'EDIT_VEHICLEJOURNEYS_CALENDARS',
+ vehicleJourneys
+ }
+ expect(actions.editVehicleJourneyCalendars(vehicleJourneys)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on add button inside calendars modal', () => {
+ it('should create an action to add the selected timetable to preselected vjs', () => {
+ const expectedAction = {
+ type: 'ADD_SELECTED_TIMETABLE',
+ }
+ expect(actions.addSelectedTimetable()).toEqual(expectedAction)
+ })
+})
+describe('when using select2 to pick a timetable', () => {
+ it('should create an action to select a timetable inside modal', () => {
+ let selectedTT = {
+ id: 1,
+ objectid: 2,
+ comment: 'test',
+ }
+ const expectedAction = {
+ type: 'SELECT_TT_CALENDAR_MODAL',
+ selectedItem:{
+ id: selectedTT.id,
+ objectid: selectedTT.objectid,
+ comment: selectedTT.comment,
+ }
+ }
+ expect(actions.selectTTCalendarsModal(selectedTT)).toEqual(expectedAction)
+ })
+})
+describe('when clicking on reset button inside query filters', () => {
+ it('should create an action to reset the query filters', () => {
+ const expectedAction = {
+ type: 'BATCH',
+ payload: [
+ {type: 'RESET_FILTERS'},
+ {type: 'RESET_PAGINATION'},
+ {type: 'QUERY_FILTER_VEHICLEJOURNEYS', dispatch: undefined},
+ ]
+ }
+ expect(actions.resetFilters()).toEqual(expectedAction)
+ })
+})
+describe('when clicking on filter button inside query filters', () => {
+ it('should create an action to filter', () => {
+ const expectedAction = {
+ type: 'BATCH',
+ payload: [
+ {type: 'CREATE_QUERY_STRING'},
+ {type: 'RESET_PAGINATION'},
+ {type: 'QUERY_FILTER_VEHICLEJOURNEYS', dispatch: undefined},
+ ]
+ }
+ expect(actions.filterQuery()).toEqual(expectedAction)
+ })
+})
+describe('when clicking on checkbox to show vj without schedule', () => {
+ it('should create an action to toggle this filter', () => {
+ const expectedAction = {
+ type: 'TOGGLE_WITHOUT_SCHEDULE',
+ }
+ expect(actions.toggleWithoutSchedule()).toEqual(expectedAction)
+ })
+})
+describe('when setting new interval', () => {
+ const val = 1
+ const unit = 'hour'
+ it('should create actions to update intervals in state', () => {
+ let expectedAction = {
+ type: 'UPDATE_START_TIME_FILTER',
+ val,
+ unit
+ }
+ expect(actions.updateStartTimeFilter(val, unit)).toEqual(expectedAction)
+ })
+ it('should create actions to update intervals in state', () => {
+ let expectedAction = {
+ type: 'UPDATE_END_TIME_FILTER',
+ val,
+ unit
+ }
+ expect(actions.updateEndTimeFilter(val, unit)).toEqual(expectedAction)
+ })
+})
+describe('when using select2 to pick a timetable in the filters', () => {
+ it('should create an action to select a timetable as a filter', () => {
+ let selectedTT = {
+ id: 1,
+ objectid: 2,
+ comment: 'test',
+ }
+ const expectedAction = {
+ type: 'SELECT_TT_FILTER',
+ selectedItem:{
+ id: selectedTT.id,
+ objectid: selectedTT.objectid,
+ comment: selectedTT.comment,
+ }
+ }
+ expect(actions.filterSelect2Timetable(selectedTT)).toEqual(expectedAction)
+ })
+})
+describe('when using select2 to pick a journeypattern in the filters', () => {
+ it('should create an action to select a journey pattern as a filter', () => {
+ let selectedJP = {
+ id: 1,
+ object_id: 2,
+ name: 'test',
+ published_name: 'test'
+ }
+ const expectedAction = {
+ type: 'SELECT_JP_FILTER',
+ selectedItem:{
+ id: selectedJP.id,
+ objectid: selectedJP.object_id,
+ name: selectedJP.name,
+ published_name: selectedJP.published_name
+ }
+ }
+ expect(actions.filterSelect2JourneyPattern(selectedJP)).toEqual(expectedAction)
+ })
+})
+describe('when user clicked either on filter or reset button in filters', () => {
+ it('should create an action to reset pagination', () => {
+ const expectedAction = {
+ type: 'RESET_PAGINATION',
+ }
+ expect(actions.resetPagination()).toEqual(expectedAction)
+ })
+})
+describe('when user clicked either on filter or reset button in filters', () => {
+ it('should create an action to create a queryString with params filters', () => {
+ const expectedAction = {
+ type: 'CREATE_QUERY_STRING',
+ }
+ expect(actions.createQueryString()).toEqual(expectedAction)
+ })
+})
+describe('when submitting new vj', () => {
+ it('should create an action to update pagination totalCount', () => {
+ const diff = 1
+ const expectedAction = {
+ type: 'UPDATE_TOTAL_COUNT',
+ diff
+ }
+ expect(actions.updateTotalCount(diff)).toEqual(expectedAction)
+ })
+})
diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js
new file mode 100644
index 000000000..84608243b
--- /dev/null
+++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js
@@ -0,0 +1,154 @@
+var statusReducer = require('es6_browserified/vehicle_journeys/reducers/filters')
+
+let state = {}
+
+describe('filters reducer', () => {
+ const cleanInterval = {
+ start:{
+ hour: '00',
+ minute: '00'
+ },
+ end:{
+ hour: '23',
+ minute: '59'
+ }
+ }
+ beforeEach(() => {
+ state = {
+ toggleArrivals: false,
+ query: {
+ interval: {
+ start:{
+ hour: '11',
+ minute: '11'
+ },
+ end:{
+ hour: '22',
+ minute: '22'
+ }
+ },
+ journeyPattern: {},
+ timetable: {},
+ withoutSchedule: false,
+ },
+ queryString: ''
+ }
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ statusReducer(undefined, {})
+ ).toEqual({})
+ })
+
+ it('should handle TOGGLE_ARRIVALS', () => {
+ expect(
+ statusReducer(state, {
+ type: 'TOGGLE_ARRIVALS'
+ })
+ ).toEqual(Object.assign({}, state, {toggleArrivals: true}))
+ })
+
+ it('should handle RESET_FILTERS', () => {
+ let cleanQuery = JSON.parse(JSON.stringify(state.query))
+ cleanQuery.interval = cleanInterval
+ expect(
+ statusReducer(state, {
+ type: 'RESET_FILTERS'
+ })
+ ).toEqual(Object.assign({}, state, {query: cleanQuery}))
+ })
+
+ it('should handle TOGGLE_WITHOUT_SCHEDULE', () => {
+ let rslt = JSON.parse(JSON.stringify(state.query))
+ rslt.withoutSchedule = true
+ expect(
+ statusReducer(state, {
+ type: 'TOGGLE_WITHOUT_SCHEDULE'
+ })
+ ).toEqual(Object.assign({}, state, {query: rslt}))
+ })
+
+ it('should handle UPDATE_START_TIME_FILTER', () => {
+ let val = 12
+ let unit = 'minute'
+ let rslt = JSON.parse(JSON.stringify(state.query))
+ rslt.interval.start.minute = String(val)
+ expect(
+ statusReducer(state, {
+ type: 'UPDATE_START_TIME_FILTER',
+ val,
+ unit
+ })
+ ).toEqual(Object.assign({}, state, {query: rslt}))
+ })
+
+ it('should handle UPDATE_START_TIME_FILTER and not make any update', () => {
+ let val = 23
+ let unit = 'hour'
+ expect(
+ statusReducer(state, {
+ type: 'UPDATE_START_TIME_FILTER',
+ val,
+ unit
+ })
+ ).toEqual(state)
+ })
+
+ it('should handle UPDATE_END_TIME_FILTER', () => {
+ let val = 12
+ let unit = 'minute'
+ let rslt = JSON.parse(JSON.stringify(state.query))
+ rslt.interval.end.minute = String(val)
+ expect(
+ statusReducer(state, {
+ type: 'UPDATE_END_TIME_FILTER',
+ val,
+ unit
+ })
+ ).toEqual(Object.assign({}, state, {query: rslt}))
+ })
+
+ it('should handle UPDATE_END_TIME_FILTER and not make any update', () => {
+ let val = 1
+ let unit = 'hour'
+ expect(
+ statusReducer(state, {
+ type: 'UPDATE_END_TIME_FILTER',
+ val,
+ unit
+ })
+ ).toEqual(state)
+ })
+
+ it('should handle SELECT_TT_FILTER', () => {
+ let newTimetable = {timetable : {id: 1}}
+ let newQuery = Object.assign({}, state.query, newTimetable)
+ expect(
+ statusReducer(state, {
+ type: 'SELECT_TT_FILTER',
+ selectedItem: {id: 1}
+ })
+ ).toEqual(Object.assign({}, state, {query: newQuery}))
+ })
+
+ it('should handle SELECT_JP_FILTER', () => {
+ let newJourneyPattern = {journeyPattern : {id: 1}}
+ let newQuery = Object.assign({}, state.query, newJourneyPattern)
+ expect(
+ statusReducer(state, {
+ type: 'SELECT_JP_FILTER',
+ selectedItem: {id: 1}
+ })
+ ).toEqual(Object.assign({}, state, {query: newQuery}))
+ })
+
+ it('should handle SELECT_JP_FILTER', () => {
+ let strResult = "q%5Bjourney_pattern_id_eq%5D=undefined&q%5Btime_tables_id_eq%5D=undefined&q%5Bvehicle_journey_at_stops_departure_time_gteq%5D=11%3A11&q%5Bvehicle_journey_at_stops_departure_time_lteq%5D=22%3A22"
+ expect(
+ statusReducer(state, {
+ type: 'CREATE_QUERY_STRING',
+ })
+ ).toEqual(Object.assign({}, state, {queryString: strResult}))
+ })
+})
diff --git a/spec/javascripts/vehicle_journeys/reducers/modal_spec.js b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js
new file mode 100644
index 000000000..7c81d729b
--- /dev/null
+++ b/spec/javascripts/vehicle_journeys/reducers/modal_spec.js
@@ -0,0 +1,160 @@
+var modalReducer = require('es6_browserified/vehicle_journeys/reducers/modal')
+
+let state = {}
+
+const cb = function(){}
+
+describe('modal reducer', () => {
+ beforeEach(() => {
+ state = {
+ type: '',
+ modalProps: {},
+ confirmModal: {}
+ }
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ modalReducer(undefined, {})
+ ).toEqual({})
+ })
+
+ it('should handle OPEN_CONFIRM_MODAL', () => {
+ let newState = Object.assign({}, state, {
+ type: 'confirm',
+ confirmModal: {
+ callback: cb
+ }
+ })
+ expect(
+ modalReducer(state, {
+ type: 'OPEN_CONFIRM_MODAL',
+ callback: cb
+ })
+ ).toEqual(newState)
+ })
+
+ it('should handle CREATE_VEHICLEJOURNEY_MODAL', () => {
+ expect(
+ modalReducer(state, {
+ type: 'CREATE_VEHICLEJOURNEY_MODAL'
+ })
+ ).toEqual(Object.assign({}, state, { type: 'create' }))
+ })
+
+ it('should handle SELECT_JP_CREATE_MODAL', () => {
+ let newModalProps = {selectedJPModal : {id: 1}}
+ expect(
+ modalReducer(state, {
+ type: 'SELECT_JP_CREATE_MODAL',
+ selectedItem: {id: 1}
+ })
+ ).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
+ })
+
+ it('should handle CLOSE_MODAL', () => {
+ expect(
+ modalReducer(state, {
+ type: 'CLOSE_MODAL'
+ })
+ ).toEqual(state)
+ })
+
+ it('should handle EDIT_NOTES_VEHICLEJOURNEY_MODAL', () => {
+ let vehicleJourney = {}
+ let modalPropsResult = {
+ vehicleJourney: {}
+ }
+ expect(
+ modalReducer(state, {
+ type: 'EDIT_NOTES_VEHICLEJOURNEY_MODAL',
+ vehicleJourney
+ })
+ ).toEqual(Object.assign({}, state, {type: 'notes_edit', modalProps: modalPropsResult}))
+ })
+
+ it('should handle TOGGLE_FOOTNOTE_MODAL', () => {
+ state.modalProps = {vehicleJourney : {footnotes: [{}, {}]}}
+ let footnote = {}
+ let newState = {
+ // for the sake of the test, no need to specify the type
+ type: '',
+ modalProps:{vehicleJourney: {footnotes: [{},{},{}]}},
+ confirmModal: {}
+ }
+ expect(
+ modalReducer(state, {
+ type: 'TOGGLE_FOOTNOTE_MODAL',
+ footnote,
+ isShown: true
+ })
+ ).toEqual(newState)
+ })
+
+ it('should handle EDIT_CALENDARS_VEHICLEJOURNEY_MODAL', () => {
+ let vehicleJourneys = []
+ let modalPropsResult = {
+ vehicleJourneys: [],
+ timetables: []
+ }
+ expect(
+ modalReducer(state, {
+ type: 'EDIT_CALENDARS_VEHICLEJOURNEY_MODAL',
+ vehicleJourneys
+ })
+ ).toEqual(Object.assign({}, state, {type: 'calendars_edit', modalProps: modalPropsResult}))
+ })
+
+ it('should handle SELECT_TT_CALENDAR_MODAL', () => {
+ let newModalProps = {selectedTimetable : {id: 1}}
+ expect(
+ modalReducer(state, {
+ type: 'SELECT_TT_CALENDAR_MODAL',
+ selectedItem: {id: 1}
+ })
+ ).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
+ })
+
+ it('should handle ADD_SELECTED_TIMETABLE', () => {
+ let fakeTimetables = [{'test': 'test'}, {'test 2': 'test 2'}, {'add': 'add'}]
+ let newTimeTables = [{'test': 'test'}, {'test 2': 'test 2'}, {'add': 'add'}]
+ let fakeVehicleJourneys= [{time_tables: fakeTimetables}, {time_tables: newTimeTables}]
+ state.modalProps.vehicleJourneys = fakeVehicleJourneys
+ state.modalProps.timetables = fakeTimetables
+ state.modalProps.selectedTimetable = {'add': 'add'}
+ let newState = {
+ type: '',
+ modalProps:{
+ vehicleJourneys: [{time_tables: newTimeTables},{time_tables: newTimeTables}],
+ timetables: [{'test': 'test'},{'test 2': 'test 2'},{'add': 'add'}],
+ selectedTimetable: {'add': 'add'}
+ },
+ confirmModal: {}
+ }
+ expect(
+ modalReducer(state, {
+ type: 'ADD_SELECTED_TIMETABLE',
+ })
+ ).toEqual(newState)
+ })
+
+ it('should handle DELETE_CALENDAR_MODAL', () => {
+ let deletableTimetable = {'delete': 'delete'}
+ let fakeTimetables = [{'test': 'test'}, {'test 2': 'test 2'}, deletableTimetable]
+ let newTimeTables = [{'test': 'test'}, {'test 2': 'test 2'}]
+ let fakeVehicleJourneys= [{time_tables: fakeTimetables}, {time_tables: fakeTimetables}]
+ state.modalProps = Object.assign({}, state.modalProps,{vehicleJourneys : fakeVehicleJourneys, timetables: fakeTimetables })
+ let newState = {
+ // for the sake of the test, no need to specify the type
+ type: '',
+ modalProps:{vehicleJourneys: [{time_tables: newTimeTables},{time_tables: newTimeTables}], timetables: [{'test': 'test'},{'test 2': 'test 2'}]},
+ confirmModal: {}
+ }
+ expect(
+ modalReducer(state, {
+ type: 'DELETE_CALENDAR_MODAL',
+ timetable: deletableTimetable
+ })
+ ).toEqual(newState)
+ })
+})
diff --git a/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js
new file mode 100644
index 000000000..ff74e1a0d
--- /dev/null
+++ b/spec/javascripts/vehicle_journeys/reducers/pagination_spec.js
@@ -0,0 +1,114 @@
+var reducer = require('es6_browserified/vehicle_journeys/reducers/pagination')
+
+const diff = 1
+let state = {
+ page : 2,
+ totalCount : 25,
+ stateChanged: false,
+ perPage: 12
+}
+let pagination = Object.assign({}, state)
+const dispatch = function(){}
+
+describe('pagination reducer, given parameters allowing page change', () => {
+
+ it('should return the initial state', () => {
+ expect(
+ reducer(undefined, {})
+ ).toEqual({})
+ })
+
+ it('should handle RESET_PAGINATION', () => {
+ expect(
+ reducer(state, {
+ type: 'RESET_PAGINATION',
+ })
+ ).toEqual(Object.assign({}, state, {page: 1}))
+ })
+
+ it('should handle UPDATE_TOTAL_COUNT', () => {
+ expect(
+ reducer(state, {
+ type: 'UPDATE_TOTAL_COUNT',
+ diff: 1
+ })
+ ).toEqual(Object.assign({}, state, {totalCount: 24}))
+ })
+
+ it('should handle GO_TO_NEXT_PAGE and change state', () => {
+ expect(
+ reducer(state, {
+ type: 'GO_TO_NEXT_PAGE',
+ dispatch,
+ pagination,
+ nextPage : true
+ })
+ ).toEqual(Object.assign({}, state, {page : state.page + 1, stateChanged: false}))
+ })
+
+ it('should return GO_TO_PREVIOUS_PAGE and change state', () => {
+ expect(
+ reducer(state, {
+ type: 'GO_TO_PREVIOUS_PAGE',
+ dispatch,
+ pagination,
+ nextPage : false
+ })
+ ).toEqual(Object.assign({}, state, {page : state.page - 1, stateChanged: false}))
+ })
+
+ it('should handle UPDATE_TIME', () => {
+ const val = '33', subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true
+ expect(
+ reducer(state, {
+ type: 'UPDATE_TIME',
+ val,
+ subIndex,
+ index,
+ timeUnit,
+ isDeparture,
+ isArrivalsToggled
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+
+})
+
+
+describe('pagination reducer, given parameters not allowing to go to previous page', () => {
+
+ beforeEach(()=>{
+ state.page = 1
+ pagination.page = 1
+ })
+
+ it('should return GO_TO_PREVIOUS_PAGE and not change state', () => {
+ expect(
+ reducer(state, {
+ type: 'GO_TO_PREVIOUS_PAGE',
+ dispatch,
+ pagination,
+ nextPage : false
+ })
+ ).toEqual(state)
+ })
+})
+
+describe('pagination reducer, given parameters not allowing to go to next page', () => {
+
+ beforeEach(()=>{
+ state.page = 3
+ pagination.page = 3
+ })
+
+ it('should return GO_TO_NEXT_PAGE and not change state', () => {
+ expect(
+ reducer(state, {
+ type: 'GO_TO_NEXT_PAGE',
+ dispatch,
+ pagination,
+ nextPage : true
+ })
+ ).toEqual(state)
+ })
+})
diff --git a/spec/javascripts/vehicle_journeys/reducers/status_spec.js b/spec/javascripts/vehicle_journeys/reducers/status_spec.js
new file mode 100644
index 000000000..d48d48f4a
--- /dev/null
+++ b/spec/javascripts/vehicle_journeys/reducers/status_spec.js
@@ -0,0 +1,45 @@
+var statusReducer = require('es6_browserified/vehicle_journeys/reducers/status')
+
+let state = {}
+
+const dispatch = function(){}
+
+describe('status reducer', () => {
+ beforeEach(() => {
+ state = {
+ fetchSuccess: true,
+ isFetching: false
+ }
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ statusReducer(undefined, {})
+ ).toEqual({})
+ })
+
+ it('should handle UNAVAILABLE_SERVER', () => {
+ expect(
+ statusReducer(state, {
+ type: 'UNAVAILABLE_SERVER'
+ })
+ ).toEqual(Object.assign({}, state, {fetchSuccess: false}))
+ })
+
+ it('should handle RECEIVE_VEHICLE_JOURNEYS', () => {
+ expect(
+ statusReducer(state, {
+ type: 'RECEIVE_VEHICLE_JOURNEYS'
+ })
+ ).toEqual(Object.assign({}, state, {fetchSuccess: true, isFetching: false}))
+ })
+
+ it('should handle FETCH_API', () => {
+ expect(
+ statusReducer(state, {
+ type: 'FETCH_API'
+ })
+ ).toEqual(Object.assign({}, state, {isFetching: true}))
+ })
+
+})
diff --git a/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js
new file mode 100644
index 000000000..dbdb253c7
--- /dev/null
+++ b/spec/javascripts/vehicle_journeys/reducers/vehicle_journeys_spec.js
@@ -0,0 +1,259 @@
+var vjReducer = require('es6_browserified/vehicle_journeys/reducers/vehicleJourneys')
+
+let state = []
+let stateModal = {
+ type: '',
+ modalProps: {},
+ confirmModal: {}
+}
+let fakeFootnotes = [{
+ id: 1,
+ code: 1,
+ label: "1"
+},{
+ id: 2,
+ code: 2,
+ label: "2"
+}]
+
+let fakeTimeTables = [{
+ published_journey_name: 'test 1',
+ objectid: '1'
+},{
+ published_journey_name: 'test 2',
+ objectid: '2'
+},{
+ published_journey_name: 'test 3',
+ objectid: '3'
+}]
+let fakeVJAS = [{
+ delta : 627,
+ arrival_time : {
+ hour: '11',
+ minute: '55'
+ },
+ departure_time : {
+ hour: '22',
+ minute: '22'
+ },
+ stop_area_object_id : "FR:92024:ZDE:420553:STIF"
+}]
+
+describe('vehicleJourneys reducer', () => {
+ beforeEach(()=>{
+ state = [
+ {
+ journey_pattern_id: 1,
+ published_journey_name: "vj1",
+ objectid: '11',
+ deletable: false,
+ selected: true,
+ footnotes: fakeFootnotes,
+ time_tables: fakeTimeTables,
+ vehicle_journey_at_stops: fakeVJAS
+ },
+ {
+ journey_pattern_id: 2,
+ published_journey_name: "vj2",
+ objectid: '22',
+ selected: false,
+ deletable: false,
+ footnotes: fakeFootnotes,
+ time_tables: fakeTimeTables,
+ vehicle_journey_at_stops: fakeVJAS
+ }
+ ]
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ vjReducer(undefined, {})
+ ).toEqual([])
+ })
+
+
+ it('should handle ADD_VEHICLEJOURNEY', () => {
+ let resultVJ = [{
+ delta : 0,
+ arrival_time : {
+ hour: '00',
+ minute: '00'
+ },
+ departure_time : {
+ hour: '00',
+ minute: '00'
+ }
+ }]
+ let fakeData = {
+ published_journey_name: {value: 'test'}
+ }
+ let fakeSelectedJourneyPattern = { id: "1"}
+ expect(
+ vjReducer(state, {
+ type: 'ADD_VEHICLEJOURNEY',
+ data: fakeData,
+ selectedJourneyPattern: fakeSelectedJourneyPattern
+ })
+ ).toEqual([{
+ dummy: false,
+ journey_pattern: fakeSelectedJourneyPattern,
+ published_journey_name: 'test',
+ objectid: '',
+ footnotes: [],
+ time_tables: [],
+ vehicle_journey_at_stops: resultVJ,
+ selected: false,
+ deletable: false
+ }, ...state])
+ })
+
+ it('should handle RECEIVE_VEHICLE_JOURNEYS', () => {
+ expect(
+ vjReducer(state, {
+ type: 'RECEIVE_VEHICLE_JOURNEYS',
+ json: state
+ })
+ ).toEqual(state)
+ })
+
+ it('should handle UPDATE_TIME', () => {
+ const val = '33', subIndex = 0, index = 0, timeUnit = 'minute', isDeparture = true, isArrivalsToggled = true
+ let newVJAS = [{
+ delta: 638,
+ arrival_time : {
+ hour: '11',
+ minute: '55'
+ },
+ departure_time : {
+ hour: '22',
+ minute: '33'
+ },
+ stop_area_object_id : "FR:92024:ZDE:420553:STIF"
+ }]
+ let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS})
+ expect(
+ vjReducer(state, {
+ type: 'UPDATE_TIME',
+ val,
+ subIndex,
+ index,
+ timeUnit,
+ isDeparture,
+ isArrivalsToggled
+ })
+ ).toEqual([newVJ, state[1]])
+ })
+
+ it('should handle SELECT_VEHICLEJOURNEY', () => {
+ const index = 1
+ const newVJ = Object.assign({}, state[1], {selected: true})
+ expect(
+ vjReducer(state, {
+ type: 'SELECT_VEHICLEJOURNEY',
+ index
+ })
+ ).toEqual([state[0], newVJ])
+ })
+
+ it('should handle CANCEL_SELECTION', () => {
+ const index = 1
+ const newVJ = Object.assign({}, state[0], {selected: false})
+ expect(
+ vjReducer(state, {
+ type: 'CANCEL_SELECTION',
+ index
+ })
+ ).toEqual([newVJ, state[1]])
+ })
+
+ it('should handle DELETE_VEHICLEJOURNEYS', () => {
+ const newVJ = Object.assign({}, state[0], {deletable: true, selected: false})
+ expect(
+ vjReducer(state, {
+ type: 'DELETE_VEHICLEJOURNEYS'
+ })
+ ).toEqual([newVJ, state[1]])
+ })
+
+ it('should handle SHIFT_VEHICLEJOURNEY', () => {
+ let newVJAS = [{
+ delta: 627,
+ arrival_time : {
+ hour: '12',
+ minute: '00'
+ },
+ departure_time : {
+ hour: '22',
+ minute: '27'
+ },
+ stop_area_object_id : "FR:92024:ZDE:420553:STIF"
+ }]
+ let fakeData = {
+ objectid: {value : '11'},
+ additional_time: {value: '5'}
+ }
+ let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS})
+ expect(
+ vjReducer(state, {
+ type: 'SHIFT_VEHICLEJOURNEY',
+ data: fakeData
+ })
+ ).toEqual([newVJ, state[1]])
+ })
+
+ it('should handle DUPLICATE_VEHICLEJOURNEY', () => {
+ let newVJAS = [{
+ delta: 627,
+ arrival_time : {
+ hour: '12',
+ minute: '00'
+ },
+ departure_time : {
+ hour: '22',
+ minute: '27'
+ },
+ stop_area_object_id : "FR:92024:ZDE:420553:STIF"
+ }]
+ let fakeData = {
+ duplicate_number: {value : 1},
+ additional_time: {value: '5'}
+ }
+ let newVJ = Object.assign({}, state[0], {vehicle_journey_at_stops: newVJAS, selected: false})
+ newVJ.published_journey_name = state[0].published_journey_name + '-0'
+ delete newVJ['objectid']
+ expect(
+ vjReducer(state, {
+ type: 'DUPLICATE_VEHICLEJOURNEY',
+ data: fakeData
+ })
+ ).toEqual([state[0], newVJ, state[1]])
+ })
+
+ it('should handle EDIT_VEHICLEJOURNEY', () => {
+ let fakeData = {
+ published_journey_name: {value : 'test'},
+ published_journey_identifier: {value: 'test'}
+ }
+ let newVJ = Object.assign({}, state[0], {published_journey_name: fakeData.published_journey_name.value, published_journey_identifier: fakeData.published_journey_identifier.value})
+ expect(
+ vjReducer(state, {
+ type: 'EDIT_VEHICLEJOURNEY',
+ data: fakeData
+ })
+ ).toEqual([newVJ, state[1]])
+ })
+
+
+ it('should handle EDIT_VEHICLEJOURNEYS_CALENDARS', () => {
+ let newState = JSON.parse(JSON.stringify(state))
+ newState.map((vj, i) =>{
+ return Object.assign({}, vj, {time_tables : vj.time_tables[0]})
+ })
+ expect(
+ vjReducer(state, {
+ type: 'EDIT_VEHICLEJOURNEYS_CALENDARS',
+ vehicleJourneys: newState
+ })
+ ).toEqual(newState)
+ })
+})
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 91f519a59..4f55ba774 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -1,6 +1,55 @@
require 'spec_helper'
describe Chouette::VehicleJourney, :type => :model do
+ describe "state_update" do
+ def vehicle_journey_to_state vj
+ vj.attributes.slice('objectid', 'published_journey_name', 'journey_pattern_id').tap do |item|
+ item['vehicle_journey_at_stops'] = []
+
+ vj.vehicle_journey_at_stops.each do |vs|
+ at_stops = {'stop_area_object_id' => vs.stop_point.stop_area.objectid }
+ [:id, :connecting_service_id, :boarding_alighting_possibility].map do |att|
+ at_stops[att.to_s] = vs.send(att) unless vs.send(att).nil?
+ end
+
+ [:arrival_time, :departure_time].map do |att|
+ at_stops[att.to_s] = {
+ 'hour' => vs.send(att).strftime('%H'),
+ 'minute' => vs.send(att).strftime('%M'),
+ }
+ end
+ item['vehicle_journey_at_stops'] << at_stops
+ end
+ end
+ end
+
+ let(:route) { create :route }
+ let(:vehicle_journey) { create :vehicle_journey, route: route }
+ let(:state) { vehicle_journey_to_state(vehicle_journey) }
+
+ it 'should update arrival_time' do
+ stop = state['vehicle_journey_at_stops'].first
+ stop['arrival_time']['hour'] = "10"
+ stop['arrival_time']['minute'] = "10"
+
+ vehicle_journey.update_vehicle_journey_at_stops_state(state['vehicle_journey_at_stops'])
+ stop = vehicle_journey.vehicle_journey_at_stops.find(stop['id'])
+ expect(stop.arrival_time).to eq('2000-01-01 10:10:00 UTC')
+ end
+
+ it 'should update departure_time' do
+ stop = state['vehicle_journey_at_stops'].first
+ stop['departure_time']['hour'] = "12"
+ stop['departure_time']['minute'] = "12"
+
+ vehicle_journey.update_vehicle_journey_at_stops_state(state['vehicle_journey_at_stops'])
+ stop = vehicle_journey.vehicle_journey_at_stops.find(stop['id'])
+ expect(stop.departure_time).to eq('2000-01-01 12:12:00 UTC')
+ end
+ end
+
+
+
subject { create(:vehicle_journey_odd) }
describe "in_relation_to_a_journey_pattern methods" do