forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles_common.rb
More file actions
206 lines (189 loc) · 6.82 KB
/
Copy pathfiles_common.rb
File metadata and controls
206 lines (189 loc) · 6.82 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
#
# Copyright (C) 2012 - 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')
module FilesCommon
# This method adds the specified file to the course
# Params:
# - fixture: location of the file to be uploaded
# - context: course in which file would be uploaded
# - name: file name
# - folder: course folder it should go under (defaults to root folder)
def add_file(fixture, context, name, folder = Folder.root_folders(context).first)
context.attachments.create! do |attachment|
attachment.uploaded_data = fixture
attachment.filename = name
attachment.folder = folder
end
end
def edit_name_from_cog_icon(file_name_new, row_selected = 0)
ff('.al-trigger-gray')[row_selected].click
fln("Rename").click
expect(f(".ef-edit-name-cancel")).to be_displayed
file_name_textbox_el = f('.ef-edit-name-form__input')
replace_content(file_name_textbox_el, file_name_new)
file_name_textbox_el.send_keys(:return)
end
def delete(row_selected = 0, delete_using = :cog_icon)
if delete_using == :cog_icon
ff('.al-trigger')[row_selected].click
fln("Delete").click
elsif delete_using == :toolbar_menu
ff('.ef-item-row')[row_selected].click
f('.btn-delete').click
end
confirm_delete_on_dialog
end
def move(file_name, row_selected = 0, move_using = :cog_icon, destination = nil)
if move_using == :cog_icon
ff('.al-trigger')[row_selected].click
fln("Move").click
elsif move_using == :toolbar_menu
ff('.ef-item-row')[row_selected].click
f('.btn-move').click
end
expect(f(".ReactModal__Header-Title h4")).to include_text "Where would you like to move #{file_name}?"
if destination.present?
folders = destination.split('/')
folders.each do |folder|
fj(".ReactModal__Body .treeLabel span:contains('#{folder}')").click
end
else
ff(".treeLabel span")[3].click
end
driver.action.send_keys(:return).perform
wait_for_ajaximations
ff(".btn-primary")[1].click
end
def move_multiple_using_toolbar(files = [])
files.each do |file_name|
file = driver.find_element(xpath: "//span[contains(text(), '#{file_name}') and @class='ef-name-col__text']")
.find_element(xpath: "../..")
driver.action.key_down(:control).click(file).key_up(:control).perform
end
wait_for_ajaximations
f('.btn-move').click
wait_for_ajaximations
expect(f(".ReactModal__Header-Title h4").text).to eq "Where would you like to move these #{files.count} items?"
ff(".treeLabel span")[3].click
driver.action.send_keys(:return).perform
wait_for_ajaximations
ff(".btn-primary")[1].click
end
# This method sets permissions on files/folders
def set_item_permissions(permission_type = :publish, restricted_access_option = nil, set_permissions_from = :cloud_icon)
if set_permissions_from == :cloud_icon
f('.btn-link.published-status').click
elsif set_permissions_from == :toolbar_menu
ff('.ef-item-row')[0].click
f('.btn-restrict').click
end
wait_for_ajaximations
if permission_type == :publish
driver.find_elements(:name, 'permissions')[0].click
elsif permission_type == :unpublish
driver.find_elements(:name, 'permissions')[1].click
else
driver.find_elements(:name, 'permissions')[2].click
if restricted_access_option == :available_with_link
driver.find_elements(:name, 'restrict_options')[0].click
else
driver.find_elements(:name, 'restrict_options')[1].click
ff('.ui-datepicker-trigger.btn')[0].click
fln("15").click
ff('.ui-datepicker-trigger.btn')[1].click
fln("25").click
end
end
ff('.btn.btn-primary')[1].click
wait_for_ajaximations
end
def should_make_folders_in_the_menu_droppable
course_with_teacher_logged_in
get "/files"
wait_for_ajaximations
f(".add_folder_link").click
wait_for_ajaximations
expect(f("#files_content .add_folder_form #folder_name")).to be_displayed
f("#files_content .add_folder_form #folder_name").send_keys("my folder\n")
wait_for_ajaximations
expect(f(".node.folder span")).to have_class('ui-droppable')
# also make sure that it has a tooltip of the file name so that you can read really long names
expect(f(".node.folder .name[title='my folder']")).not_to be_nil
end
def should_show_students_link_to_download_zip_of_folder
course_with_student_logged_in
get "/courses/#{@course.id}/files"
link = f(".links a.download_zip_link")
wait_for_ajaximations
expect(link).to be_displayed
expect(link).to have_attribute('href', %r"/courses/#{@course.id}/folders/\d+/download")
end
def confirm_delete_on_dialog
driver.switch_to.alert.accept
wait_for_ajaximations
end
def cancel_delete_on_dialog
driver.switch_to.alert.dismiss
wait_for_ajaximations
end
def add_folder(name = 'new folder')
click_new_folder_button
new_folder = f("input[aria-label='Folder Name']")
new_folder.send_keys(name)
new_folder.send_keys(:return)
wait_for_ajaximations
end
def click_new_folder_button
f("button[aria-label='Add Folder']").click
wait_for_ajaximations
end
def create_new_folder
f('.btn-add-folder').click
f('.ef-edit-name-form').submit
wait_for_ajaximations
all_files_folders.first
end
def all_files_folders
# TODO: switch to ff once specs stop using this to find non-existence of stuff
driver.find_elements(:class, 'ef-item-row')
end
def insert_file_from_rce(insert_into = nil)
if insert_into == :quiz
ff(".ui-tabs-anchor")[6].click
else
file_tab = ff(".ui-tabs-anchor")[1]
expect(file_tab).to be_displayed
ff(".ui-tabs-anchor")[1].click
end
ff(".name.text")[0].click
wait_for_ajaximations
ff(".name.text")[1].click
wait_for_ajaximations
ff(".name.text")[2].click
wait_for_ajaximations
if insert_into == :quiz
ff(".name.text")[3].click
ff(".btn-primary")[3].click
elsif insert_into == :discussion
f("#edit_discussion_form_buttons .btn-primary").click
else
f(".btn-primary").click
end
wait_for_ajaximations
expect(fln("some test file")).to be_displayed
end
end