forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcourses_spec.rb
More file actions
541 lines (443 loc) · 20.5 KB
/
Copy pathcourses_spec.rb
File metadata and controls
541 lines (443 loc) · 20.5 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
#
# Copyright (C) 2011 - 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/>.
require File.expand_path(File.dirname(__FILE__) + '/common')
describe "courses" do
include_context "in-process server selenium tests"
context "as a teacher" do
def create_new_course
get "/"
f('[aria-controls="new_course_form"]').click
wait_for_ajaximations
f('[name="course[name]"]').send_keys "testing"
f('.ui-dialog-buttonpane .btn-primary').click
end
before (:each) do
account = Account.default
account.settings = {:open_registration => true, :no_enrollments_can_create_courses => true, :teachers_can_create_courses => true}
account.save!
end
context 'draft state' do
before(:each) do
course_with_teacher_logged_in
end
def validate_action_button(postion, validation_text)
action_button = ff('#course_status_actions button').send(postion)
expect(action_button).to have_class('disabled')
expect(action_button.text).to eq validation_text
end
it "should allow publishing of the course through the course status actions" do
@course.workflow_state = 'claimed'
@course.lock_all_announcements = true
@course.save!
get "/courses/#{@course.id}"
course_status_buttons = ff('#course_status_actions button')
expect(course_status_buttons.first).to have_class('disabled')
expect(course_status_buttons.first.text).to eq 'Unpublished'
expect(course_status_buttons.last).not_to have_class('disabled')
expect(course_status_buttons.last.text).to eq 'Publish'
expect_new_page_load { course_status_buttons.last.click }
validate_action_button(:last, 'Published')
@course.reload
expect(@course.lock_all_announcements).to be_truthy
end
it "should display a creative commons license when set", priority: "1", test_id: 272274 do
@course.license = 'cc_by_sa'
@course.save!
get "/courses/#{@course.id}"
wait_for_ajaximations
expect(f('.public-license-text').text).to include('This course content is offered under a')
end
it "should allow unpublishing of a course through the course status actions" do
get "/courses/#{@course.id}"
course_status_buttons = ff('#course_status_actions button')
expect(course_status_buttons.first).not_to have_class('disabled')
expect(course_status_buttons.first.text).to eq 'Unpublish'
expect(course_status_buttons.last).to have_class('disabled')
expect(course_status_buttons.last.text).to eq 'Published'
expect_new_page_load { course_status_buttons.first.click }
validate_action_button(:first, 'Unpublished')
end
it "should allow publishing even if graded submissions exist" do
course_with_student_submissions({submission_points: true, unpublished: true})
get "/courses/#{@course.id}"
course_status_buttons = ff('#course_status_actions button')
expect(course_status_buttons.first).to have_class('disabled')
expect(course_status_buttons.first.text).to eq 'Unpublished'
expect(course_status_buttons.last).not_to have_class('disabled')
expect(course_status_buttons.last.text).to eq 'Publish'
expect_new_page_load { course_status_buttons.last.click }
@course.reload
expect(@course).to be_available
end
it "should not show course status if published and graded submissions exist" do
course_with_student_submissions({submission_points: true})
get "/courses/#{@course.id}"
expect(f("#content")).not_to contain_css('#course_status')
end
it "should allow unpublishing of the course if submissions have no score or grade" do
course_with_student_submissions
get "/courses/#{@course.id}"
course_status_buttons = ff('#course_status_actions button')
expect_new_page_load { course_status_buttons.first.click }
assert_flash_notice_message('successfully updated')
validate_action_button(:first, 'Unpublished')
end
it "should allow publishing/unpublishing with only change_course_state permission" do
@course.account.role_overrides.create!(:permission => :manage_course_content, :role => teacher_role, :enabled => false)
@course.account.role_overrides.create!(:permission => :manage_courses, :role => teacher_role, :enabled => false)
get "/courses/#{@course.id}"
expect_new_page_load { ff('#course_status_actions button').first.click }
validate_action_button(:first, 'Unpublished')
expect_new_page_load { ff('#course_status_actions button').last.click }
validate_action_button(:last, 'Published')
end
it "should not allow publishing/unpublishing without change_course_state permission" do
@course.account.role_overrides.create!(:permission => :change_course_state, :role => teacher_role, :enabled => false)
get "/courses/#{@course.id}"
expect(f("#content")).not_to contain_css('#course_status_actions')
end
end
describe 'course wizard' do
def go_to_checklist
get "/courses/#{@course.id}"
f(".wizard_popup_link").click()
expect(f(".ic-wizard-box")).to be_displayed
wait_for_ajaximations
end
def check_if_item_complete(item)
elem = "#wizard_#{item}.ic-wizard-box__content-trigger--checked"
expect(f(elem)).to be_displayed
end
def check_if_item_not_complete(item)
expect(f("#wizard_#{item}.ic-wizard-box__content-trigger")).to be_displayed
expect(f("#content")).not_to contain_css("#wizard_#{item}.ic-wizard-box__content-trigger--checked")
end
it "should open up the choose home page dialog from the wizard" do
skip_if_chrome('research')
course_with_teacher_logged_in
create_new_course
go_to_checklist
f("#wizard_home_page").click
f(".ic-wizard-box__message-button a").click
wait_for_ajaximations
modal = fj("h3:contains('Choose Home Page')")
expect(modal).to be_displayed
end
it "should have the correct initial state" do
course_with_teacher_logged_in
go_to_checklist
check_if_item_not_complete('content_import')
check_if_item_not_complete('add_assignments')
check_if_item_not_complete('add_students')
check_if_item_not_complete('add_files')
check_if_item_not_complete('content_import')
check_if_item_not_complete('select_navigation')
check_if_item_complete('home_page')
check_if_item_not_complete('course_calendar')
check_if_item_not_complete('add_tas')
end
it "should complete 'Add Course Assignments' checklist item" do
course_with_teacher_logged_in
@course.assignments.create({name: "Test Assignment"})
go_to_checklist
check_if_item_complete('add_assignments')
end
it "should complete 'Add Students to the Course' checklist item" do
course_with_teacher_logged_in
student = user_with_pseudonym(:username => 'student@example.com', :active_all => 1)
student_in_course(:user => student, :active_all => 1)
go_to_checklist
check_if_item_complete('add_students')
end
it "should complete 'Select Navigation Links' checklist item" do
skip_if_chrome('research')
course_with_teacher_logged_in
# Navigate to Navigation tab
go_to_checklist
f('#wizard_select_navigation').click
f('.ic-wizard-box__message-button a').click
# Modify Naviagtion
f('#navigation_tab').click
f('.navitem.enabled.modules .al-trigger.al-trigger-gray').click
f('.navitem.enabled.modules .admin-links .disable_nav_item_link').click
f('#tab-navigation .btn').click
go_to_checklist
check_if_item_complete('select_navigation')
end
it "should complete 'Add Course Calendar Events' checklist item" do
skip_if_chrome('research')
course_with_teacher_logged_in
# Navigate to Calendar tab
go_to_checklist
f('#wizard_course_calendar').click
f('.ic-wizard-box__message-button a').click
# Add Event
f("#create_new_event_link").click
wait_for_ajaximations
replace_content(f('#edit_calendar_event_form #calendar_event_title'), "Event")
f("#edit_calendar_event_form button.event_button").click
wait_for_ajaximations
go_to_checklist
check_if_item_complete('course_calendar')
end
it "should complete 'Publish the Course' checklist item" do
skip_if_chrome('research')
course_with_teacher_logged_in
# Publish from Checklist
go_to_checklist
f('#wizard_publish_course').click
f('.ic-wizard-box__message-button button').click
go_to_checklist
check_if_item_complete('publish_course')
end
end
it "should correctly update the course quota" do
course_with_admin_logged_in
# first try setting the quota explicitly
get "/courses/#{@course.id}/settings"
f("#ui-id-1").click
form = f("#course_form")
expect(form).to be_displayed
quota_input = form.find_element(:css, "input#course_storage_quota_mb")
replace_content(quota_input, "10")
submit_form(form)
value = f("#course_form input#course_storage_quota_mb")['value']
expect(value).to eq "10"
# then try just saving it (without resetting it)
get "/courses/#{@course.id}/settings"
form = f("#course_form")
value = f("#course_form input#course_storage_quota_mb")['value']
expect(value).to eq "10"
submit_form(form)
form = f("#course_form")
value = f("#course_form input#course_storage_quota_mb")['value']
expect(value).to eq "10"
# then make sure it's right after a reload
get "/courses/#{@course.id}/settings"
value = f("#course_form input#course_storage_quota_mb")['value']
expect(value).to eq "10"
@course.reload
expect(@course.storage_quota).to eq 10.megabytes
end
it "should redirect to the gradebook when switching courses when viewing a students grades" do
teacher = user_with_pseudonym(:username => 'teacher@example.com', :active_all => 1)
student = user_with_pseudonym(:username => 'student@example.com', :active_all => 1)
course1 = course_with_teacher_logged_in(:user => teacher, :active_all => 1, :course_name => 'course1').course
student_in_course(:user => student, :active_all => 1)
course2 = course_with_teacher(:user => teacher, :active_all => 1, :course_name => 'course2').course
student_in_course(:user => student, :active_all => 1)
create_session(student.pseudonyms.first)
get "/courses/#{course1.id}/grades/#{student.id}"
select = f('#course_url')
options = select.find_elements(:css, 'option')
expect(options.length).to eq 2
wait_for_ajaximations
expect_new_page_load{ click_option('#course_url', course2.name) }
expect(f('#breadcrumbs .home + li a')).to include_text(course2.name)
end
it "should load the users page using ajax" do
course_with_teacher_logged_in
# Set up the course with > 50 users (to test scrolling)
create_users_in_course @course, 60
@course.enroll_user(user_factory, 'TaEnrollment')
# Test that the page loads properly the first time.
get "/courses/#{@course.id}/users"
wait_for_ajaximations
expect_no_flash_message :error
expect(ff('.roster .rosterUser').length).to eq 50
end
it "should only show users that a user has permissions to view" do
# Set up the test
course_factory(active_course: true)
%w[One Two].each do |name|
section = @course.course_sections.create!(:name => name)
@course.enroll_student(user_factory, :section => section).accept!
end
user_logged_in
enrollment = @course.enroll_ta(@user)
enrollment.accept!
enrollment.update_attributes(:limit_privileges_to_course_section => true,
:course_section => CourseSection.where(name: 'Two').first)
# Test that only users in the approved section are displayed.
get "/courses/#{@course.id}/users"
wait_for_ajaximations
expect(ff('.roster .rosterUser').length).to eq 2
end
it "should display users section name" do
course_with_teacher_logged_in(:active_all => true)
user1, user2 = [user_factory, user_factory]
section1 = @course.course_sections.create!(:name => 'One')
section2 = @course.course_sections.create!(:name => 'Two')
@course.enroll_student(user1, :section => section1).accept!
[section1, section2].each do |section|
e = user2.student_enrollments.build
e.workflow_state = 'active'
e.course = @course
e.course_section = section
e.save!
end
get "/courses/#{@course.id}/users"
wait_for_ajaximations
sections = ff('.roster .section')
expect(sections.map(&:text).sort).to eq ["One", "One", "Two", "Unnamed Course", "Unnamed Course"]
end
context "course_home_sub_navigation lti apps" do
def create_course_home_sub_navigation_tool(options = {})
@course.root_account.enable_feature!(:lor_for_account)
defaults = {
name: options[:name] || "external tool",
consumer_key: 'test',
shared_secret: 'asdf',
url: 'http://example.com/ims/lti',
course_home_sub_navigation: { icon_url: '/images/delete.png' },
}
@course.context_external_tools.create!(defaults.merge(options))
end
it "should display course_home_sub_navigation lti apps", priority: "1", test_id: 2624910 do
course_with_teacher_logged_in(active_all: true)
num_tools = 2
num_tools.times { |index| create_course_home_sub_navigation_tool(name: "external tool #{index}") }
get "/courses/#{@course.id}"
expect(ff(".course-home-sub-navigation-lti").size).to eq num_tools
end
it "should include launch type parameter", priority: "1", test_id: 2624911 do
course_with_teacher_logged_in(active_all: true)
create_course_home_sub_navigation_tool
get "/courses/#{@course.id}"
expect(f('.course-home-sub-navigation-lti')).to have_attribute("href", /launch_type=course_home_sub_navigation/)
end
it "should only display active tools", priority: "1", test_id: 2624912 do
course_with_teacher_logged_in(active_all: true)
tool = create_course_home_sub_navigation_tool
tool.workflow_state = 'deleted'
tool.save!
get "/courses/#{@course.id}"
expect(f("#content")).not_to contain_css(".course-home-sub-navigation-lti")
end
it "should not display admin tools to students", priority: "1", test_id: 2624913 do
course_with_teacher_logged_in(active_all: true)
tool = create_course_home_sub_navigation_tool
tool.course_home_sub_navigation['visibility'] = 'admins'
tool.save!
get "/courses/#{@course.id}"
expect(ff(".course-home-sub-navigation-lti").size).to eq 1
course_with_student_logged_in(course: @course, active_all: true)
get "/courses/#{@course.id}"
expect(f("#content")).not_to contain_css(".course-home-sub-navigation-lti")
end
end
end
context "course as a student" do
def enroll_student(student, accept_invitation)
if accept_invitation
@course.enroll_student(student).accept
else
@course.enroll_student(student)
end
end
before (:each) do
course_with_teacher(:active_all => true, :name => 'discussion course')
@student = user_with_pseudonym(:active_user => true, :username => 'student@example.com', :name => 'student@example.com', :password => 'asdfasdf')
Account.default.settings[:allow_invitation_previews] = true
Account.default.save!
end
it "should auto-accept the course invitation if previews are not allowed" do
Account.default.settings[:allow_invitation_previews] = false
Account.default.save!
enroll_student(@student, false)
create_session(@student.pseudonym)
get "/courses/#{@course.id}"
assert_flash_notice_message "Invitation accepted!"
expect(f("#content")).not_to contain_css(".ic-notification button[name='accept'] ")
end
it "should accept the course invitation" do
enroll_student(@student, false)
create_session(@student.pseudonym)
get "/courses/#{@course.id}"
f(".ic-notification button[name='accept'] ").click
assert_flash_notice_message "Invitation accepted!"
end
it "should reject a course invitation" do
enroll_student(@student, false)
create_session(@student.pseudonym)
get "/courses/#{@course.id}"
f(".ic-notification button[name=reject]").click
assert_flash_notice_message "Invitation canceled."
end
it "should display user groups on courses page" do
group = Group.create!(:name => "group1", :context => @course)
group.add_user(@student)
enroll_student(@student, true)
create_session(@student.pseudonym)
get '/courses'
content = f('#content')
expect(content).to include_text('My Groups')
expect(content).to include_text('group1')
end
it "should reset cached permissions when enrollment is activated by date" do
enable_cache do
enroll_student(@student, true)
@course.start_at = 1.day.from_now
@course.restrict_enrollments_to_course_dates = true
@course.restrict_student_future_view = true
@course.save!
user_session(@student)
User.where(:id => @student).update_all(:updated_at => 5.minutes.ago) # make sure that touching the user resets the cache
get "/courses/#{@course.id}"
# cache unauthorized permission
expect(f('#unauthorized_message')).to be_displayed
# manually trigger a stale enrollment - should recalculate on visit if it didn't already in the background
Course.where(:id => @course).update_all(:start_at => 1.day.ago)
Enrollment.where(:id => @student.student_enrollments).update_all(:updated_at => 1.second.from_now) # because of enrollment date caching
EnrollmentState.where(:enrollment_id => @student.student_enrollments).update_all(:state_is_current => false)
refresh_page
expect(f('#course_home_content')).to be_displayed
end
end
end
it "shouldn't cache unauth permissions for semi-public courses from sessionless permission checks" do
course_factory(active_all: true)
@course.update_attribute(:is_public_to_auth_users, true)
user_factory(active_all: true)
user_session(@user)
enable_cache do
# previously was cached by visiting "/courses/#{@course.id}/assignments/syllabus"
expect(@course.grants_right?(@user, :read)).to be_falsey # requires session[:user_id] - caches a false value
get "/courses/#{@course.id}"
expect(f('#course_home_content')).to be_displayed
end
end
it "should display announcements on course home page if enabled and is wiki" do
course_with_teacher_logged_in :active_all => true
get "/courses/#{@course.id}"
expect(element_exists?('#announcements_on_home_page')).to be_falsey
text = "here's some html or whatever"
html = "<p>#{text}</p>"
@course.announcements.create!(:title => "something", :message => html)
@course.default_view = "wiki"
@course.show_announcements_on_home_page = true
@course.home_page_announcement_limit = 5
@course.save!
@course.wiki.wiki_pages.create!(:title => 'blah').set_as_front_page!
get "/courses/#{@course.id}"
expect(f('#announcements_on_home_page')).to be_displayed
expect(f('#announcements_on_home_page')).to contain_css("button")
f('#announcements_on_home_page button').click
expect(f('#announcements_on_home_page')).to include_text(text)
expect(f('#announcements_on_home_page')).to_not include_text(html)
end
end