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
|
# frozen_string_literal: true
module QA
module Page
module Project
module WebIDE
class Edit < Page::Base
prepend Page::Component::WebIDE::Alert
include Page::Component::DropdownFilter
view 'app/assets/javascripts/ide/components/activity_bar.vue' do
element :commit_mode_tab
element :edit_mode_tab
end
view 'app/assets/javascripts/ide/components/ide_status_bar.vue' do
element :commit_sha_content
end
view 'app/assets/javascripts/ide/components/ide_tree.vue' do
element :new_file_button
element :new_directory_button
end
view 'app/assets/javascripts/ide/components/ide_tree_list.vue' do
element :file_list
end
view 'app/assets/javascripts/ide/components/file_templates/bar.vue' do
element :file_templates_bar
element :file_template_dropdown
end
view 'app/assets/javascripts/ide/components/file_templates/dropdown.vue' do
element :dropdown_filter_input
end
view 'app/assets/javascripts/ide/components/commit_sidebar/actions.vue' do
element :commit_to_current_branch_radio
end
view 'app/assets/javascripts/ide/components/commit_sidebar/form.vue' do
element :begin_commit_button
element :commit_button
end
view 'app/assets/javascripts/ide/components/commit_sidebar/new_merge_request_option.vue' do
element :start_new_mr_checkbox
end
view 'app/assets/javascripts/ide/components/repo_editor.vue' do
element :editor_container
end
view 'app/assets/javascripts/ide/components/ide.vue' do
element :first_file_button
end
view 'app/assets/javascripts/vue_shared/components/file_row.vue' do
element :file_name_content
element :file_row_container
end
view 'app/assets/javascripts/ide/components/new_dropdown/index.vue' do
element :dropdown_button
element :rename_move_button
element :delete_button
end
view 'app/views/shared/_confirm_fork_modal.html.haml' do
element :fork_project_button
element :confirm_fork_modal
end
view 'app/assets/javascripts/ide/components/ide_project_header.vue' do
element :project_path_content
end
view 'app/assets/javascripts/ide/components/commit_sidebar/message_field.vue' do
element :ide_commit_message_field
end
view 'app/assets/javascripts/vue_shared/components/changed_file_icon.vue' do
element :changed_file_icon_content
end
view 'app/assets/javascripts/vue_shared/components/file_icon.vue' do
element :folder_icon_content
end
view 'app/assets/javascripts/vue_shared/components/content_viewer/content_viewer.vue' do
element :preview_container
end
view 'app/assets/javascripts/vue_shared/components/content_viewer/viewers/download_viewer.vue' do
element :download_button
end
view 'app/assets/javascripts/vue_shared/components/content_viewer/viewers/image_viewer.vue' do
element :image_viewer_container
end
view 'app/assets/javascripts/ide/components/new_dropdown/upload.vue' do
element :file_upload_field
end
view 'app/assets/javascripts/ide/components/commit_sidebar/list_item.vue' do
element :file_to_commit_content
end
def has_file?(file_name)
within_element(:file_list) do
has_element?(:file_name_content, file_name: file_name)
end
end
def has_file_to_commit?(file_name)
has_element?(:file_to_commit_content, file_name: file_name)
end
def has_project_path?(project_path)
has_element?(:project_path_content, project_path: project_path)
end
def has_file_addition_icon?(file_name)
within_element(:file_row_container, file_name: file_name) do
has_element?(:changed_file_icon_content, title: 'Added')
end
end
def has_folder_icon?(file_name)
within_element(:file_row_container, file_name: file_name) do
has_element?(:folder_icon_content)
end
end
def has_download_button?(file_name)
click_element(:file_row_container, file_name: file_name)
within_element(:preview_container) do
has_element?(:download_button)
end
end
def has_image_viewer?(file_name)
click_element(:file_row_container, file_name: file_name)
within_element(:preview_container) do
has_element?(:image_viewer_container)
end
end
def has_file_content?(file_name, file_content)
click_element(:file_row_container, file_name: file_name)
within_element(:editor_container) do
has_text?(file_content)
end
end
def go_to_project
click_element(:project_path_content, Page::Project::Show)
end
def create_new_file_from_template(file_name, template)
click_element(:new_file_button, Page::Component::WebIDE::Modal::CreateNewFile)
within_element(:template_list) do
click_on file_name
rescue Capybara::ElementNotFound
raise ElementNotFound, %Q(Couldn't find file template named "#{file_name}". Please confirm that it is a valid option.)
end
# Wait for the modal to fade out too
has_no_element?(:new_file_modal)
wait_until(reload: false) do
within_element(:file_templates_bar) do
click_element :file_template_dropdown
fill_element :dropdown_filter_input, template
begin
click_on template
rescue Capybara::ElementNotFound
raise ElementNotFound, %Q(Couldn't find template "#{template}" for #{file_name}. Please confirm that it exists in the list of templates.)
end
end
end
end
def commit_sha
return unless has_element?(:commit_sha_content, wait: 0)
find_element(:commit_sha_content).text
end
def commit_changes(commit_message = nil, open_merge_request: false)
# Clicking :begin_commit_button switches from the
# edit to the commit view
click_element(:begin_commit_button)
active_element?(:commit_mode_tab)
original_commit = commit_sha
# After clicking :begin_commit_button, there is an animation
# that hides :begin_commit_button and shows :commit_button
#
# Wait for the animation to complete before clicking :commit_button
# otherwise the click will quietly do nothing.
wait_until(reload: false) do
has_no_element?(:begin_commit_button) &&
has_element?(:commit_button)
end
if commit_message
fill_element(:ide_commit_message_field, commit_message)
end
if open_merge_request
click_element(:commit_button, Page::MergeRequest::New)
else
# Click :commit_button and keep retrying just in case part of the
# animation is still in process even when the buttons have the
# expected visibility.
commit_success = retry_until(sleep_interval: 5) do
click_element(:commit_to_current_branch_radio) if has_element?(:commit_to_current_branch_radio)
click_element(:commit_button) if has_element?(:commit_button)
# If this is the first commit, the commit SHA only appears after reloading
wait_until(reload: true) do
active_element?(:edit_mode_tab) && commit_sha != original_commit
end
end
raise "The changes do not appear to have been committed successfully." unless commit_success
end
end
def add_to_modified_content(content)
finished_loading?
modified_text_area.click
modified_text_area.set content
end
def modified_text_area
wait_for_animated_element(:editor_container)
within_element(:editor_container) do
find('.modified textarea.inputarea')
end
end
def create_first_file(file_name)
click_element(:first_file_button, Page::Component::WebIDE::Modal::CreateNewFile)
fill_element(:file_name_field, file_name)
click_button('Create file')
end
def add_file(file_name, file_text)
click_element(:new_file_button, Page::Component::WebIDE::Modal::CreateNewFile)
fill_element(:file_name_field, file_name)
click_button('Create file')
wait_until(reload: false) { has_file?(file_name) }
within_element(:editor_container) do
find('textarea.inputarea').click.set(file_text)
end
end
def add_directory(directory_name)
click_element(:new_directory_button, Page::Component::WebIDE::Modal::CreateNewFile)
fill_element(:file_name_field, directory_name)
click_button('Create directory')
wait_until(reload: false) { has_file?(directory_name) }
end
def rename_file(file_name, new_file_name)
click_element(:file_name_content, file_name: file_name)
click_element(:dropdown_button)
click_element(:rename_move_button, Page::Component::WebIDE::Modal::CreateNewFile)
fill_element(:file_name_field, new_file_name)
click_button('Rename file')
end
def fork_project!
wait_until(reload: false) do
has_element?(:confirm_fork_modal)
end
click_element(:fork_project_button)
# wait for the fork to be created
wait_until(reload: true) do
has_element?(:file_list)
end
end
def upload_file(file_path)
within_element(:file_list) do
find_element(:file_upload_field, visible: false).send_keys(file_path)
end
end
def delete_file(file_name)
click_element(:file_name_content, file_name: file_name)
click_element(:dropdown_button)
click_element(:delete_button)
end
def switch_to_commit_tab
click_element(:commit_mode_tab)
end
end
end
end
end
end
QA::Page::Project::WebIDE::Edit.prepend_if_ee('QA::EE::Page::Component::WebIDE::WebTerminalPanel')
|