forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradezilla_common.rb
More file actions
316 lines (280 loc) · 11.8 KB
/
Copy pathgradezilla_common.rb
File metadata and controls
316 lines (280 loc) · 11.8 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
require File.expand_path(File.dirname(__FILE__) + '/../common')
module GradezillaCommon
shared_context 'gradebook_components' do
let(:gradebook_settings_cog) { f('#gradebook_settings') }
let(:show_notes) { fj('li a:contains("Show Notes Column")') }
let(:save_button) { fj('button span:contains("Save")') }
let(:hide_notes) { f(".hide") }
end
shared_context 'reusable_course' do
let(:test_course) { course_factory(active_course: true) }
let(:teacher) { user_factory(active_all: true) }
let(:student) { user_factory(active_all: true) }
let(:concluded_student) { user_factory(name: 'Concluded Student', active_all: true) }
let(:observer) { user_factory(active_all: true) }
let(:enroll_teacher_and_students) do
test_course.enroll_user(teacher, 'TeacherEnrollment', enrollment_state: 'active')
test_course.enroll_user(student, 'StudentEnrollment', enrollment_state: 'active')
test_course.enroll_user(concluded_student, 'StudentEnrollment', enrollment_state: 'completed')
end
let(:assignment_group_1) { test_course.assignment_groups.create! name: 'Group 1' }
let(:assignment_group_2) { test_course.assignment_groups.create! name: 'Group 2' }
let(:assignment_1) do
test_course.assignments.create!(
title: 'Points Assignment',
grading_type: 'points',
points_possible: 10,
submission_types: 'online_text_entry',
due_at: 2.days.ago,
assignment_group: assignment_group_1
)
end
let(:assignment_2) do
test_course.assignments.create!(
title: 'Percent Assignment',
grading_type: 'percent',
points_possible: 10,
)
end
let(:assignment_3) do
test_course.assignments.create!(
title: 'Complete/Incomplete Assignment',
grading_type: 'pass_fail',
points_possible: 10
)
end
let(:assignment_4) do
test_course.assignments.create!(
title: 'Letter Grade Assignment',
grading_type: 'letter_grade',
points_possible: 10
)
end
let(:assignment_5) do
test_course.assignments.create!(
title: 'Zero Points Possible',
grading_type: 'points',
points_possible: 0,
assignment_group: assignment_group_2
)
end
let(:student_submission) do
assignment_1.submit_homework(
student,
submission_type: 'online_text_entry',
body: 'Hello!'
)
end
end
def init_course_with_students(num = 1)
course_with_teacher(active_all: true)
@students = []
(1..num).each do |i|
student = User.create!(:name => "Student_#{i}")
student.register!
e1 = @course.enroll_student(student)
e1.workflow_state = 'active'
e1.save!
@course.reload
@students.push student
end
end
def set_default_grade(cell_index, points = "5")
move_to_click('[data-menu-item-id="set-default-grade"]')
dialog = find_with_jquery('.ui-dialog:visible')
f('.grading_value').send_keys(points)
submit_dialog(dialog, '.ui-button')
accept_alert
end
def toggle_muting(assignment)
find_with_jquery(".slick-header-column[id*='assignment_#{assignment.id}'] .Gradebook__ColumnHeaderAction").click
find_with_jquery('[data-menu-item-id="assignment-muter"]').click
find_with_jquery('.ui-dialog-buttonpane [data-action$="mute"]:visible').click
wait_for_ajaximations
end
def open_assignment_options(cell_index)
assignment_cell = ffj('#gradebook_grid .container_1 .slick-header-column')[cell_index]
driver.action.move_to(assignment_cell).perform
trigger = assignment_cell.find_element(:css, '.gradebook-header-drop')
trigger.click
expect(fj("##{trigger['aria-owns']}")).to be_displayed
end
def find_slick_cells(row_index, element)
grid = element
rows = grid.find_elements(:css, '.slick-row')
ff('.slick-cell', rows[row_index])
end
def edit_grade(cell, grade)
hover_and_click cell
grade_input = fj("#{cell} .grade")
set_value(grade_input, grade)
grade_input.send_keys(:return)
wait_for_ajaximations
end
def open_comment_dialog(x=0, y=0)
cell = f("#gradebook_grid .container_1 .slick-row:nth-child(#{y+1}) .slick-cell:nth-child(#{x+1})")
hover cell
fj('.gradebook-cell-comment:visible', cell).click
# the dialog fetches the comments async after it displays and then innerHTMLs the whole
# thing again once it has fetched them from the server, completely replacing it
wait_for_ajax_requests
fj('.submission_details_dialog:visible')
end
def final_score_for_row(row)
grade_grid = f('#gradebook_grid .container_1')
cells = find_slick_cells(row, grade_grid)
cells[4].find_element(:css, '.percentage').text
end
def switch_to_section(section=nil)
section = section.id if section.is_a?(CourseSection)
section ||= ""
fj('.section-select-button:visible').click
expect(fj('.section-select-menu:visible')).to be_displayed
fj("label[for='section_option_#{section}']").click
wait_for_ajaximations
end
def gradebook_column_array(css_row_class)
column = ff(css_row_class)
text_values = []
column.each do |row|
text_values.push(row.text)
end
text_values
end
def conclude_and_unconclude_course
# conclude course
@course.complete!
@user.reload
@user.cached_current_enrollments
@enrollment.reload
# un-conclude course
@enrollment.workflow_state = 'active'
@enrollment.save!
@course.reload
end
def gradebook_data_setup(opts={})
assignment_setup_defaults
assignment_setup(opts)
end
def data_setup_as_observer
user_with_pseudonym
course_with_observer user: @user, active_all: true
@course.observers=[@observer]
assignment_setup_defaults
assignment_setup
@all_students.each {|s| s.observers=[@observer]}
end
def assignment_setup_defaults
@assignment_1_points = "10"
@assignment_2_points = "5"
@assignment_3_points = "50"
@attendance_points = "15"
@student_name_1 = "student 1"
@student_name_2 = "student 2"
@student_name_3 = "student 3"
@student_1_total_ignoring_ungraded = "100%"
@student_2_total_ignoring_ungraded = "66.67%"
@student_3_total_ignoring_ungraded = "66.67%"
@student_1_total_treating_ungraded_as_zeros = "18.75%"
@student_2_total_treating_ungraded_as_zeros = "12.5%"
@student_3_total_treating_ungraded_as_zeros = "12.5%"
@default_password = "qwertyuiop"
end
def assignment_setup(opts={})
course_with_teacher({active_all: true}.merge(opts))
@course.grading_standard_enabled = true
@course.save!
@course.reload
# add first student
@student_1 = User.create!(:name => @student_name_1)
@student_1.register!
@student_1.pseudonyms.create!(:unique_id => "nobody1@example.com", :password => @default_password, :password_confirmation => @default_password)
e1 = @course.enroll_student(@student_1)
e1.workflow_state = 'active'
e1.save!
@course.reload
# add second student
@other_section = @course.course_sections.create(:name => "the other section")
@student_2 = User.create!(:name => @student_name_2)
@student_2.register!
@student_2.pseudonyms.create!(:unique_id => "nobody2@example.com", :password => @default_password, :password_confirmation => @default_password)
e2 = @course.enroll_student(@student_2, :section => @other_section)
e2.workflow_state = 'active'
e2.save!
@course.reload
# add third student
@student_3 = User.create!(:name => @student_name_3)
@student_3.register!
@student_3.pseudonyms.create!(:unique_id => "nobody3@example.com", :password => @default_password, :password_confirmation => @default_password)
e3 = @course.enroll_student(@student_3)
e3.workflow_state = 'active'
e3.save!
@course.reload
@all_students = [@student_1, @student_2, @student_3]
# first assignment data
@group = @course.assignment_groups.create!(:name => 'first assignment group', :group_weight => 100)
@first_assignment = assignment_model({
:course => @course,
:name => 'A name that would not reasonably fit in the header cell which should have some limit set',
:due_at => nil,
:points_possible => @assignment_1_points,
:submission_types => 'online_text_entry,online_upload',
:assignment_group => @group
})
rubric_model
@association = @rubric.associate_with(@assignment, @course, :purpose => 'grading')
@assignment.reload
@assignment.submit_homework(@student_1, :body => 'student 1 submission assignment 1')
@assignment.grade_student(@student_1, grade: 10, grader: @teacher)
# second student submission for assignment 1
@assignment.submit_homework(@student_2, :body => 'student 2 submission assignment 1')
@assignment.grade_student(@student_2, grade: 5, grader: @teacher)
# third student submission for assignment 1
@student_3_submission = @assignment.submit_homework(@student_3, :body => 'student 3 submission assignment 1')
@assignment.grade_student(@student_3, grade: 5, grader: @teacher)
# second assignment data
@second_assignment = assignment_model({
:course => @course,
:name => 'second assignment',
:due_at => nil,
:points_possible => @assignment_2_points,
:submission_types => 'online_text_entry',
:assignment_group => @group
})
@second_association = @rubric.associate_with(@second_assignment, @course, :purpose => 'grading')
# all students get a 5 on assignment 2
@all_students.each do |s|
@second_assignment.submit_homework(s, :body => "#{s.name} submission assignment 2")
@second_assignment.grade_student(s, grade: 5, grader: @teacher)
end
# third assignment data
due_date = Time.zone.now + 1.day
@third_assignment = assignment_model({
:course => @course,
:name => 'assignment three',
:due_at => due_date,
:points_possible => @assignment_3_points,
:submission_types => 'online_text_entry',
:assignment_group => @group
})
@third_association = @rubric.associate_with(@third_assignment, @course, :purpose => 'grading')
# attendance assignment
@attendance_assignment = assignment_model({
:course => @course,
:name => 'attendance assignment',
:title => 'attendance assignment',
:due_at => nil,
:points_possible => @attendance_points,
:submission_types => 'attendance',
:assignment_group => @group,
})
@ungraded_assignment = @course.assignments.create!(
:title => 'not-graded assignment',
:submission_types => 'not_graded',
:assignment_group => @group
)
end
def get_group_points
ff('div.assignment-points-possible')
end
end