forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_migrations_spec.rb
More file actions
633 lines (505 loc) · 21.8 KB
/
Copy pathcontent_migrations_spec.rb
File metadata and controls
633 lines (505 loc) · 21.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
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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
require File.expand_path(File.dirname(__FILE__) + '/common')
def visit_page
@course.reload
get "/courses/#{@course.id}/content_migrations"
end
def select_migration_type(type=nil)
type ||= @type
click_option('#chooseMigrationConverter', type, :value)
end
def select_migration_file(opts={})
filename = opts[:filename] || @filename
new_filename, fullpath, data = get_file(filename, opts[:data])
f('#migrationFileUpload').send_keys(fullpath)
return new_filename
end
def fill_migration_form(opts={})
select_migration_type('none') unless opts[:type] == 'none'
select_migration_type(opts[:type])
select_migration_file(opts)
end
def submit
@course.reload
# depending on the type of migration, we need to wait for it to have one of these states
scope = { workflow_state: %w[queued exporting exported] }
count = @course.content_migrations.where(scope).count
driver.execute_script("$('#migrationConverterContainer').submit()")
keep_trying_until do
expect(@course.content_migrations.where(scope).count).to eq count + 1
end
end
def run_migration(cm=nil)
cm ||= @course.content_migrations.last
cm.reload
cm.skip_job_progress = false
cm.reset_job_progress
worker_class = Canvas::Migration::Worker.const_get(Canvas::Plugin.find(cm.migration_type).settings['worker'])
worker_class.new(cm.id).perform
end
def import(cm=nil)
cm ||= @course.content_migrations.last
cm.reload
cm.set_default_settings
cm.import_content
end
def test_selective_content(source_course=nil)
visit_page
# Open selective dialog
expect(f('.migrationProgressItem .progressStatus')).to include_text("Waiting for select")
f('.migrationProgressItem .selectContentBtn').click
wait_for_ajaximations
f('input[name="copy[all_assignments]"]').click
# Submit selection
f(".selectContentDialog input[type=submit]").click
wait_for_ajaximations
if source_course
run_migration
else
import
end
visit_page
expect(f('.migrationProgressItem .progressStatus')).to include_text("Completed")
expect(@course.assignments.count).to eq(source_course ? source_course.assignments.count : 1)
end
describe "content migrations", :non_parallel do
include_context "in-process server selenium tests"
context "common cartridge importing" do
before :each do
course_with_teacher_logged_in
@type = 'common_cartridge_importer'
@filename = 'cc_full_test.zip'
end
# TODO reimplement per CNVS-29593, but make sure we're testing at the right level
it "should import all content immediately by default"
it "should show each form" do
visit_page
migration_types = ff('#chooseMigrationConverter option').map { |op| op['value'] } - ['none']
migration_types.each do |type|
select_migration_type(type)
expect(f("#content")).to contain_jqcss("input[type=\"submit\"]:visible")
select_migration_type('none')
expect(f("#content")).not_to contain_jqcss("input[type=\"submit\"]:visible")
end
select_migration_type
cancel_btn = f('#migrationConverterContainer .cancelBtn')
expect(cancel_btn).to be_displayed
cancel_btn.click
expect(f("#content")).not_to contain_css('#migrationFileUpload')
end
it "should submit, queue and list migrations" do
visit_page
fill_migration_form
ff('[name=selective_import]')[0].click
submit
expect(ff('.migrationProgressItem').count).to eq 1
fill_migration_form(:filename => 'cc_ark_test.zip')
ff('[name=selective_import]')[0].click
submit
visit_page
expect(@course.content_migrations.count).to eq 2
progress_items = ff('.migrationProgressItem')
expect(progress_items.count).to eq 2
source_links = []
progress_items.each do |item|
expect(item.find_element(:css, '.migrationName')).to include_text('Common Cartridge')
expect(item.find_element(:css, '.progressStatus')).to include_text('Queued')
source_links << item.find_element(:css, '.sourceLink a')
end
hrefs = source_links.map { |a| a.attribute(:href) }
@course.content_migrations.each do |cm|
expect(hrefs.find { |href| href.include?("/files/#{cm.attachment.id}/download") }).not_to be_nil
end
end
# TODO reimplement per CNVS-29594, but make sure we're testing at the right level
it "should import selective content"
# TODO reimplement per CNVS-29595, but make sure we're testing at the right level
it "should overwrite quizzes when option is checked and duplicate otherwise"
it "should shift dates" do
visit_page
fill_migration_form
f('#dateAdjustCheckbox').click
ff('[name=selective_import]')[0].click
set_value f('#oldStartDate'), '7/1/2014'
set_value f('#oldEndDate'), 'Jul 11, 2014'
set_value f('#newStartDate'), '8-5-2014'
set_value f('#newEndDate'), 'Aug 15, 2014'
2.times { f('#addDaySubstitution').click }
click_option('#daySubstitution ul > div:nth-child(1) .currentDay', "1", :value)
click_option('#daySubstitution ul > div:nth-child(1) .subDay', "2", :value)
click_option('#daySubstitution ul > div:nth-child(2) .currentDay', "5", :value)
click_option('#daySubstitution ul > div:nth-child(2) .subDay', "4", :value)
submit
opts = @course.content_migrations.last.migration_settings["date_shift_options"]
expect(opts["shift_dates"]).to eq '1'
expect(opts["day_substitutions"]).to eq({"1" => "2", "5" => "4"})
expect(Date.parse(opts["old_start_date"])).to eq Date.new(2014, 7, 1)
expect(Date.parse(opts["old_end_date"])).to eq Date.new(2014, 7, 11)
expect(Date.parse(opts["new_start_date"])).to eq Date.new(2014, 8, 5)
expect(Date.parse(opts["new_end_date"])).to eq Date.new(2014, 8, 15)
end
# TODO reimplement per CNVS-29596, but make sure we're testing at the right level
it "should remove dates"
context "default question bank" do
# TODO reimplement per CNVS-29597, but make sure we're testing at the right level
it "should import into selected question bank"
# TODO reimplement per CNVS-29598, but make sure we're testing at the right level
it "should import into new question bank"
# TODO reimplement per CNVS-29599, but make sure we're testing at the right level
it "should import into default question bank if not selected"
end
end
context "course copy" do
before :once do
#the "true" param is important, it forces the cache clear
# without it this spec group fails if
# you run it with the whole suite
# because of a cached default account
# that no longer exists in the db
Account.clear_special_account_cache!(true)
@copy_from = course_factory
@copy_from.update_attribute(:name, 'copy from me')
data = File.read(File.dirname(__FILE__) + '/../fixtures/migration/cc_full_test.zip')
cm = ContentMigration.new(:context => @copy_from, :migration_type => "common_cartridge_importer")
cm.migration_settings = {:import_immediately => true,
:migration_ids_to_import => {:copy => {:everything => true}}}
cm.skip_job_progress = true
cm.save!
att = attachment_model(:context => cm, :filename => "cc_full_test.zip",
:uploaded_data => stub_file_data("cc_full_test.zip", data, "application/zip"))
cm.attachment = att
cm.save!
worker_class = Canvas::Migration::Worker.const_get(Canvas::Plugin.find(cm.migration_type).settings['worker'])
worker_class.new(cm.id).perform
@course = nil
@type = "course_copy_importer"
end
before :each do
course_with_teacher_logged_in(:active_all => true)
@copy_from.enroll_teacher(@user).accept
end
it "should show warning before self-copy", priority: "1", test_id: 2889675 do
visit_page
select_migration_type
wait_for_ajaximations
# drop-down
click_option('#courseSelect', @course.id.to_s, :value)
wait_for_ajaximations
expect(f('#courseSelectWarning')).to be_displayed
click_option('#courseSelect', @copy_from.id.to_s, :value)
wait_for_ajaximations
expect(f('#courseSelectWarning')).to_not be_displayed
end
it "should select by drop-down or by search box", priority: "2", test_id: 2889684 do
visit_page
select_migration_type
wait_for_ajaximations
# drop-down
expect(f("option[value=\"#{@copy_from.id}\"]")).not_to be_nil
# search bar
f('#courseSearchField').send_keys("cop")
ui_auto_complete = f('.ui-autocomplete')
expect(ui_auto_complete).to be_displayed
el = f('.ui-autocomplete li a')
divs = ff('div', el)
expect(divs[0].text).to eq @copy_from.name
expect(divs[1].text).to eq @copy_from.enrollment_term.name
el.click
ff('[name=selective_import]')[0].click
submit
cm = @course.content_migrations.last
expect(cm.migration_settings["source_course_id"]).to eq @copy_from.id
expect(cm.source_course).to eq @copy_from
expect(cm.initiated_source).to eq :api
source_link = f('.migrationProgressItem .sourceLink a')
expect(source_link.text).to eq @copy_from.name
expect(source_link['href']).to include("/courses/#{@copy_from.id}")
end
it "should only show courses the user is authorized to see", priority: "1", test_id: 2889686 do
new_course = Course.create!(:name => "please don't see me")
visit_page
select_migration_type
wait_for_ajaximations
expect(f("option[value=\"#{@copy_from.id}\"]")).not_to be_nil
expect(f("#content")).not_to contain_css("option[value=\"#{new_course.id}\"]")
admin_logged_in
visit_page
select_migration_type
wait_for_ajaximations
expect(f("option[value=\"#{new_course.id}\"]")).not_to be_nil
end
it "should include completed courses when checked", priority: "1", test_id: 2889687 do
new_course = Course.create!(:name => "completed course")
new_course.enroll_teacher(@user).accept
new_course.complete!
visit_page
select_migration_type
wait_for_ajaximations
expect(f("#content")).not_to contain_css("option[value=\"#{new_course.id}\"]")
f('#include_completed_courses').click
expect(f("option[value=\"#{new_course.id}\"]")).not_to be_nil
end
it "should find courses in other accounts", priority: "1", test_id: 2890402 do
new_account1 = account_model
enrolled_course = Course.create!(:name => "faraway course", :account => new_account1)
enrolled_course.enroll_teacher(@user).accept
new_account2 = account_model
admin_course = Course.create!(:name => "another course", :account => new_account2)
account_admin_user(:user => @user, :account => new_account2)
visit_page
select_migration_type
wait_for_ajaximations
expect(f("option[value=\"#{admin_course.id}\"]")).not_to be_nil
expect(f("option[value=\"#{enrolled_course.id}\"]")).not_to be_nil
end
it "should copy all content from a course", priority: "1", test_id: 126677 do
skip unless Qti.qti_enabled?
visit_page
select_migration_type
wait_for_ajaximations
click_option('#courseSelect', @copy_from.id.to_s, :value)
ff('[name=selective_import]')[0].click
submit
run_migration
expect(@course.attachments.count).to eq 10
expect(@course.discussion_topics.count).to eq 2
expect(@course.context_modules.count).to eq 3
expect(@course.context_external_tools.count).to eq 2
expect(@course.quizzes.count).to eq 1
expect(@course.quizzes.first.quiz_questions.count).to eq 11
end
it "should selectively copy content", priority: "1", test_id: 126682 do
skip unless Qti.qti_enabled?
visit_page
select_migration_type
wait_for_ajaximations
click_option('#courseSelect', @copy_from.id.to_s, :value)
ff('[name=selective_import]')[1].click
submit
test_selective_content(@copy_from)
end
it "should set day substitution and date adjustment settings", priority: "1", test_id: 2891737 do
new_course = Course.create!(:name => "day sub")
new_course.enroll_teacher(@user).accept
visit_page
select_migration_type
wait_for_ajaximations
click_option('#courseSelect', new_course.id.to_s, :value)
f('#dateAdjustCheckbox').click
3.times do
f('#addDaySubstitution').click
end
expect(ff("#daySubstitution ul > div").count).to eq 3
f("#daySubstitution ul > div a").click # Remove day substitution
expect(ff("#daySubstitution ul > div").count).to eq 2
click_option('#daySubstitution ul > div:nth-child(1) .currentDay', "1", :value)
click_option('#daySubstitution ul > div:nth-child(1) .subDay', "2", :value)
click_option('#daySubstitution ul > div:nth-child(2) .currentDay', "2", :value)
click_option('#daySubstitution ul > div:nth-child(2) .subDay', "3", :value)
f('#oldStartDate').send_keys('7/1/2012')
f('#oldEndDate').send_keys('Jul 11, 2012')
f('#newStartDate').clear
f('#newStartDate').send_keys('8-5-2012')
f('#newEndDate').send_keys('Aug 15, 2012')
ff('[name=selective_import]')[0].click
submit
opts = @course.content_migrations.last.migration_settings["date_shift_options"]
expect(opts["shift_dates"]).to eq '1'
expect(opts["day_substitutions"]).to eq({"1" => "2", "2" => "3"})
expected = {
"old_start_date" => "Jul 1, 2012", "old_end_date" => "Jul 11, 2012",
"new_start_date" => "Aug 5, 2012", "new_end_date" => "Aug 15, 2012"
}
expected.each do |k, v|
expect(Date.parse(opts[k].to_s)).to eq Date.parse(v)
end
end
it "should set pre-populate date adjustment settings" do
new_course = Course.create!(:name => "date adjust", :start_at => 'Jul 1, 2012', :conclude_at => 'Jul 11, 2012')
new_course.enroll_teacher(@user).accept
@course.start_at = 'Aug 5, 2012'
@course.conclude_at = 'Aug 15, 2012'
@course.save!
visit_page
select_migration_type
wait_for_ajaximations
click_option('#courseSelect', new_course.id.to_s, :value)
f('#dateAdjustCheckbox').click
ff('[name=selective_import]')[0].click
submit
opts = @course.content_migrations.last.migration_settings["date_shift_options"]
expect(opts["shift_dates"]).to eq '1'
expect(opts["day_substitutions"]).to eq({})
expected = {
"old_start_date" => "Jul 1, 2012", "old_end_date" => "Jul 11, 2012",
"new_start_date" => "Aug 5, 2012", "new_end_date" => "Aug 15, 2012"
}
expected.each do |k, v|
expect(Date.parse(opts[k].to_s)).to eq Date.parse(v)
end
end
it "should remove dates", priority: "1", test_id: 2891742 do
new_course = Course.create!(:name => "date remove", :start_at => 'Jul 1, 2014', :conclude_at => 'Jul 11, 2014')
new_course.enroll_teacher(@user).accept
visit_page
select_migration_type
wait_for_ajaximations
click_option('#courseSelect', new_course.id.to_s, :value)
f('#dateAdjustCheckbox').click
f('#dateRemoveOption').click
ff('[name=selective_import]')[0].click
submit
opts = @course.content_migrations.last.migration_settings["date_shift_options"]
expect(opts["remove_dates"]).to eq '1'
end
it "should retain announcement content settings after course copy", priority: "2", test_id: 403057 do
@announcement = @copy_from.announcements.create!(:title => 'Migration', :message => 'Here is my message')
@copy_from.lock_all_announcements = true
@copy_from.save!
visit_page
select_migration_type
wait_for_ajaximations
click_option('#courseSelect', @copy_from.id.to_s, :value)
ff('[name=selective_import]')[0].click
submit
run_jobs
expect(f('.migrationProgressItem .progressStatus')).to include_text("Completed")
@course.reload
expect(@course.announcements.last.locked).to be_truthy
expect(@course.lock_all_announcements).to be_truthy
end
it "should persist topic 'allow liking' settings across course copy", priority: "2", test_id: 1041950 do
@copy_from.discussion_topics.create!(
title: 'Liking Allowed Here',
message: 'Like I said, liking is allowed',
allow_rating: true
)
visit_page
select_migration_type
wait_for_ajaximations
click_option('#courseSelect', @copy_from.id.to_s, :value)
ff('[name=selective_import]')[0].click
submit
run_jobs
expect(f('.migrationProgressItem .progressStatus')).to include_text("Completed")
@course.reload
expect(@course.discussion_topics.last.allow_rating).to be_truthy
end
end
context "importing LTI content" do
let(:import_course) {
account = account_model
account.enable_feature!(:lor_for_account)
course_with_teacher_logged_in(:account => account).course
}
let(:import_tool) do
tool = import_course.context_external_tools.new({
name: "test lti import tool",
consumer_key: "key",
shared_secret: "secret",
url: "http://www.example.com/ims/lti",
})
tool.migration_selection = {
url: "http://#{HostUrl.default_host}/selection_test",
text: "LTI migration text",
selection_width: 500,
selection_height: 500,
icon_url: "/images/add.png",
}
tool.save!
tool
end
let(:other_tool) do
tool = import_course.context_external_tools.new({
name: "other lti tool",
consumer_key: "key",
shared_secret: "secret",
url: "http://www.example.com/ims/lti",
})
tool.resource_selection = {
url: "http://#{HostUrl.default_host}/selection_test",
text: "other resource text",
selection_width: 500,
selection_height: 500,
icon_url: "/images/add.png",
}
tool.save!
tool
end
it "should show LTI tools with migration_selection in the select control" do
import_tool
other_tool
visit_page
migration_type_options = ff('#chooseMigrationConverter option')
migration_type_values = migration_type_options.map { |op| op['value'] }
migration_type_texts = migration_type_options.map { |op| op.text }
expect(migration_type_values).to include(import_tool.asset_string)
expect(migration_type_texts).to include(import_tool.name)
expect(migration_type_values).not_to include(other_tool.asset_string)
expect(migration_type_texts).not_to include(other_tool.name)
end
it "should show LTI view when LTI tool selected" do
import_tool
visit_page
select_migration_type(import_tool.asset_string)
expect(f("#converter .externalToolLaunch")).to be_displayed
expect(f("#converter .selectContent")).to be_displayed
end
it "should launch LTI tool on browse and get content link" do
import_tool
visit_page
select_migration_type(import_tool.asset_string)
f("button#externalToolLaunch").click
tool_iframe = f(".tool_launch")
expect(f('.ui-dialog-title').text).to eq import_tool.label_for(:migration_selection)
driver.switch_to.frame(tool_iframe)
f("#basic_lti_link").click
driver.switch_to.default_content
expect(f("#converter .file_name")).to include_text "lti embedded link"
end
it "should have content selection option" do
import_tool
visit_page
select_migration_type(import_tool.asset_string)
expect(ff('input[name=selective_import]').size).to eq 2
end
end
it "should be able to selectively import common cartridge submodules" do
course_with_teacher_logged_in
cm = ContentMigration.new(:context => @course, :user => @user)
cm.migration_type = 'common_cartridge_importer'
cm.save!
package_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/cc_full_test.zip")
attachment = Attachment.new
attachment.context = cm
attachment.filename = "file.zip"
attachment.uploaded_data = File.open(package_path, 'rb')
attachment.save!
cm.attachment = attachment
cm.save!
cm.queue_migration
run_jobs
visit_page
f('.migrationProgressItem .selectContentBtn').click
wait_for_ajaximations
f('li.top-level-treeitem[data-type="context_modules"] a.checkbox-caret').click
wait_for_ajaximations
submod = f('li.top-level-treeitem[data-type="context_modules"] li.normal-treeitem')
expect(submod).to include_text("1 sub-module")
submod.find_element(:css, "a.checkbox-caret").click
wait_for_ajaximations
expect(submod.find_element(:css, ".module_options")).to_not be_displayed
sub_submod = submod.find_element(:css, "li.normal-treeitem")
expect(sub_submod).to include_text("Study Guide")
sub_submod.find_element(:css, 'input[type="checkbox"]').click
wait_for_ajaximations
expect(submod.find_element(:css, ".module_options")).to be_displayed # should show the module option now
# select to import submodules individually
radio_to_click = submod.find_element(:css, 'input[type="radio"][value="separate"]')
move_to_click("label[for=#{radio_to_click['id']}]")
f(".selectContentDialog input[type=submit]").click
wait_for_ajaximations
run_jobs
expect(@course.context_modules.count).to eq 1
expect(@course.context_modules.first.name).to eq "Study Guide"
end
end