diff options
| -rw-r--r-- | app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js | 11 | ||||
| -rw-r--r-- | spec/javascripts/time_table/reducers/timetable_spec.js | 13 |
2 files changed, 24 insertions, 0 deletions
diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js index 64db1ccc1..84d90d53c 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js +++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js @@ -59,6 +59,17 @@ const timetable = (state = {}, action) => { }) newState = _.assign({}, state, {current_month: newCMe, time_table_dates: newDates}) return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)}) + case 'UPDATE_DAY_TYPES': + // We get the week days of the activated day types to reject the out_dates that that are out of newDayTypes + let weekDays = _.reduce(action.dayTypes, (array, dt, i) => { + if (dt) array.push(i) + return array + }, []) + + newDates = _.reject(state.time_table_dates, (d) => { + return d.in_out == false && !weekDays.includes(new Date(d.date).getDay()) + }) + return _.assign({}, state, {time_table_dates: newDates}) case 'UPDATE_CURRENT_MONTH_FROM_DAYTYPES': return _.assign({}, state, {current_month: actions.updateSynthesis(state, action.dayTypes)}) case 'VALIDATE_PERIOD_FORM': diff --git a/spec/javascripts/time_table/reducers/timetable_spec.js b/spec/javascripts/time_table/reducers/timetable_spec.js index 805a29b5f..5b3561a5f 100644 --- a/spec/javascripts/time_table/reducers/timetable_spec.js +++ b/spec/javascripts/time_table/reducers/timetable_spec.js @@ -192,6 +192,19 @@ describe('timetable reducer with filled state', () => { ).toEqual(newState) }) + it('should handle UPDATE_DAY_TYPES and remove out_day that are out of day types', () => { + state.time_table_dates = [{date: "2017-05-01", in_out: false}] + let newArrDayTypes = arrDayTypes.slice(0) + newArrDayTypes[1] = false + let newState = Object.assign({}, state, {time_table_dates: []}) + expect( + timetableReducer(state, { + type: 'UPDATE_DAY_TYPES', + dayTypes: newArrDayTypes + }).time_table_dates + ).toEqual([]) + }) + it('should handle VALIDATE_PERIOD_FORM and add period if modalProps index = false', () => { let newPeriods = state.time_table_periods.concat({"period_start": "2018-05-15", "period_end": "2018-05-24"}) let newState = Object.assign({}, state, {time_table_periods: newPeriods}) |
