forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_files_spec.rb
More file actions
463 lines (400 loc) · 18.5 KB
/
Copy pathnew_files_spec.rb
File metadata and controls
463 lines (400 loc) · 18.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
require File.expand_path(File.dirname(__FILE__) + '/common')
require File.expand_path(File.dirname(__FILE__) + '/helpers/files_common')
require File.expand_path(File.dirname(__FILE__) + '/helpers/public_courses_context')
describe "better_file_browsing" do
include_context "in-process server selenium tests"
include FilesCommon
context "As a teacher" do
before(:once) do
course_with_teacher(active_all: true)
add_file(fixture_file_upload('files/example.pdf', 'application/pdf'),
@course, "example.pdf")
end
before(:each) do
user_session @teacher
end
it "should display new files UI", priority: "1", test_id: 133092 do
get "/courses/#{@course.id}/files"
expect(f('.btn-upload')).to be_displayed
expect(all_files_folders.count).to eq 1
end
it "should load correct column values on uploaded file", priority: "1", test_id: 133129 do
get "/courses/#{@course.id}/files"
time_current = @course.attachments.first.updated_at.strftime("%l:%M%P").strip
expect(ff('.ef-name-col__text')[0]).to include_text 'example.pdf'
expect(ff('.ef-date-created-col')[1]).to include_text time_current
expect(ff('.ef-date-modified-col')[1]).to include_text time_current
expect(ff('.ef-size-col')[1]).to include_text '194 KB'
end
context "from cog icon" do
before :each do
get "/courses/#{@course.id}/files"
end
it "should edit file name", priority: "1", test_id: 133127 do
expect(fln("example.pdf")).to be_present
file_rename_to = "Example_edited.pdf"
edit_name_from_cog_icon(file_rename_to)
expect(f("#content")).not_to contain_link("example.pdf")
expect(fln(file_rename_to)).to be_present
end
it "should delete file", priority: "1", test_id: 133128 do
delete(0, :cog_icon)
expect(f("body")).not_to contain_css('.ef-item-row')
end
end
context "from cloud icon" do
before :each do
get "/courses/#{@course.id}/files"
end
it "should unpublish and publish a file", priority: "1", test_id: 133096 do
set_item_permissions(:unpublish, :cloud_icon)
expect(f('.btn-link.published-status.unpublished')).to be_displayed
set_item_permissions(:publish, :cloud_icon)
expect(f('.btn-link.published-status.published')).to be_displayed
end
it "should make file available to student with link", priority: "1", test_id: 223504 do
set_item_permissions(:restricted_access, :available_with_link, :cloud_icon)
expect(f('.btn-link.published-status.hiddenState')).to be_displayed
end
it "should make file available to student within given timeframe", priority: "1", test_id: 223505 do
set_item_permissions(:restricted_access, :available_with_timeline, :cloud_icon)
expect(f('.btn-link.published-status.restricted')).to be_displayed
end
end
context "from toolbar menu" do
it "should delete file from toolbar", priority: "1", test_id: 133105 do
get "/courses/#{@course.id}/files"
delete(0, :toolbar_menu)
expect(f("body")).not_to contain_css('.ef-item-row')
end
it "should unpublish and publish a file", priority: "1", test_id: 223503 do
get "/courses/#{@course.id}/files"
set_item_permissions(:unpublish, :toolbar_menu)
expect(f('.btn-link.published-status.unpublished')).to be_displayed
set_item_permissions(:publish, :toolbar_menu)
expect(f('.btn-link.published-status.published')).to be_displayed
end
it "should make file available to student with link from toolbar", priority: "1", test_id: 193158 do
get "/courses/#{@course.id}/files"
set_item_permissions(:restricted_access, :available_with_link, :toolbar_menu)
expect(f('.btn-link.published-status.hiddenState')).to be_displayed
end
it "should make file available to student within given timeframe from toolbar", priority: "1", test_id: 193159 do
get "/courses/#{@course.id}/files"
set_item_permissions(:restricted_access, :available_with_timeline, :toolbar_menu)
expect(f('.btn-link.published-status.restricted')).to be_displayed
end
it "should disable the file preview button when a folder is selected" do
folder_model(name: 'Testing')
get "/courses/#{@course.id}/files"
fj('.ef-item-row:contains("Testing")').click
expect(f('.Toolbar__ViewBtn--onlyfolders')).to be_displayed
end
end
context "accessibility tests for preview" do
before do
get "/courses/#{@course.id}/files"
fln("example.pdf").click
end
it "tabs through all buttons in the header button bar", priority: "1", test_id: 193816 do
buttons = ff('.ef-file-preview-header-buttons > *')
driver.execute_script("$('.ef-file-preview-header-buttons').children().first().focus()")
buttons.each do |button|
check_element_has_focus(button)
button.send_keys("\t")
end
end
it "returns focus to the link that was clicked when closing with the esc key", priority: "1", test_id: 193817 do
driver.switch_to.active_element.send_keys :escape
check_element_has_focus(fln("example.pdf"))
end
it "returns focus to the link when the close button is clicked", priority: "1", test_id: 193818 do
f('.ef-file-preview-header-close').click
check_element_has_focus(fln("example.pdf"))
end
end
context "accessibility tests for Toolbar Previews" do
it "returns focus to the preview toolbar button when closed", priority: "1", test_id: 193819 do
get "/courses/#{@course.id}/files"
ff('.ef-item-row')[0].click
f('.btn-view').click
f('.ef-file-preview-header-close').click
check_element_has_focus(f('.btn-view'))
end
end
end
context "when a public course is accessed" do
include_context "public course as a logged out user"
it "should display course files", priority: "1", test_id: 270032 do
get "/courses/#{public_course.id}/files"
expect(f('div.ef-main[data-reactid]')).to be_displayed
end
end
context "Search textbox" do
before(:each) do
course_with_teacher_logged_in
txt_files = ["a_file.txt", "b_file.txt", "c_file.txt"]
txt_files.map do |text_file|
add_file(fixture_file_upload("files/#{text_file}", 'text/plain'), @course, text_file)
end
get "/courses/#{@course.id}/files"
end
it "should search for a file", priority: "2", test_id: 220355 do
expect(all_files_folders).to have_size 3
f("input[type='search']").send_keys "b_fi", :return
expect(all_files_folders).to have_size 1
end
end
context "Move dialog" do
before(:once) do
course_with_teacher(active_all: true)
txt_files = ["a_file.txt", "b_file.txt", "c_file.txt"]
txt_files.map { |text_file| add_file(fixture_file_upload("files/#{text_file}", 'text/plain'), @course, text_file) }
end
before(:each) do
user_session(@teacher)
end
it "should set focus to the folder tree when opening the dialog", priority: "1", test_id: 220356 do
get "/courses/#{@course.id}/files"
ff('.al-trigger')[0].click
fln("Move").click
wait_for_ajaximations
check_element_has_focus(ff('.tree')[1])
end
it "should move a file using cog icon", priority: "1", test_id: 133103 do
file_name = "a_file.txt"
folder_model(name: "destination_folder")
get "/courses/#{@course.id}/files"
move(file_name, 0, :cog_icon)
expect(f("#flash_message_holder")).to include_text "#{file_name} moved to destination_folder"
expect(ff('.ef-name-col__text')[0]).not_to include_text file_name
ff('.ef-name-col__text')[2].click
expect(fln(file_name)).to be_displayed
end
it "should move a file using toolbar menu", priority: "1", test_id: 217603 do
file_name = "a_file.txt"
folder_model(name: "destination_folder")
get "/courses/#{@course.id}/files"
move(file_name, 0, :toolbar_menu)
expect(f("#flash_message_holder")).to include_text "#{file_name} moved to destination_folder"
expect(ff('.ef-name-col__text')[0]).not_to include_text file_name
ff('.ef-name-col__text')[2].click
expect(fln(file_name)).to be_displayed
end
it "should move multiple files", priority: "1", test_id: 220357 do
files = ["a_file.txt", "b_file.txt", "c_file.txt"]
folder_model(name: "destination_folder")
get "/courses/#{@course.id}/files"
move_multiple_using_toolbar(files)
expect(f("#flash_message_holder")).to include_text "#{files.count} items moved to destination_folder"
expect(ff('.ef-name-col__text')[0]).not_to include_text files[0]
ff('.ef-name-col__text')[0].click
files.each do |file|
expect(fln(file)).to be_displayed
end
end
context "Search Results" do
def search_and_move(file_name: "", destination: "My Files")
f("input[type='search']").send_keys file_name, :return
expect(f('.ef-item-row')).to include_text file_name
move(file_name, 0, :cog_icon, destination)
final_destination = destination.split('/').pop
expect(f("#flash_message_holder")).to include_text "#{file_name} moved to #{final_destination}"
fj("a.treeLabel span:contains('#{final_destination}')").click
expect(fln(file_name)).to be_displayed
end
before(:once) do
user_files = ["a_file.txt", "b_file.txt"]
user_files.map { |text_file| add_file(fixture_file_upload("files/#{text_file}", 'text/plain'), @teacher, text_file) }
# Course file
add_file(fixture_file_upload("files/c_file.txt", 'text/plain'), @course, "c_file.txt")
end
let(:folder_name) { "destination_folder" }
it "should move a file to a destination if contexts are different" do
skip_if_chrome('research')
folder_model(name: folder_name)
get "/files"
search_and_move(file_name: "a_file.txt", destination: "#{@course.name}/#{folder_name}")
end
it "should move a file to a destination if the contexts are the same" do
skip_if_chrome('research')
folder_model(name: folder_name, context: @user)
get "/files"
search_and_move(file_name: "a_file.txt", destination: folder_name)
end
end
end
context "Publish Cloud Dialog" do
before(:once) do
course_with_teacher(active_all: true)
add_file(fixture_file_upload('files/a_file.txt', 'text/plain'),
@course, "a_file.txt")
end
before(:each) do
user_session(@teacher)
get "/courses/#{@course.id}/files"
end
it "should validate that file is published by default", priority: "1", test_id: 193820 do
expect(f('.btn-link.published-status.published')).to be_displayed
end
it "should set focus to the close button when opening the dialog", priority: "1", test_id: 194243 do
f('.btn-link.published-status').click
wait_for_ajaximations
shouldFocus = f('.ui-dialog-titlebar-close')
element = driver.switch_to.active_element
expect(element).to eq(shouldFocus)
end
end
context "File Preview" do
before(:each) do
course_with_teacher_logged_in
add_file(fixture_file_upload('files/a_file.txt', 'text/plain'),
@course, "a_file.txt")
add_file(fixture_file_upload('files/b_file.txt', 'text/plain'),
@course, "b_file.txt")
get "/courses/#{@course.id}/files"
end
it "should switch files in preview when clicking the arrows" do
fln("a_file.txt").click
ff('.ef-file-preview-container-arrow-link')[0].click
expect(f('.ef-file-preview-header-filename')).to include_text('b_file.txt')
ff('.ef-file-preview-container-arrow-link')[1].click
expect(f('.ef-file-preview-header-filename')).to include_text('a_file.txt')
end
end
context "Usage Rights Dialog" do
def set_usage_rights_in_modal(rights = 'creative_commons')
set_value f('.UsageRightsSelectBox__select'), rights
if rights == 'creative_commons'
set_value f('.UsageRightsSelectBox__creativeCommons'), 'cc_by'
end
set_value f('#copyrightHolder'), 'Test User'
f('.ReactModal__Footer-Actions .btn-primary').click
expect(f("body")).not_to contain_css('.ReactModal__Content')
end
def verify_usage_rights_ui_updates(iconClass = 'icon-files-creative-commons')
expect(f(".UsageRightsIndicator__openModal i.#{iconClass}")).to be_displayed
end
before :once do
course_with_teacher(active_all: true)
Account.default.enable_feature!(:usage_rights_required)
add_file(fixture_file_upload('files/a_file.txt', 'text/plan'),
@course, "a_file.txt")
add_file(fixture_file_upload('files/amazing_file.txt', 'text/plan'),
@user, "amazing_file.txt")
add_file(fixture_file_upload('files/a_file.txt', 'text/plan'),
@user, "a_file.txt")
end
before :each do
user_session @teacher
end
context "course files" do
it "should set usage rights on a file via the modal by clicking the indicator", priority: "1", test_id: 194244 do
get "/courses/#{@course.id}/files"
f('.UsageRightsIndicator__openModal').click
set_usage_rights_in_modal
# a11y: focus should go back to the element that was clicked.
check_element_has_focus(f('.UsageRightsIndicator__openModal'))
verify_usage_rights_ui_updates
end
it "should set usage rights on a file via the cog menu", priority: "1", test_id: 194245 do
get "/courses/#{@course.id}/files"
f('.ef-links-col .al-trigger').click
f('.ItemCog__OpenUsageRights a').click
set_usage_rights_in_modal
# a11y: focus should go back to the element that was clicked.
check_element_has_focus(f('.ef-links-col .al-trigger'))
verify_usage_rights_ui_updates
end
it "should set usage rights on a file via the toolbar", priority: "1", test_id: 132584 do
get "/courses/#{@course.id}/files"
f('.ef-item-row').click
f('.Toolbar__ManageUsageRights').click
set_usage_rights_in_modal
# a11y: focus should go back to the element that was clicked.
check_element_has_focus(f('.Toolbar__ManageUsageRights'))
verify_usage_rights_ui_updates
end
it "should set usage rights on a file inside a folder via the toolbar", priority: "1", test_id: 132585 do
folder_model name: "new folder"
get "/courses/#{@course.id}/files"
move("a_file.txt", 0, :cog_icon)
wait_for_ajaximations
f('.ef-item-row').click
f('.Toolbar__ManageUsageRights').click
expect(f('.UsageRightsDialog__fileName')).to include_text "new folder"
expect(f(".UsageRightsSelectBox__select")).to be_displayed
set_usage_rights_in_modal
# a11y: focus should go back to the element that was clicked.
check_element_has_focus(f('.Toolbar__ManageUsageRights'))
ff('.ef-name-col__text')[0].click
verify_usage_rights_ui_updates
end
it "should not show the creative commons selection if creative commons isn't selected", priority: "1", test_id: 194247 do
get "/courses/#{@course.id}/files"
f('.UsageRightsIndicator__openModal').click
set_value f('.UsageRightsSelectBox__select'), 'fair_use'
expect(f('.UsageRightsSelectBox__container')).not_to contain_css('.UsageRightsSelectBox__creativeCommons')
end
it "should publish warning when usage rights is not selected", priority: "2", test_id: 133135 do
get "/courses/#{@course.id}/files"
expect(f('.icon-warning')).to be_present
f('.icon-publish').click
f('.form-controls .btn-primary').click
expect(f('.errorBox')).to be_present
end
end
context "user files" do
it "should update course files from user files page", priority: "1", test_id: 194248 do
get "/files/folder/courses_#{@course.id}/"
f('.UsageRightsIndicator__openModal').click
set_usage_rights_in_modal
# a11y: focus should go back to the element that was clicked.
check_element_has_focus(f('.UsageRightsIndicator__openModal'))
verify_usage_rights_ui_updates
end
it "should copy a file to a different context", priority: "1", test_id: 194249 do
get "/files/"
file_name = "amazing_file.txt"
move(file_name, 1, :cog_icon)
expect(f("#flash_message_holder")).to include_text "#{file_name} moved to course files"
expect(ff('.ef-name-col__text')[1]).to include_text file_name
end
it "should show modal on how to handle duplicates when copying files", priority: "1", test_id: 194250 do
get "/files/"
file_name = "a_file.txt"
move(file_name, 0, :cog_icon)
expect(f("#renameFileMessage")).to include_text "An item named \"#{file_name}\" already exists in this location. Do you want to replace the existing file?"
ff(".btn-primary")[2].click
expect(f("#flash_message_holder")).to include_text "#{file_name} moved to course files"
expect(ff('.ef-name-col__text')[0]).to include_text file_name
end
end
end
context "When Require Usage Rights is turned-off" do
it "sets files to published by default", priority: "1", test_id: 133136 do
course_with_teacher_logged_in
Account.default.disable_feature!(:usage_rights_required)
add_file(fixture_file_upload("files/b_file.txt", 'text/plain'), @course, 'b_file.txt')
get "/courses/#{@course.id}/files"
expect(f('.btn-link.published-status.published')).to be_displayed
end
end
context "Directory Header" do
it "should sort the files properly", priority: 2, test_id: 1664875 do
# this test performs 2 sample sort combinations
course_with_teacher_logged_in
add_file(fixture_file_upload('files/example.pdf', 'application/pdf'), @course, "a_example.pdf")
add_file(fixture_file_upload("files/b_file.txt", 'text/plain'), @course, 'b_file.txt')
get "/courses/#{@course.id}/files"
# click name once to make it sort descending
fj('.ef-plain-link span:contains("Name")').click
expect(ff('.ef-name-col__text')[0]).to include_text 'example.pdf'
expect(ff('.ef-name-col__text')[1]).to include_text 'b_file.txt'
# click size twice to make it sort ascending
2.times { fj('.ef-plain-link span:contains("Size")').click }
expect(ff('.ef-name-col__text')[0]).to include_text 'b_file.txt'
expect(ff('.ef-name-col__text')[1]).to include_text 'example.pdf'
end
end
end