aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjpl2017-05-04 18:04:04 +0200
committerjpl2017-05-04 18:04:12 +0200
commitbfea9e8e22a41d3de85fb265ba51b70e62aeba3f (patch)
tree46dd5efa9fc877458915686a36c12c6dce148d04
parentf9a3cec2a44a817ae21a446987983aed43fd383a (diff)
downloadchouette-core-bfea9e8e22a41d3de85fb265ba51b70e62aeba3f.tar.bz2
adding reducer tests for timetables reactux
-rw-r--r--spec/javascripts/time_table/reducers/metas_spec.js2
-rw-r--r--spec/javascripts/time_table/reducers/modal_spec.js185
-rw-r--r--spec/javascripts/time_table/reducers/pagination_spec.js128
-rw-r--r--spec/javascripts/time_table/reducers/status_spec.js50
-rw-r--r--spec/javascripts/time_table/reducers/timetable_spec.js20
5 files changed, 384 insertions, 1 deletions
diff --git a/spec/javascripts/time_table/reducers/metas_spec.js b/spec/javascripts/time_table/reducers/metas_spec.js
index adc6a9d05..61e3048db 100644
--- a/spec/javascripts/time_table/reducers/metas_spec.js
+++ b/spec/javascripts/time_table/reducers/metas_spec.js
@@ -2,7 +2,7 @@ var metasReducer = require('es6_browserified/time_tables/reducers/metas')
let state = {}
-describe('status reducer', () => {
+describe('metas reducer', () => {
beforeEach(() => {
let tag = {
id: 0,
diff --git a/spec/javascripts/time_table/reducers/modal_spec.js b/spec/javascripts/time_table/reducers/modal_spec.js
new file mode 100644
index 000000000..ceed0a43e
--- /dev/null
+++ b/spec/javascripts/time_table/reducers/modal_spec.js
@@ -0,0 +1,185 @@
+var modalReducer = require('es6_browserified/time_tables/reducers/modal')
+
+let state = {}
+
+describe('modal reducer', () => {
+ beforeEach(() => {
+ state = {
+ confirmModal: {},
+ modalProps: {
+ active: false,
+ begin: {
+ day: '01',
+ month: '01',
+ year: String(new Date().getFullYear())
+ },
+ end: {
+ day: '01',
+ month: '01',
+ year: String(new Date().getFullYear())
+ },
+ index: false,
+ error: ''
+ },
+ type: ""
+ }
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ modalReducer(undefined, {})
+ ).toEqual({})
+ })
+
+ it('should handle OPEN_CONFIRM_MODAL', () => {
+ let callback = function(){}
+ expect(
+ modalReducer(state, {
+ type: 'OPEN_CONFIRM_MODAL',
+ callback
+ })
+ ).toEqual(Object.assign({}, state, {type: "confirm", confirmModal: { callback: callback }}))
+ })
+
+ it('should handle CLOSE_PERIOD_FORM', () => {
+ let newModalProps = Object.assign({}, state.modalProps, {active: false})
+ expect(
+ modalReducer(state, {
+ type: 'CLOSE_PERIOD_FORM'
+ })
+ ).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
+ })
+
+ it('should handle OPEN_EDIT_PERIOD_FORM', () => {
+ let period = {
+ id : 1,
+ period_end : "2017-03-05",
+ period_start : "2017-02-23"
+ }
+ let period_start = period.period_start.split('-')
+ let period_end = period.period_end.split('-')
+
+ let index = 1
+
+ let newModalProps = {
+ active: true,
+ begin: {
+ day: period_start[2],
+ month: period_start[1],
+ year: period_start[0]
+ },
+ end: {
+ day: period_end[2],
+ month: period_end[1],
+ year: period_end[0]
+ },
+ index: index,
+ error: ''
+ }
+ expect(
+ modalReducer(state, {
+ type: 'OPEN_EDIT_PERIOD_FORM',
+ period,
+ index
+ })
+ ).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
+ })
+
+ it('should handle OPEN_ADD_PERIOD_FORM', () => {
+ let emptyDate = {
+ day: '01',
+ month: '01',
+ year: String(new Date().getFullYear())
+ }
+ let newModalProps = Object.assign({}, state.modalProps, {
+ active: true,
+ begin: emptyDate,
+ end: emptyDate,
+ index: false,
+ error: ""
+ })
+
+ expect(
+ modalReducer(state, {
+ type: 'OPEN_ADD_PERIOD_FORM'
+ })
+ ).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
+ })
+
+ it('should handle UPDATE_PERIOD_FORM', () => {
+ let val = "11"
+ let group = "begin"
+ let selectType = "day"
+
+ let newModalProps = {
+ active: false,
+ begin: {
+ day: val,
+ month: '01',
+ year: String(new Date().getFullYear())
+ },
+ end: {
+ day: '01',
+ month: '01',
+ year: String(new Date().getFullYear())
+ },
+ index: false,
+ error: ''
+ }
+
+ expect(
+ modalReducer(state, {
+ type: 'UPDATE_PERIOD_FORM',
+ val,
+ group,
+ selectType
+ })
+ ).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
+ })
+
+ it('should handle VALIDATE_PERIOD_FORM', () => {
+ // if period_end <= period_start, throw error
+ // if newperiod is on another one, throw error
+
+ let modProps = {
+ active: false,
+ begin: {
+ day: '13',
+ month: '01',
+ year: String(new Date().getFullYear())
+ },
+ end: {
+ day: '01',
+ month: '01',
+ year: String(new Date().getFullYear())
+ },
+ index: false,
+ error: ''
+ }
+ let newModalProps = {
+ active: false,
+ begin: {
+ day: '01',
+ month: '01',
+ year: String(new Date().getFullYear())
+ },
+ end: {
+ day: '01',
+ month: '01',
+ year: String(new Date().getFullYear())
+ },
+ index: false,
+ error: 'La date de départ doit être antérieure à la date de fin'
+ }
+
+ let ttperiods = []
+
+ expect(
+ modalReducer(state, {
+ type: 'VALIDATE_PERIOD_FORM',
+ modalProps : modProps,
+ timeTablePeriods: ttperiods
+ })
+ ).toEqual(Object.assign({}, state, {modalProps: newModalProps}))
+ })
+})
diff --git a/spec/javascripts/time_table/reducers/pagination_spec.js b/spec/javascripts/time_table/reducers/pagination_spec.js
new file mode 100644
index 000000000..740ded3ac
--- /dev/null
+++ b/spec/javascripts/time_table/reducers/pagination_spec.js
@@ -0,0 +1,128 @@
+var paginationReducer = require('es6_browserified/time_tables/reducers/pagination')
+
+const dispatch = function(){}
+
+let pagination = {
+ currentPage: "1982-02-15",
+ periode_range: ["1982-02-01", "1982-02-02", "1982-02-03"],
+ stateChanged: false
+}
+
+let state = {}
+
+describe('pagination reducer', () => {
+ beforeEach(() => {
+ state = {
+ currentPage: "",
+ periode_range: [],
+ stateChanged: false
+ }
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ paginationReducer(undefined, {})
+ ).toEqual({})
+ })
+
+ it('should handle RECEIVE_TIME_TABLES', () => {
+ let json = [{
+ current_periode_range: "1982-02-15",
+ periode_range: ["1982-02-01", "1982-02-02", "1982-02-03"]
+ }]
+ expect(
+ paginationReducer(state, {
+ type: 'RECEIVE_TIME_TABLES',
+ json
+ })
+ ).toEqual(Object.assign({}, state, {currentPage: json.current_periode_range, periode_range: json.periode_range}))
+ })
+
+ it('should handle GO_TO_PREVIOUS_PAGE', () => {
+ let nextPage = nextPage ? 1 : -1
+ let newPage = pagination.periode_range[pagination.periode_range.indexOf(pagination.currentPage) + nextPage]
+
+ expect(
+ paginationReducer(state, {
+ type: 'GO_TO_PREVIOUS_PAGE',
+ dispatch,
+ pagination,
+ nextPage: false
+ })
+ ).toEqual(Object.assign({}, state, {currentPage : newPage, stateChanged: false}))
+ })
+ it('should handle GO_TO_NEXT_PAGE', () => {
+ let nextPage = nextPage ? 1 : -1
+ let newPage = pagination.periode_range[pagination.periode_range.indexOf(pagination.currentPage) + nextPage]
+
+ expect(
+ paginationReducer(state, {
+ type: 'GO_TO_NEXT_PAGE',
+ dispatch,
+ pagination,
+ nextPage: false
+ })
+ ).toEqual(Object.assign({}, state, {currentPage : newPage, stateChanged: false}))
+ })
+
+ it('should handle CHANGE_PAGE', () => {
+ let page = "1982-02-15"
+ expect(
+ paginationReducer(state, {
+ type: 'CHANGE_PAGE',
+ dispatch,
+ page
+ })
+ ).toEqual(Object.assign({}, state, {currentPage : page, stateChanged: false}))
+ })
+
+ it('should handle INCLUDE_DATE_IN_PERIOD', () => {
+ expect(
+ paginationReducer(state, {
+ type: 'INCLUDE_DATE_IN_PERIOD'
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+ it('should handle EXCLUDE_DATE_FROM_PERIOD', () => {
+ expect(
+ paginationReducer(state, {
+ type: 'EXCLUDE_DATE_FROM_PERIOD'
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+ it('should handle DELETE_PERIOD', () => {
+ expect(
+ paginationReducer(state, {
+ type: 'DELETE_PERIOD'
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+ it('should handle VALIDATE_PERIOD_FORM', () => {
+ expect(
+ paginationReducer(state, {
+ type: 'VALIDATE_PERIOD_FORM'
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+ it('should handle UPDATE_COMMENT', () => {
+ expect(
+ paginationReducer(state, {
+ type: 'UPDATE_COMMENT'
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+ it('should handle UPDATE_COLOR', () => {
+ expect(
+ paginationReducer(state, {
+ type: 'UPDATE_COLOR'
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+ it('should handle UPDATE_DAY_TYPES', () => {
+ expect(
+ paginationReducer(state, {
+ type: 'UPDATE_DAY_TYPES'
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+})
diff --git a/spec/javascripts/time_table/reducers/status_spec.js b/spec/javascripts/time_table/reducers/status_spec.js
new file mode 100644
index 000000000..f000324cc
--- /dev/null
+++ b/spec/javascripts/time_table/reducers/status_spec.js
@@ -0,0 +1,50 @@
+var statusReducer = require('es6_browserified/time_tables/reducers/status')
+
+let state = {}
+
+describe('status reducer', () => {
+ beforeEach(() => {
+ state = {
+ actionType: "edit",
+ fetchSuccess: true,
+ isFetching: false
+ }
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ statusReducer(undefined, {})
+ ).toEqual({})
+ })
+
+ it('should handle UNAVAILABLE_SERVER', () => {
+ expect(
+ statusReducer(state, {
+ type: 'UNAVAILABLE_SERVER'
+ })
+ ).toEqual(Object.assign({}, state, {fetchSuccess: false}))
+ })
+
+ it('should handle FETCH_API', () => {
+ expect(
+ statusReducer(state, {
+ type: 'FETCH_API'
+ })
+ ).toEqual(Object.assign({}, state, {isFetching: true}))
+ })
+
+ it('should handle RECEIVE_TIME_TABLES', () => {
+ expect(
+ statusReducer(state, {
+ type: 'RECEIVE_TIME_TABLES'
+ })
+ ).toEqual(Object.assign({}, state, {fetchSuccess: true, isFetching: false}))
+ })
+ it('should handle RECEIVE_MONTH', () => {
+ expect(
+ statusReducer(state, {
+ type: 'RECEIVE_MONTH'
+ })
+ ).toEqual(Object.assign({}, state, {fetchSuccess: true, isFetching: false}))
+ })
+})
diff --git a/spec/javascripts/time_table/reducers/timetable_spec.js b/spec/javascripts/time_table/reducers/timetable_spec.js
new file mode 100644
index 000000000..734095cfc
--- /dev/null
+++ b/spec/javascripts/time_table/reducers/timetable_spec.js
@@ -0,0 +1,20 @@
+var timetableReducer = require('es6_browserified/time_tables/reducers/timetable')
+
+let state = {}
+
+describe('timetable reducer', () => {
+ beforeEach(() => {
+ state = {
+ current_month: [],
+ current_periode_range: "",
+ periode_range: [],
+ time_table_periods: []
+ }
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ timetableReducer(undefined, {})
+ ).toEqual({})
+ })
+})