forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutcomeResultCollectionSpec.coffee
More file actions
133 lines (121 loc) · 4.07 KB
/
Copy pathOutcomeResultCollectionSpec.coffee
File metadata and controls
133 lines (121 loc) · 4.07 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
#
# Copyright (C) 2015 - 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 [
'Backbone'
'compiled/models/grade_summary/Outcome'
'compiled/collections/OutcomeResultCollection'
'helpers/fakeENV'
'timezone'
], (Backbone, Outcome, OutcomeResultCollection, fakeENV, tz) ->
QUnit.module 'OutcomeResultCollectionSpec',
setup: ->
fakeENV.setup()
ENV.context_asset_string = 'course_1'
ENV.student_id = '1'
@outcome = new Outcome({
mastery_points: 8
points_possible: 10
})
@outcomeResultCollection = new OutcomeResultCollection([], {
outcome: @outcome
})
@alignmentName = 'First Alignment Name'
@alignmentName2 = 'Second Alignment Name'
@alignmentName3 = 'Third Alignment Name'
@response = {
outcome_results: [{
submitted_or_assessed_at: tz.parse('2015-04-24T19:27:54Z')
links: {
alignment: 'alignment_1'
}
}],
linked: {
alignments: [{
id: 'alignment_1'
name: @alignmentName
}]
}
}
@response2 = {
outcome_results: [{
submitted_or_assessed_at: tz.parse('2015-04-24T19:27:54Z')
links: {
alignment: 'alignment_1'
}
},{
submitted_or_assessed_at: tz.parse('2015-04-23T19:27:54Z')
links: {
alignment: 'alignment_2'
}
},{
submitted_or_assessed_at: tz.parse('2015-04-25T19:27:54Z')
links: {
alignment: 'alignment_3'
}
}],
linked: {
alignments: [{
id: 'alignment_1'
name: @alignmentName
},{
id: 'alignment_2'
name: @alignmentName2
},{
id: 'alignment_3'
name: @alignmentName3
}]
}
}
teardown: ->
fakeENV.teardown()
test 'default params reflect aligned outcome', ->
collectionModel = new @outcomeResultCollection.model()
deepEqual collectionModel.get("mastery_points"), 8
deepEqual collectionModel.get("points_possible"), 10
test '#parse', ->
ok !@outcomeResultCollection.alignments, 'precondition'
ok @outcomeResultCollection.parse(@response)
ok @outcomeResultCollection.alignments instanceof Backbone.Collection
ok @outcomeResultCollection.alignments.length, 1
test '#handleAdd', ->
equal @outcomeResultCollection.length, 0, 'precondition'
@outcomeResultCollection.alignments = new Backbone.Collection(
@response['linked']['alignments']
)
ok @outcomeResultCollection.add(
@response['outcome_results'][0]
)
ok @outcomeResultCollection.length, 1
equal @alignmentName, @outcomeResultCollection.first().get('alignment_name')
test '#handleSort', ->
equal @outcomeResultCollection.length, 0, 'precondition'
@outcomeResultCollection.alignments = new Backbone.Collection(
@response2['linked']['alignments']
)
ok @outcomeResultCollection.add(
@response2['outcome_results'][0]
)
ok @outcomeResultCollection.add(
@response2['outcome_results'][1]
)
ok @outcomeResultCollection.add(
@response2['outcome_results'][2]
)
ok @outcomeResultCollection.length, 3
equal @alignmentName3, @outcomeResultCollection.at(0).get('alignment_name')
equal @alignmentName, @outcomeResultCollection.at(1).get('alignment_name')
equal @alignmentName2, @outcomeResultCollection.at(2).get('alignment_name')