aboutsummaryrefslogtreecommitdiffstats
path: root/spec/javascript/time_table/actions_spec.js
blob: 003b7f6b5f810eecbc1df73d2f9a3e6319b840b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import actions from '../../../app/javascript/time_tables/actions'
const dispatch = function(){}
const dayTypes = [true, true, true, true, true, true, true]
const day = {
  date : "2017-05-01",
  day : "lundi",
  excluded_date : false,
  in_periods : true,
  include_date : false,
  mday : 1,
  wday : 1,
  wnumber : "18"
}
describe('actions', () => {
  it('should create an action to update dayTypes', () => {
    let obj = {}
    const expectedAction = {
      type: 'UPDATE_DAY_TYPES',
      dayTypes: obj
    }
    expect(actions.updateDayTypes(obj)).toEqual(expectedAction)
  })

  it('should create an action to update comment', () => {
    const expectedAction = {
      type: 'UPDATE_COMMENT',
      comment: 'test'
    }
    expect(actions.updateComment('test')).toEqual(expectedAction)
  })

  it('should create an action to update color', () => {
    const expectedAction = {
      type: 'UPDATE_COLOR',
      color: '#ffffff'
    }
    expect(actions.updateColor('#ffffff')).toEqual(expectedAction)
  })

  it('should create an action to update selected tags', () => {
    let selectedItem = {
      id: 1,
      name: 'test'
    }
    const expectedAction = {
      type: 'UPDATE_SELECT_TAG',
      selectedItem: selectedItem
    }
    expect(actions.select2Tags(selectedItem)).toEqual(expectedAction)
  })

  it('should create an action to update unselected tags', () => {
    let selectedItem = {
      id: 1,
      name: 'test'
    }
    const expectedAction = {
      type: 'UPDATE_UNSELECT_TAG',
      selectedItem: selectedItem
    }
    expect(actions.unselect2Tags(selectedItem)).toEqual(expectedAction)
  })

  it('should create an action to go to previous page', () => {
    let pagination = {
      currentPage: '2017-01-01',
      periode_range: [],
      stateChanged: false
    }
    const expectedAction = {
      type: 'GO_TO_PREVIOUS_PAGE',
      dispatch,
      pagination,
      nextPage: false
    }
    expect(actions.goToPreviousPage(dispatch, pagination)).toEqual(expectedAction)
  })

  it('should create an action to go to next page', () => {
    let pagination = {
      currentPage: '2017-01-01',
      periode_range: [],
      stateChanged: false
    }
    const expectedAction = {
      type: 'GO_TO_NEXT_PAGE',
      dispatch,
      pagination,
      nextPage: true
    }
    expect(actions.goToNextPage(dispatch, pagination)).toEqual(expectedAction)
  })

  it('should create an action to change page', () => {
    let page = '2017-05-04'
    const expectedAction = {
      type: 'CHANGE_PAGE',
      dispatch,
      page: page
    }
    expect(actions.changePage(dispatch, page)).toEqual(expectedAction)
  })

  it('should create an action to delete period', () => {
    let index = 1
    const expectedAction = {
      type: 'DELETE_PERIOD',
      index,
      dayTypes
    }
    expect(actions.deletePeriod(index, dayTypes)).toEqual(expectedAction)
  })

  it('should create an action to open add period form', () => {
    const expectedAction = {
      type: 'OPEN_ADD_PERIOD_FORM',
    }
    expect(actions.openAddPeriodForm()).toEqual(expectedAction)
  })

  it('should create an action to open edit period form', () => {
    let period = {
      id : 1,
      period_end : "2017-03-05",
      period_start : "2017-02-23"
    }
    let index = 1
    const expectedAction = {
      type: 'OPEN_EDIT_PERIOD_FORM',
      period,
      index
    }
    expect(actions.openEditPeriodForm(period, index)).toEqual(expectedAction)
  })

  it('should create an action to close period form', () => {
    const expectedAction = {
      type: 'CLOSE_PERIOD_FORM',
    }
    expect(actions.closePeriodForm()).toEqual(expectedAction)
  })

  it('should create an action to update period form', () => {
    let val = "11"
    let group = "start"
    let selectType = "day"
    const expectedAction = {
      type: 'UPDATE_PERIOD_FORM',
      val,
      group,
      selectType
    }
    expect(actions.updatePeriodForm(val, group, selectType)).toEqual(expectedAction)
  })

  it('should create an action to validate period form', () => {
    let modalProps = {}
    let timeTablePeriods = []
    let metas = {}
    let timetableInDates = []
    let error = ''
    const expectedAction = {
      type: 'VALIDATE_PERIOD_FORM',
      modalProps,
      timeTablePeriods,
      metas,
      timetableInDates,
      error
    }
    expect(actions.validatePeriodForm(modalProps, timeTablePeriods, metas, timetableInDates, error)).toEqual(expectedAction)
  })

  it('should create an action to add an included date', () => {
    let index = 1
    let date = actions.formatDate(new Date)
    const expectedAction = {
      type: 'ADD_INCLUDED_DATE',
      index,
      dayTypes,
      date
    }
    expect(actions.addIncludedDate(index, dayTypes, date)).toEqual(expectedAction)
  })

  it('should create an action to remove an included dat', () => {
    let index = 1
    let date = actions.formatDate(new Date)
    const expectedAction = {
      type: 'REMOVE_INCLUDED_DATE',
      index,
      dayTypes,
      date
    }
    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', () => {
    let callback = function(){}
    const expectedAction = {
      type: 'OPEN_CONFIRM_MODAL',
      callback
    }
    expect(actions.openConfirmModal(callback)).toEqual(expectedAction)
  })

  it('should create an action to close modal', () => {
    const expectedAction = {
      type: 'CLOSE_MODAL',
    }
    expect(actions.closeModal()).toEqual(expectedAction)
  })

})