aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-08-16 01:09:50 +0200
committercedricnjanga2017-08-16 09:28:48 +0200
commit44fd650c7951176999e6db8b1bc92c2f29dc3ec2 (patch)
tree7a15a418f02e0c093c2eb134e8a5790c37140781
parentefbd9f90ae41b357ad8559fbc3b29fc59524bb73 (diff)
downloadchouette-core-44fd650c7951176999e6db8b1bc92c2f29dc3ec2.tar.bz2
Update JS timetable specs
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/actions/index.js32
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/components/ErrorModal.js2
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js4
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js4
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js1
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js5
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js8
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/index.js15
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/reducers/modal.js2
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js2
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js12
-rw-r--r--spec/javascripts/time_table/actions_spec.js18
-rw-r--r--spec/javascripts/time_table/reducers/modal_spec.js6
-rw-r--r--spec/javascripts/time_table/reducers/timetable_spec.js68
14 files changed, 117 insertions, 62 deletions
diff --git a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
index f88d64d4d..61667f5ab 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
@@ -105,22 +105,24 @@ const actions = {
group,
selectType
}),
- validatePeriodForm: (modalProps, timeTablePeriods, metas, currentMonthDaysIn) => ({
+ validatePeriodForm: (modalProps, timeTablePeriods, metas, timetableInDates) => ({
type: 'VALIDATE_PERIOD_FORM',
modalProps,
timeTablePeriods,
metas,
- currentMonthDaysIn
+ timetableInDates
}),
- includeDateInPeriod: (index, dayTypes) => ({
+ includeDateInPeriod: (index, dayTypes, date) => ({
type: 'INCLUDE_DATE_IN_PERIOD',
index,
- dayTypes
+ dayTypes,
+ date
}),
- excludeDateFromPeriod: (index, dayTypes) => ({
+ excludeDateFromPeriod: (index, dayTypes, date) => ({
type: 'EXCLUDE_DATE_FROM_PERIOD',
index,
- dayTypes
+ dayTypes,
+ date
}),
openConfirmModal : (callback) => ({
type : 'OPEN_CONFIRM_MODAL',
@@ -166,16 +168,15 @@ const actions = {
// We compare periods & currentDate, to determine if it is included or not
let testDate = false
periods.map((p, i) => {
- if(p.deleted){
- return false
- }
+ if (p.deleted) return false
+
let begin = new Date(p.period_start)
let end = new Date(p.period_end)
if(testDate === false){
if(currentDate >= begin && currentDate <= end) {
testDate = true
- p.include_date = false
+ // p.include_date = false
}
}
})
@@ -220,12 +221,12 @@ const actions = {
})
return error
},
- checkErrorsInDates: (start, end, days) => {
+ checkErrorsInDates: (start, end, in_days) => {
let error = ''
start = new Date(start)
end = new Date(end)
- _.each(days, ({date}) => {
+ _.each(in_days, ({date}) => {
if (start <= new Date(date) && end >= new Date(date)) {
error = 'Une période ne peut chevaucher une date dans un calendrier'
}
@@ -310,6 +311,13 @@ const actions = {
return errorKey
}
+ },
+ checkIfTTHasDate: (dates, date) => {
+ if (_.some(dates, date)) {
+ return _.reject(dates, ['date', date.date])
+ } else {
+ return dates.concat(date)
+ }
}
}
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/ErrorModal.js b/app/assets/javascripts/es6_browserified/time_tables/components/ErrorModal.js
index 84af28f30..4e8f7e363 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/components/ErrorModal.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/components/ErrorModal.js
@@ -3,7 +3,7 @@ var Component = require('react').Component
var PropTypes = require('react').PropTypes
var errorModalMessage = require('../actions').errorModalMessage
-const ErrorModal = ({dispatch, modal, onModalClose}) => (
+const ErrorModal = ({dispatch, modal, I18n, onModalClose}) => (
<div className={ 'modal fade ' + ((modal.type == 'error') ? 'in' : '') } id='ErrorModal'>
<div className='modal-container'>
<div className='modal-dialog'>
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js b/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js
index 10b558373..4879e537f 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js
@@ -20,7 +20,7 @@ class ExceptionsInDay extends Component {
data-actiontype='remove'
onClick={(e) => {
$(e.currentTarget).toggleClass('active')
- this.props.onExcludeDateFromPeriod(this.props.index, this.props.metas.day_types)
+ this.props.onExcludeDateFromPeriod(this.props.index, this.props.metas.day_types, this.props.currentDate)
}}
>
<span className='fa fa-times'></span>
@@ -36,7 +36,7 @@ class ExceptionsInDay extends Component {
data-actiontype='add'
onClick={(e) => {
$(e.currentTarget).toggleClass('active')
- this.props.onIncludeDateInPeriod(this.props.index, this.props.metas.day_types)
+ this.props.onIncludeDateInPeriod(this.props.index, this.props.metas.day_types, this.props.currentDate)
}}
>
<span className='fa fa-plus'></span>
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js
index 1426a5908..3234a3fd7 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodForm.js
@@ -32,7 +32,7 @@ const makeYearsOptions = (yearSelected) => {
return arr
}
-const PeriodForm = ({modal, timetable, metas, currentMonthDaysIn, onOpenAddPeriodForm, onClosePeriodForm, onUpdatePeriodForm, onValidatePeriodForm}) => (
+const PeriodForm = ({modal, timetable, metas, onOpenAddPeriodForm, onClosePeriodForm, onUpdatePeriodForm, onValidatePeriodForm}) => (
<div className="container-fluid">
<div className="row">
<div className="col lg-6 col-lg-offset-3">
@@ -108,7 +108,7 @@ const PeriodForm = ({modal, timetable, metas, currentMonthDaysIn, onOpenAddPerio
<button
type='button'
className='btn btn-outline-primary mr-sm'
- onClick={() => onValidatePeriodForm(modal.modalProps, timetable.time_table_periods, metas, currentMonthDaysIn)}
+ onClick={() => onValidatePeriodForm(modal.modalProps, timetable.time_table_periods, metas, _.filter(timetable.time_table_dates, ['in_out', true]))}
>
Valider
</button>
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js b/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js
index d562655b9..3af1a11a4 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js
@@ -79,6 +79,7 @@ class Timetable extends Component{
<ExceptionsInDay
index={i}
value={this.props.timetable}
+ currentDate={d.date}
metas={this.props.metas}
blueDaytype={this.props.metas.day_types[d.wday]}
onExcludeDateFromPeriod={this.props.onExcludeDateFromPeriod}
diff --git a/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js b/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js
index 813f9d795..723a4a7fb 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/containers/PeriodForm.js
@@ -8,7 +8,6 @@ const mapStateToProps = (state) => {
modal: state.modal,
timetable: state.timetable,
metas: state.metas,
- currentMonthDaysIn: _.filter(state.timetable.current_month, ['include_date', true])
}
}
@@ -28,8 +27,8 @@ const mapDispatchToProps = (dispatch) => {
val = (val < 10) ? '0' + String(val) : String(val)
dispatch(actions.updatePeriodForm(val, group, 'day'))
},
- onValidatePeriodForm: (modalProps, timeTablePeriods, metas, currentMonthDaysIn) => {
- dispatch(actions.validatePeriodForm(modalProps, timeTablePeriods, metas, currentMonthDaysIn))
+ onValidatePeriodForm: (modalProps, timeTablePeriods, metas, timetableInDates) => {
+ dispatch(actions.validatePeriodForm(modalProps, timeTablePeriods, metas, timetableInDates))
}
}
}
diff --git a/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js b/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js
index c6b5fcc6b..639a1e2ab 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js
@@ -15,11 +15,11 @@ const mapDispatchToProps = (dispatch) => {
onDeletePeriod: (index, dayTypes) =>{
dispatch(actions.deletePeriod(index, dayTypes))
},
- onExcludeDateFromPeriod: (index, dayTypes) => {
- dispatch(actions.excludeDateFromPeriod(index, dayTypes))
+ onExcludeDateFromPeriod: (index, dayTypes, date) => {
+ dispatch(actions.excludeDateFromPeriod(index, dayTypes, date))
},
- onIncludeDateInPeriod: (index, dayTypes) => {
- dispatch(actions.includeDateInPeriod(index, dayTypes))
+ onIncludeDateInPeriod: (index, dayTypes, date) => {
+ dispatch(actions.includeDateInPeriod(index, dayTypes, date))
},
onOpenEditPeriodForm: (period, index) => {
dispatch(actions.openEditPeriodForm(period, index))
diff --git a/app/assets/javascripts/es6_browserified/time_tables/index.js b/app/assets/javascripts/es6_browserified/time_tables/index.js
index 4a36b6f92..a91747991 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/index.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/index.js
@@ -6,10 +6,10 @@ var timeTablesApp = require('./reducers')
var App = require('./containers/App')
// logger, DO NOT REMOVE
-var applyMiddleware = require('redux').applyMiddleware
-var createLogger = require('redux-logger')
-var thunkMiddleware = require('redux-thunk').default
-var promise = require('redux-promise')
+// var applyMiddleware = require('redux').applyMiddleware
+// var createLogger = require('redux-logger')
+// var thunkMiddleware = require('redux-thunk').default
+// var promise = require('redux-promise')
var initialState = {
status: {
@@ -22,7 +22,8 @@ var initialState = {
current_month: [],
current_periode_range: '',
periode_range: [],
- time_table_periods: []
+ time_table_periods: [],
+ time_table_dates: []
},
metas: {
comment: '',
@@ -57,12 +58,12 @@ var initialState = {
confirmModal: {}
}
}
-const loggerMiddleware = createLogger()
+// const loggerMiddleware = createLogger()
let store = createStore(
timeTablesApp,
initialState,
- applyMiddleware(thunkMiddleware, promise, loggerMiddleware)
+ // applyMiddleware(thunkMiddleware, promise, loggerMiddleware)
)
render(
diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/modal.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/modal.js
index eaa5ad385..3fe4e43a2 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/reducers/modal.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/modal.js
@@ -64,7 +64,7 @@ const modal = (state = {}, action) => {
}
let newPeriods = JSON.parse(JSON.stringify(action.timeTablePeriods))
- let newDays = JSON.parse(JSON.stringify(action.currentMonthDaysIn))
+ let newDays = JSON.parse(JSON.stringify(action.timetableInDates))
let error = actions.checkErrorsInPeriods(period_start, period_end, action.modalProps.index, newPeriods)
if (error == '') error = actions.checkErrorsInDates(period_start, period_end, newDays)
newModalProps.error = error
diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js
index 3d96fb7b7..45fec6b5f 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js
@@ -26,6 +26,8 @@ const pagination = (state = {}, action) => {
case 'VALIDATE_PERIOD_FORM':
case 'UPDATE_COMMENT':
case 'UPDATE_COLOR':
+ case 'UPDATE_DAY_TYPES':
+ case 'UPDATE_CURRENT_MONTH_FROM_DAYTYPES':
toggleOnConfirmModal('modal')
return _.assign({}, state, {stateChanged: true})
default:
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 057e9a380..64db1ccc1 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/timetable.js
@@ -1,6 +1,7 @@
const _ = require('lodash')
var actions = require('../actions')
let newState = {}
+let newDates = []
const timetable = (state = {}, action) => {
switch (action.type) {
@@ -9,7 +10,8 @@ const timetable = (state = {}, action) => {
current_month: action.json.current_month,
current_periode_range: action.json.current_periode_range,
periode_range: action.json.periode_range,
- time_table_periods: action.json.time_table_periods
+ time_table_periods: action.json.time_table_periods,
+ time_table_dates: action.json.time_table_dates
})
return _.assign({}, fetchedState, {current_month: actions.updateSynthesis(fetchedState, actions.strToArrayDayTypes(action.json.day_types))})
case 'RECEIVE_MONTH':
@@ -38,22 +40,24 @@ const timetable = (state = {}, action) => {
newState = _.assign({}, state, {time_table_periods : ttperiods})
return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)})
case 'INCLUDE_DATE_IN_PERIOD':
+ newDates = actions.checkIfTTHasDate(state.time_table_dates, {date: action.date, in_out: true})
let newCMi = state.current_month.map((d, i) => {
if(i == action.index){
d.include_date = !d.include_date
}
return d
})
- newState = _.assign({}, state, {current_month: newCMi})
+ newState = _.assign({}, state, {current_month: newCMi, time_table_dates: newDates})
return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)})
case 'EXCLUDE_DATE_FROM_PERIOD':
+ newDates = actions.checkIfTTHasDate(state.time_table_dates, {date: action.date, in_out: false})
let newCMe = state.current_month.map((d, i) => {
if(i == action.index){
d.excluded_date = !d.excluded_date
}
return d
})
- newState = _.assign({}, state, {current_month: newCMe})
+ newState = _.assign({}, state, {current_month: newCMe, time_table_dates: newDates})
return _.assign({}, newState, {current_month: actions.updateSynthesis(newState, action.dayTypes)})
case 'UPDATE_CURRENT_MONTH_FROM_DAYTYPES':
return _.assign({}, state, {current_month: actions.updateSynthesis(state, action.dayTypes)})
@@ -64,7 +68,7 @@ const timetable = (state = {}, action) => {
return state
}
let newPeriods = JSON.parse(JSON.stringify(action.timeTablePeriods))
- let newDays = JSON.parse(JSON.stringify(action.currentMonthDaysIn))
+ let newDays = JSON.parse(JSON.stringify(action.timetableInDates))
let error = actions.checkErrorsInPeriods(period_start, period_end, action.modalProps.index, newPeriods)
if (error == '') error = actions.checkErrorsInDates(period_start, period_end, newDays)
diff --git a/spec/javascripts/time_table/actions_spec.js b/spec/javascripts/time_table/actions_spec.js
index d3618834a..f32e93327 100644
--- a/spec/javascripts/time_table/actions_spec.js
+++ b/spec/javascripts/time_table/actions_spec.js
@@ -158,35 +158,39 @@ describe('actions', () => {
let modalProps = {}
let timeTablePeriods = []
let metas = {}
- let currentMonthDaysIn = []
+ let timetableInDates = []
const expectedAction = {
type: 'VALIDATE_PERIOD_FORM',
modalProps,
timeTablePeriods,
metas,
- currentMonthDaysIn
+ timetableInDates
}
- expect(actions.validatePeriodForm(modalProps, timeTablePeriods, metas, currentMonthDaysIn)).toEqual(expectedAction)
+ expect(actions.validatePeriodForm(modalProps, timeTablePeriods, metas, timetableInDates)).toEqual(expectedAction)
})
it('should create an action to include date in period', () => {
let index = 1
+ let date = actions.formatDate(new Date)
const expectedAction = {
type: 'INCLUDE_DATE_IN_PERIOD',
index,
- dayTypes
+ dayTypes,
+ date
}
- expect(actions.includeDateInPeriod(index, dayTypes)).toEqual(expectedAction)
+ expect(actions.includeDateInPeriod(index, dayTypes, date)).toEqual(expectedAction)
})
it('should create an action to exclude date from period', () => {
let index = 1
+ let date = actions.formatDate(new Date)
const expectedAction = {
type: 'EXCLUDE_DATE_FROM_PERIOD',
index,
- dayTypes
+ dayTypes,
+ date
}
- expect(actions.excludeDateFromPeriod(index, dayTypes)).toEqual(expectedAction)
+ expect(actions.excludeDateFromPeriod(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 f125052b3..160f3955f 100644
--- a/spec/javascripts/time_table/reducers/modal_spec.js
+++ b/spec/javascripts/time_table/reducers/modal_spec.js
@@ -177,7 +177,7 @@ describe('modal reducer', () => {
type: 'VALIDATE_PERIOD_FORM',
modalProps : modProps,
timeTablePeriods: ttperiods,
- currentMonthDaysIn: ttdates
+ timetableInDates: ttdates
})
).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
})
@@ -247,7 +247,7 @@ describe('modal reducer', () => {
type: 'VALIDATE_PERIOD_FORM',
modalProps : modProps2,
timeTablePeriods: ttperiods2,
- currentMonthDaysIn: ttdates2
+ timetableInDates: ttdates2
})
).toEqual(Object.assign({}, state2, {modalProps: newModalProps2}))
})
@@ -312,7 +312,7 @@ describe('modal reducer', () => {
type: 'VALIDATE_PERIOD_FORM',
modalProps : modProps3,
timeTablePeriods: ttperiods3,
- currentMonthDaysIn: ttdates3
+ timetableInDates: ttdates3
})
).toEqual(Object.assign({}, state3, {modalProps: newModalProps3}))
})
diff --git a/spec/javascripts/time_table/reducers/timetable_spec.js b/spec/javascripts/time_table/reducers/timetable_spec.js
index b832c0a86..805a29b5f 100644
--- a/spec/javascripts/time_table/reducers/timetable_spec.js
+++ b/spec/javascripts/time_table/reducers/timetable_spec.js
@@ -12,7 +12,7 @@ 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 = current_month.filter( ({include_date}) => !!include_date)
+let time_table_dates = []
let json = {
current_month: current_month,
@@ -29,7 +29,8 @@ describe('timetable reducer with empty state', () => {
current_month: [],
current_periode_range: "",
periode_range: [],
- time_table_periods: []
+ time_table_periods: [],
+ time_table_dates: []
}
})
@@ -45,6 +46,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
}
expect(
timetableReducer(state, {
@@ -134,45 +136,79 @@ describe('timetable reducer with filled state', () => {
).toEqual(state)
})
- it('should handle INCLUDE_DATE_IN_PERIOD', () => {
+ it('should handle INCLUDE_DATE_IN_PERIOD and add in_day if TT doesnt have it', () => {
+ 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
expect(
timetableReducer(state, {
type: 'INCLUDE_DATE_IN_PERIOD',
index: 4,
- dayTypes: arrDayTypes
+ dayTypes: arrDayTypes,
+ date: "2017-05-05"
})
- ).toEqual(state)
+ ).toEqual(newState)
+ })
+
+ it('should handle INCLUDE_DATE_IN_PERIOD and remove in_day if TT has it', () => {
+ 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: []})
+ expect(
+ timetableReducer(state, {
+ type: 'INCLUDE_DATE_IN_PERIOD',
+ index: 4,
+ dayTypes: arrDayTypes,
+ date: "2017-05-05"
+ })
+ ).toEqual(newState)
})
- it('should handle EXCLUDE_DATE_FROM_PERIOD', () => {
+ it('should handle EXCLUDE_DATE_FROM_PERIOD and add out_day if TT doesnt have it', () => {
+ let newDates = state.time_table_dates.concat({date: "2017-05-01", in_out: false})
+ let newState = Object.assign({}, state, {time_table_dates: newDates})
state.current_month[0].excluded_date = true
expect(
timetableReducer(state, {
type: 'EXCLUDE_DATE_FROM_PERIOD',
index: 0,
- dayTypes: arrDayTypes
+ dayTypes: arrDayTypes,
+ date: "2017-05-01"
})
- ).toEqual(state)
+ ).toEqual(newState)
})
- it('should handle VALIDATE_PERIOD_FORM', () => {
- state.current_month[13].in_periods = false
- state.time_table_periods[4].period_start = '2017-05-15'
+ it('should handle EXCLUDE_DATE_FROM_PERIOD and remove out_day if TT has it', () => {
+ 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: []})
+ expect(
+ timetableReducer(state, {
+ type: 'EXCLUDE_DATE_FROM_PERIOD',
+ index: 0,
+ dayTypes: arrDayTypes,
+ date: "2017-05-01"
+ })
+ ).toEqual(newState)
+ })
+
+ 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})
let modalProps = {
active: false,
begin: {
day: '15',
month: '05',
- year: '2017'
+ year: '2018'
},
end: {
day: '24',
month: '05',
- year: '2017'
+ year: '2018'
},
error: '',
- index: 4
+ index: false
}
expect(
timetableReducer(state, {
@@ -182,8 +218,8 @@ describe('timetable reducer with filled state', () => {
metas: {
day_types: arrDayTypes
},
- currentMonthDaysIn: time_table_dates
+ timetableInDates: state.time_table_dates.filter(d => d.in_out == true)
})
- ).toEqual(state)
+ ).toEqual(newState)
})
})