diff options
| author | cedricnjanga | 2017-08-21 11:58:13 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-08-21 11:58:13 +0200 |
| commit | efa8b6072e35f09d580f227b0b3175260c145fea (patch) | |
| tree | 89858695fd08ede5214730239f57067247012bc7 /spec/javascripts | |
| parent | 8176b98b2e84ce62299f79a048156c0ec443e49e (diff) | |
| download | chouette-core-efa8b6072e35f09d580f227b0b3175260c145fea.tar.bz2 | |
Add the possibility to add included days in a period
Diffstat (limited to 'spec/javascripts')
| -rw-r--r-- | spec/javascripts/time_table/actions_spec.js | 36 | ||||
| -rw-r--r-- | spec/javascripts/time_table/reducers/modal_spec.js | 10 | ||||
| -rw-r--r-- | spec/javascripts/time_table/reducers/pagination_spec.js | 26 | ||||
| -rw-r--r-- | spec/javascripts/time_table/reducers/timetable_spec.js | 118 |
4 files changed, 160 insertions, 30 deletions
diff --git a/spec/javascripts/time_table/actions_spec.js b/spec/javascripts/time_table/actions_spec.js index f32e93327..bd6f3b1aa 100644 --- a/spec/javascripts/time_table/actions_spec.js +++ b/spec/javascripts/time_table/actions_spec.js @@ -169,28 +169,52 @@ describe('actions', () => { expect(actions.validatePeriodForm(modalProps, timeTablePeriods, metas, timetableInDates)).toEqual(expectedAction) }) - it('should create an action to include date in period', () => { + it('should create an action to add an included date', () => { let index = 1 let date = actions.formatDate(new Date) const expectedAction = { - type: 'INCLUDE_DATE_IN_PERIOD', + type: 'ADD_INCLUDED_DATE', index, dayTypes, date } - expect(actions.includeDateInPeriod(index, dayTypes, date)).toEqual(expectedAction) + expect(actions.addIncludedDate(index, dayTypes, date)).toEqual(expectedAction) }) - it('should create an action to exclude date from period', () => { + it('should create an action to remove an included dat', () => { let index = 1 let date = actions.formatDate(new Date) const expectedAction = { - type: 'EXCLUDE_DATE_FROM_PERIOD', + type: 'REMOVE_INCLUDED_DATE', index, dayTypes, date } - expect(actions.excludeDateFromPeriod(index, dayTypes, date)).toEqual(expectedAction) + expect(actions.removeIncludedDate(index, dayTypes, date)).toEqual(expectedAction) + }) + + it('should create an action to add an excluded date in period', () => { + let index = 1 + let date = actions.formatDate(new Date) + const expectedAction = { + type: 'ADD_EXCLUDED_DATE', + index, + dayTypes, + date + } + expect(actions.addExcludedDate(index, dayTypes, date)).toEqual(expectedAction) + }) + + it('should create an action to remove an excluded date from period', () => { + let index = 1 + let date = actions.formatDate(new Date) + const expectedAction = { + type: 'REMOVE_EXCLUDED_DATE', + index, + dayTypes, + date + } + expect(actions.removeExcludedDate(index, dayTypes, date)).toEqual(expectedAction) }) it('should create an action to open confirm modal', () => { diff --git a/spec/javascripts/time_table/reducers/modal_spec.js b/spec/javascripts/time_table/reducers/modal_spec.js index 160f3955f..9e8220a51 100644 --- a/spec/javascripts/time_table/reducers/modal_spec.js +++ b/spec/javascripts/time_table/reducers/modal_spec.js @@ -171,12 +171,14 @@ describe('modal reducer', () => { let ttperiods = [] let ttdates = [] + let metas = [] expect( modalReducer(state, { type: 'VALIDATE_PERIOD_FORM', modalProps : modProps, timeTablePeriods: ttperiods, + metas: metas, timetableInDates: ttdates }) ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) @@ -287,9 +289,12 @@ describe('modal reducer', () => { index: false, error: '' } - let ttperiods3 = [] + let ttperiods3 = [] let ttdates3 = [{date: "2017-08-04", include_date: true}] + let metas = { + day_types: [true,true,true,true,true,true,true] + } let newModalProps3 = { active: true, @@ -312,7 +317,8 @@ describe('modal reducer', () => { type: 'VALIDATE_PERIOD_FORM', modalProps : modProps3, timeTablePeriods: ttperiods3, - timetableInDates: ttdates3 + timetableInDates: ttdates3, + metas: metas }) ).toEqual(Object.assign({}, state3, {modalProps: newModalProps3})) }) diff --git a/spec/javascripts/time_table/reducers/pagination_spec.js b/spec/javascripts/time_table/reducers/pagination_spec.js index 5da58427e..3c1edb9c5 100644 --- a/spec/javascripts/time_table/reducers/pagination_spec.js +++ b/spec/javascripts/time_table/reducers/pagination_spec.js @@ -76,20 +76,38 @@ describe('pagination reducer', () => { ).toEqual(Object.assign({}, state, {currentPage : page, stateChanged: false})) }) - it('should handle INCLUDE_DATE_IN_PERIOD', () => { + it('should handle ADD_INCLUDED_DATE', () => { expect( paginationReducer(state, { - type: 'INCLUDE_DATE_IN_PERIOD' + type: 'ADD_INCLUDED_DATE' }) ).toEqual(Object.assign({}, state, {stateChanged: true})) }) - it('should handle EXCLUDE_DATE_FROM_PERIOD', () => { + + it('should handle REMOVE_INCLUDED_DATE', () => { + expect( + paginationReducer(state, { + type: 'REMOVE_INCLUDED_DATE' + }) + ).toEqual(Object.assign({}, state, {stateChanged: true})) + }) + + it('should handle ADD_EXCLUDED_DATE', () => { expect( paginationReducer(state, { - type: 'EXCLUDE_DATE_FROM_PERIOD' + type: 'ADD_EXCLUDED_DATE' }) ).toEqual(Object.assign({}, state, {stateChanged: true})) }) + + it('should handle REMOVE_EXCLUDED_DATE', () => { + expect( + paginationReducer(state, { + type: 'REMOVE_EXCLUDED_DATE' + }) + ).toEqual(Object.assign({}, state, {stateChanged: true})) + }) + it('should handle DELETE_PERIOD', () => { expect( paginationReducer(state, { diff --git a/spec/javascripts/time_table/reducers/timetable_spec.js b/spec/javascripts/time_table/reducers/timetable_spec.js index 805a29b5f..515efa4c8 100644 --- a/spec/javascripts/time_table/reducers/timetable_spec.js +++ b/spec/javascripts/time_table/reducers/timetable_spec.js @@ -12,8 +12,6 @@ let current_month = [{"day":"lundi","date":"2017-05-01","wday":1,"wnumber":"18", let newCurrentMonth = [{"day":"lundi","date":"2017-05-01","wday":1,"wnumber":"18","mday":1,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mardi","date":"2017-05-02","wday":2,"wnumber":"18","mday":2,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mercredi","date":"2017-05-03","wday":3,"wnumber":"18","mday":3,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"jeudi","date":"2017-05-04","wday":4,"wnumber":"18","mday":4,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"vendredi","date":"2017-05-05","wday":5,"wnumber":"18","mday":5,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"samedi","date":"2017-05-06","wday":6,"wnumber":"18","mday":6,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"dimanche","date":"2017-05-07","wday":0,"wnumber":"18","mday":7,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"lundi","date":"2017-05-08","wday":1,"wnumber":"19","mday":8,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mardi","date":"2017-05-09","wday":2,"wnumber":"19","mday":9,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mercredi","date":"2017-05-10","wday":3,"wnumber":"19","mday":10,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"jeudi","date":"2017-05-11","wday":4,"wnumber":"19","mday":11,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"vendredi","date":"2017-05-12","wday":5,"wnumber":"19","mday":12,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"samedi","date":"2017-05-13","wday":6,"wnumber":"19","mday":13,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"dimanche","date":"2017-05-14","wday":0,"wnumber":"19","mday":14,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"lundi","date":"2017-05-15","wday":1,"wnumber":"20","mday":15,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mardi","date":"2017-05-16","wday":2,"wnumber":"20","mday":16,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mercredi","date":"2017-05-17","wday":3,"wnumber":"20","mday":17,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"jeudi","date":"2017-05-18","wday":4,"wnumber":"20","mday":18,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"vendredi","date":"2017-05-19","wday":5,"wnumber":"20","mday":19,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"samedi","date":"2017-05-20","wday":6,"wnumber":"20","mday":20,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"dimanche","date":"2017-05-21","wday":0,"wnumber":"20","mday":21,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"lundi","date":"2017-05-22","wday":1,"wnumber":"21","mday":22,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mardi","date":"2017-05-23","wday":2,"wnumber":"21","mday":23,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mercredi","date":"2017-05-24","wday":3,"wnumber":"21","mday":24,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"jeudi","date":"2017-05-25","wday":4,"wnumber":"21","mday":25,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"vendredi","date":"2017-05-26","wday":5,"wnumber":"21","mday":26,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"samedi","date":"2017-05-27","wday":6,"wnumber":"21","mday":27,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"dimanche","date":"2017-05-28","wday":0,"wnumber":"21","mday":28,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"lundi","date":"2017-05-29","wday":1,"wnumber":"22","mday":29,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mardi","date":"2017-05-30","wday":2,"wnumber":"22","mday":30,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mercredi","date":"2017-05-31","wday":3,"wnumber":"22","mday":31,"include_date":false,"excluded_date":false,"in_periods":false}] -let time_table_dates = [] - let json = { current_month: current_month, current_periode_range: current_periode_range, @@ -46,7 +44,7 @@ describe('timetable reducer with empty state', () => { current_periode_range: current_periode_range, periode_range: periode_range, time_table_periods: time_table_periods, - time_table_dates: time_table_dates + time_table_dates: [] } expect( timetableReducer(state, { @@ -125,24 +123,46 @@ describe('timetable reducer with filled state', () => { ).toEqual(Object.assign({}, state, {current_periode_range: newPage})) }) - it('should handle DELETE_PERIOD', () => { - state.time_table_periods[0].deleted = true + it('should handle DELETE_PERIOD and remove excluded days that were in period', () => { + state.time_table_dates.push({date: "2017-05-01", in_out: false}) + state.current_month[0].excluded_date = true + state.time_table_periods[3].deleted = true + + let begin = new Date(state.time_table_periods[3].period_start) + let end = new Date(state.time_table_periods[3].period_end) + + let newState = Object.assign({}, state, { + time_table_dates: [], + current_month: state.current_month.map((d, i) => { + if (new Date(d.date) >= begin && new Date(d.date) <= end) { + d.excluded_date = false + d.in_periods = false + } + return d + }) + }) expect( timetableReducer(state, { type: 'DELETE_PERIOD', - index: 0, + index: 3, dayTypes: arrDayTypes }) - ).toEqual(state) + ).toEqual(newState) }) - it('should handle INCLUDE_DATE_IN_PERIOD and add in_day if TT doesnt have it', () => { + it('should handle ADD_INCLUDED_DATE', () => { let newDates = state.time_table_dates.concat({date: "2017-05-05", in_out: true}) - let newState = Object.assign({}, state, {time_table_dates: newDates}) - state.current_month[4].include_date = true + + let newCM = newCurrentMonth.map((d,i) => { + if (i == 4) d.include_date = true + return d + }) + + let newState = Object.assign({}, state, {time_table_dates: newDates, current_month: newCM}) + expect( timetableReducer(state, { - type: 'INCLUDE_DATE_IN_PERIOD', + type: 'ADD_INCLUDED_DATE', index: 4, dayTypes: arrDayTypes, date: "2017-05-05" @@ -150,13 +170,20 @@ describe('timetable reducer with filled state', () => { ).toEqual(newState) }) - it('should handle INCLUDE_DATE_IN_PERIOD and remove in_day if TT has it', () => { + it('should handle REMOVE_INCLUDED_DATE', () => { state.current_month[4].include_date = true state.time_table_dates.push({date: "2017-05-05", in_out: true}) - let newState = Object.assign({}, state, {time_table_dates: []}) + + let newCM = newCurrentMonth.map((d,i) => { + if (i == 4) d.include_date = false + return d + }) + + let newDates = state.time_table_dates.filter(d => d.date != "2017-05-05" && d.in_out != true ) + let newState = Object.assign({}, state, {time_table_dates: newDates, current_month: newCM}) expect( timetableReducer(state, { - type: 'INCLUDE_DATE_IN_PERIOD', + type: 'REMOVE_INCLUDED_DATE', index: 4, dayTypes: arrDayTypes, date: "2017-05-05" @@ -164,13 +191,19 @@ describe('timetable reducer with filled state', () => { ).toEqual(newState) }) - it('should handle EXCLUDE_DATE_FROM_PERIOD and add out_day if TT doesnt have it', () => { + it('should handle ADD_EXCLUDED_DATE', () => { let newDates = state.time_table_dates.concat({date: "2017-05-01", in_out: false}) - let newState = Object.assign({}, state, {time_table_dates: newDates}) + + let newCM = newCurrentMonth.map((d,i) => { + if (i == 0) d.include_date = false + return d + }) + + let newState = Object.assign({}, state, {time_table_dates: newDates, current_month: newCM}) state.current_month[0].excluded_date = true expect( timetableReducer(state, { - type: 'EXCLUDE_DATE_FROM_PERIOD', + type: 'ADD_EXCLUDED_DATE', index: 0, dayTypes: arrDayTypes, date: "2017-05-01" @@ -178,7 +211,7 @@ describe('timetable reducer with filled state', () => { ).toEqual(newState) }) - it('should handle EXCLUDE_DATE_FROM_PERIOD and remove out_day if TT has it', () => { + it('should handle REMOVE_EXCLUDED_DATE', () => { state.time_table_dates = [{date: "2017-05-01", in_out: false}] state.current_month[0].excluded_date = true let newState = Object.assign({}, state, {time_table_dates: []}) @@ -222,4 +255,53 @@ describe('timetable reducer with filled state', () => { }) ).toEqual(newState) }) + + it('should handle VALIDATE_PERIOD_FORM and update period if modalProps index != false', () => { + + let begin = new Date(state.time_table_periods[0].period_start) + let end = new Date(state.time_table_periods[0].period_end) + let newCM = newCurrentMonth.map((d) => { + if (new Date (d.date) >= begin && new Date(d.date) <= end) { + d.in_periods = false + d.excluded_date = false + } + return d + }) + + let newPeriods = state.time_table_periods.map( (p,i) => { + if (i == 0) { + p.period_start = "2018-05-15" + p.period_end = "2018-05-24" + } + return p + }) + let newState = Object.assign({}, state, {time_table_periods: newPeriods}) + + let modalProps = { + active: false, + begin: { + day: '15', + month: '05', + year: '2018' + }, + end: { + day: '24', + month: '05', + year: '2018' + }, + error: '', + index: 0 + } + expect( + timetableReducer(state, { + type: 'VALIDATE_PERIOD_FORM', + modalProps: modalProps, + timeTablePeriods: state.time_table_periods, + metas: { + day_types: arrDayTypes + }, + timetableInDates: state.time_table_dates.filter(d => d.in_out == true) + }) + ).toEqual(newState) + }) }) |
