forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeBlockRowSpec.coffee
More file actions
135 lines (113 loc) · 4.93 KB
/
Copy pathTimeBlockRowSpec.coffee
File metadata and controls
135 lines (113 loc) · 4.93 KB
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
#
# Copyright (C) 2012 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
define [
'jquery'
'compiled/util/fcUtil'
'compiled/calendar/TimeBlockList'
'compiled/calendar/TimeBlockRow'
'timezone'
'timezone/America/Detroit'
], ($, fcUtil, TimeBlockList, TimeBlockRow, tz, detroit) ->
nextYear = new Date().getFullYear() + 1
unfudged_start = tz.parse("#{nextYear}-02-03T12:32:00Z")
unfudged_end = tz.parse("#{nextYear}-02-03T17:32:00Z")
QUnit.module "TimeBlockRow",
setup: ->
@snapshot = tz.snapshot()
tz.changeZone(detroit, 'America/Detroit')
@start = fcUtil.wrap(unfudged_start)
@end = fcUtil.wrap(unfudged_end)
@$holder = $('<table />').appendTo(document.getElementById("fixtures"))
@timeBlockList = new TimeBlockList(@$holder)
# fakeTimer'd because the tests with failed validations add an error box
# that is faded in. if we don't tick past the fade-in, other unrelated
# tests that use fake timers fail.
@clock = sinon.useFakeTimers((new Date()).valueOf())
teardown: ->
# tick past any remaining errorBox fade-ins
@clock.tick 250
@clock.restore()
@$holder.detach()
$("#fixtures").empty()
$(".ui-tooltip").remove()
$(".error_box").remove()
tz.restore(@snapshot)
test "should init properly", ->
me = new TimeBlockRow(@timeBlockList, {@start, @end})
# make sure the <input> `value`s are right
equal me.$date.val().trim(), tz.format(unfudged_start, 'date.formats.medium_with_weekday')
equal me.$start_time.val().trim(), tz.format(unfudged_start, 'time.formats.tiny')
equal me.$end_time.val().trim(), tz.format(unfudged_end, 'time.formats.tiny')
test "delete link", ->
me = @timeBlockList.addRow({@start, @end})
ok (me in @timeBlockList.rows), 'make sure I am in the timeBlockList to start out with'
me.$row.find('.delete-block-link').click()
ok !(me in @timeBlockList.rows)
ok !me.$row[0].parentElement, 'make sure I am no longer on the page'
test 'validate: fields must be individually valid', ->
me = new TimeBlockRow(@timeBlockList)
me.$date.val('invalid').change()
ok !me.validate()
me.$date.data('instance').setDate(@start)
me.$start_time.val('invalid').change()
ok !me.validate()
me.$start_time.data('instance').setDate(@start)
me.$end_time.val('invalid').change()
ok !me.validate()
test 'validate: with good data', ->
me = new TimeBlockRow(@timeBlockList, {@start, @end})
ok me.validate(), 'whole row validates if has good info'
test 'validate: date in past', ->
me = new TimeBlockRow(@timeBlockList, {@start, @end})
me.$date.val('1/1/2000').change()
ok !me.validate()
ok me.$end_time.hasClass('error'), 'has error class'
ok me.$end_time.data('associated_error_box')?.is(':visible'), 'error box is visible'
test 'validate: just time in past', ->
fudgedMidnight = fcUtil.now().minutes(0).hours(0)
fudgedEnd = fcUtil.clone(fudgedMidnight)
fudgedEnd.minutes(1)
me = new TimeBlockRow(@timeBlockList, {start: fudgedMidnight, end: fudgedEnd})
ok !me.validate(), 'not valid if time in past'
ok me.$end_time.hasClass('error'), 'has error class'
ok me.$end_time.data('associated_error_box')?.is(':visible'), 'error box is visible'
test 'validate: end before start', ->
me = new TimeBlockRow(@timeBlockList, {start: @end, end: @start})
ok !me.validate()
ok me.$start_time.hasClass('error'), 'has error class'
ok me.$start_time.data('associated_error_box')?.is(':visible'), 'error box is visible'
test 'valid if whole row is blank', ->
me = new TimeBlockRow(@timeBlockList)
ok me.validate()
test 'valid if incomplete', ->
me = new TimeBlockRow(@timeBlockList, start: @start, end: null)
ok me.validate()
test 'getData', ->
me = new TimeBlockRow(@timeBlockList, {@start, @end})
me.validate()
equal +me.getData()[0], +@start
equal +me.getData()[1], +@end
equal +me.getData()[2], false
test 'incomplete: false if whole row blank', ->
me = new TimeBlockRow(@timeBlockList)
ok !me.incomplete()
test 'incomplete: false if whole row populated', ->
me = new TimeBlockRow(@timeBlockList, {@start, @end})
ok !me.incomplete()
test 'incomplete: true if only one field blank', ->
me = new TimeBlockRow(@timeBlockList, start: @start, end: null)
ok me.incomplete()