aboutsummaryrefslogtreecommitdiffstats
path: root/spec/javascripts
diff options
context:
space:
mode:
authorcedricnjanga2017-08-16 01:09:50 +0200
committercedricnjanga2017-08-16 09:28:48 +0200
commit44fd650c7951176999e6db8b1bc92c2f29dc3ec2 (patch)
tree7a15a418f02e0c093c2eb134e8a5790c37140781 /spec/javascripts
parentefbd9f90ae41b357ad8559fbc3b29fc59524bb73 (diff)
downloadchouette-core-44fd650c7951176999e6db8b1bc92c2f29dc3ec2.tar.bz2
Update JS timetable specs
Diffstat (limited to 'spec/javascripts')
-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
3 files changed, 66 insertions, 26 deletions
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)
})
})