diff options
Diffstat (limited to 'spec/javascripts')
| -rw-r--r-- | spec/javascripts/vehicle_journeys/actions_spec.js | 36 | ||||
| -rw-r--r-- | spec/javascripts/vehicle_journeys/reducers/filters_spec.js | 99 |
2 files changed, 134 insertions, 1 deletions
diff --git a/spec/javascripts/vehicle_journeys/actions_spec.js b/spec/javascripts/vehicle_journeys/actions_spec.js index 56a2e8511..301f5d8ba 100644 --- a/spec/javascripts/vehicle_journeys/actions_spec.js +++ b/spec/javascripts/vehicle_journeys/actions_spec.js @@ -270,3 +270,39 @@ describe('when using select2 to pick a timetable', () => { 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: 'RESET_FILTERS', + } + expect(actions.resetFilters()).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) + }) +}) diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js index ecb80f3c3..53ac5d75b 100644 --- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js +++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js @@ -3,9 +3,34 @@ 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, + toggleArrivals: false, + query: { + interval: { + start:{ + hour: '11', + minute: '11' + }, + end:{ + hour: '22', + minute: '22' + } + }, + journeyPattern: {}, + timetable: {}, + withoutSchedule: false + } } }) @@ -23,4 +48,76 @@ describe('filters reducer', () => { ).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) + }) + }) |
