forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuizSpec.coffee
More file actions
223 lines (173 loc) · 7.16 KB
/
Copy pathQuizSpec.coffee
File metadata and controls
223 lines (173 loc) · 7.16 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
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
#
# Copyright (C) 2013 - 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/models/Quiz'
'compiled/models/Assignment'
'compiled/models/DateGroup'
'compiled/collections/AssignmentOverrideCollection'
'jquery.ajaxJSON'
], ($, Quiz, Assignment, DateGroup, AssignmentOverrideCollection) ->
QUnit.module 'Quiz',
setup: ->
@quiz = new Quiz(id: 1, html_url: 'http://localhost:3000/courses/1/quizzes/24')
@ajaxStub = @stub $, 'ajaxJSON'
teardown: ->
# Initialize
test '#initialize ignores assignment if not given', ->
ok !@quiz.get('assignment')
test '#initialize sets assignment', ->
assign = id: 1, title: 'Foo Bar'
@quiz = new Quiz(assignment: assign)
equal @quiz.get('assignment').constructor, Assignment
test '#initialize ignores assignment_overrides if not given', ->
ok !@quiz.get('assignment_overrides')
test '#initialize assigns assignment_override collection', ->
@quiz = new Quiz(assignment_overrides: [])
equal @quiz.get('assignment_overrides').constructor, AssignmentOverrideCollection
test '#initialize should set url from html url', ->
equal @quiz.get('url'), 'http://localhost:3000/courses/1/quizzes/1'
test '#initialize should set edit_url from html url', ->
equal @quiz.get('edit_url'), 'http://localhost:3000/courses/1/quizzes/1/edit'
test '#initialize should set publish_url from html url', ->
equal @quiz.get('publish_url'), 'http://localhost:3000/courses/1/quizzes/publish'
test '#initialize should set unpublish_url from html url', ->
equal @quiz.get('unpublish_url'), 'http://localhost:3000/courses/1/quizzes/unpublish'
test '#initialize should set title_label from title', ->
@quiz = new Quiz(title: 'My Quiz!', readable_type: 'Quiz')
equal @quiz.get('title_label'), 'My Quiz!'
test '#initialize should set title_label from readable_type', ->
@quiz = new Quiz(readable_type: 'Quiz')
equal @quiz.get('title_label'), 'Quiz'
test '#initialize defaults unpublishable to true', ->
ok @quiz.get('unpublishable')
test '#initialize sets unpublishable to false', ->
@quiz = new Quiz(unpublishable: false)
ok !@quiz.get('unpublishable')
test '#initialize sets publishable from can_unpublish and published', ->
@quiz = new Quiz(can_unpublish: false, published: true)
ok !@quiz.get('unpublishable')
test "#initialize sets question count", ->
@quiz = new Quiz(question_count: 1, published: true)
equal @quiz.get('question_count_label'), "1 Question"
@quiz = new Quiz(question_count: 2, published: true)
equal @quiz.get('question_count_label'), "2 Questions"
test "#initialize sets possible points count with no points", ->
@quiz = new Quiz()
equal @quiz.get('possible_points_label'), ''
test "#initialize sets possible points count with 0 points", ->
@quiz = new Quiz(points_possible: 0)
equal @quiz.get('possible_points_label'), ''
test "#initialize sets possible points count with 1 points", ->
@quiz = new Quiz(points_possible: 1)
equal @quiz.get('possible_points_label'), "1 pt"
test "#initialize sets possible points count with 2 points", ->
@quiz = new Quiz(points_possible: 2)
equal @quiz.get('possible_points_label'), "2 pts"
test "#initialize points possible to null if ungraded survey", ->
@quiz = new Quiz(points_possible: 5, quiz_type: "survey")
equal @quiz.get('possible_points_label'), ""
# Publishing
test '#publish saves to the server', ->
@quiz.publish()
ok @ajaxStub.called
test '#publish sets published attribute to true', ->
@quiz.publish()
ok @quiz.get('published')
test '#unpublish saves to the server', ->
@quiz.unpublish()
ok @ajaxStub.called
test '#unpublish sets published attribute to false', ->
@quiz.unpublish()
ok !@quiz.get('published')
# multiple due dates
QUnit.module "Quiz#multipleDueDates"
test "checks for multiple due dates from assignment overrides", ->
quiz = new Quiz all_dates: [{title: "Winter"}, {title: "Summer"}]
ok quiz.multipleDueDates()
test "checks for no multiple due dates from quiz overrides", ->
quiz = new Quiz
ok !quiz.multipleDueDates()
QUnit.module "Quiz#allDates"
test "gets the due dates from the assignment overrides", ->
dueAt = new Date("2013-08-20T11:13:00Z")
dates = [
new DateGroup due_at: dueAt, title: "Everyone"
]
quiz = new Quiz all_dates: dates
allDates = quiz.allDates()
first = allDates[0]
equal first.dueAt+"", dueAt+""
equal first.dueFor, "Everyone"
test "gets empty due dates when there are no dates", ->
quiz = new Quiz
deepEqual quiz.allDates(), []
# single section due date
test "gets the due date for section instead of null", ->
dueAt = new Date("2013-11-27T11:01:00Z")
quiz = new Quiz all_dates: [
{due_at: null, title: "Everyone"},
{due_at: dueAt, title: "Summer"}
]
@stub quiz, "multipleDueDates", -> false
deepEqual quiz.singleSectionDueDate(), dueAt.toISOString()
test "returns due_at when only one date/section are present", ->
date = Date.now()
quiz = new Quiz name: 'Taco party!'
quiz.set 'due_at', date
deepEqual quiz.singleSectionDueDate(), quiz.dueAt()
# toView
QUnit.module "Quiz#toView"
test "returns the quiz's dueAt", ->
date = Date.now()
quiz = new Quiz name: 'foo'
quiz.dueAt date
json = quiz.toView()
deepEqual json.dueAt, date
test "returns quiz's lockAt", ->
lockAt = Date.now()
quiz = new Quiz name: 'foo'
quiz.lockAt lockAt
json = quiz.toView()
deepEqual json.lockAt, lockAt
test "includes quiz's unlockAt", ->
unlockAt = Date.now()
quiz = new Quiz name: 'foo'
quiz.unlockAt unlockAt
json = quiz.toView()
deepEqual json.unlockAt, unlockAt
test "includes htmlUrl", ->
quiz = new Quiz url: 'http://example.com/quizzes/1'
json = quiz.toView()
deepEqual json.htmlUrl, 'http://example.com/quizzes/1'
test "includes multipleDueDates", ->
quiz = new Quiz all_dates: [{title: "Summer"}, {title: "Winter"}]
json = quiz.toView()
deepEqual json.multipleDueDates, true
test "includes allDates", ->
quiz = new Quiz all_dates: [{title: "Summer"}, {title: "Winter"}]
json = quiz.toView()
equal json.allDates.length, 2
test "includes singleSectionDueDate", ->
dueAt = new Date("2013-11-27T11:01:00Z")
quiz = new Quiz all_dates: [
{due_at: null, title: "Everyone"},
{due_at: dueAt, title: "Summer"}
]
@stub quiz, "multipleDueDates", -> false
json = quiz.toView()
equal json.singleSectionDueDate, dueAt.toISOString()