-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstep_definitions.rb
396 lines (301 loc) · 10.7 KB
/
step_definitions.rb
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
# frozen_string_literal: true
Before do
@uuid = SecureRandom.uuid
end
Given 'an administrator user is logged in' do
visit "#{STAFF_URL}/logout"
login_admin
ensure_test_repository_exists
ensure_test_user_exists
ensure_test_agent_exists
ensure_test_subject_exists
ensure_test_accession_exists
ensure_test_classification_exists
end
Given 'an archivist user is logged in' do
login_archivist
end
Given 'a Repository with name {string} has been created' do |repository_name|
visit "#{STAFF_URL}/repositories"
fill_in 'filter-text', with: repository_name
within '.search-filter' do
find('button').click
end
begin
find('tr', text: repository_name, match: :first)
rescue Capybara::ElementNotFound
visit "#{STAFF_URL}/repositories/new"
fill_in 'Repository Short Name', with: repository_name
fill_in 'Repository Name', with: repository_name
click_on 'Save'
end
end
When 'the user clicks on {string}' do |string|
click_on_string string
wait_for_ajax if current_url.include?("resources/#{@resource_id}/edit") ||
current_url.include?("digital_objects/#{@digital_object_id}/edit")
end
When 'the user hovers on {string} in the dropdown menu' do |string|
within '.dropdown-menu' do
element = find(:xpath, "//button[contains(text(), '#{string}')] | //a[contains(text(), '#{string}')]")
element.hover
end
end
When 'the user clicks on {string} in the record toolbar' do |string|
within '.record-toolbar' do
click_on_string string
end
end
When 'the user clicks on {string} in the modal' do |string|
wait_for_ajax
within '.modal-content' do
click_on_string string
end
end
When 'the user clicks on {string} in the transfer form' do |string|
dropdown_menu = find('.transfer-form')
within dropdown_menu do
click_on_string string
end
end
When 'the user clicks on {string} in the dropdown menu' do |string|
dropdown_menu = find('.dropdown-menu', match: :first)
within dropdown_menu do
elements = dropdown_menu.all(:xpath, ".//*[contains(text(), '#{string}')]")
elements.each do |element|
if (element.tag_name == 'button' || element.tag_name == 'a') && element.text == string
element.click
break
end
end
end
end
When 'the user clicks on {string} in the spawn dropdown menu' do |string|
within '#spawn-dropdown' do
click_on_string string
end
end
When 'the user clicks on the first dropdown in the {string} form' do |form_title|
section_title = find('h3', text: form_title)
section = section_title.ancestor('section')
expect(section[:id]).to_not eq nil
within section do
find('.dropdown-toggle', match: :first).click
end
end
When 'the user clicks on {string} in the {string} form' do |string, form_title|
section_title = find('h3', text: form_title)
section = section_title.ancestor('section')
expect(section[:id]).to_not eq nil
within section do
click_on string
end
end
When 'the user clicks on {string} in the dropdown menu in the {string} form' do |string, form_title|
section_title = find('h3', text: form_title)
section = section_title.ancestor('section')
expect(section[:id]).to_not eq nil
within section do
dropdown_menu = find('.dropdown-menu')
within dropdown_menu do
click_on string
end
end
end
When 'the user fills in {string}' do |label|
@uuid = SecureRandom.uuid if @uuid.nil?
fill_in label, with: @uuid, match: :first
end
When 'the user fills in {string} in the modal' do |label|
@uuid = SecureRandom.uuid if @uuid.nil?
within '.modal-content' do
fill_in label, with: @uuid, match: :first
end
end
When 'the user clears the {string} field' do |label|
fill_in label, with: '', match: :first
end
When 'the user fills in {string} with {string}' do |label, value|
fill_in label, with: value, match: :first
end
When 'the user fills in {string} with {string} in the modal' do |label, value|
within '.modal-content' do
fill_in label, with: value, match: :first
end
end
When 'the user fills in {string} with a unique identifier in the modal' do |label|
within '.modal-content' do
fill_in label, with: @uuid, match: :first
end
end
When 'the user clicks on remove icon in the {string} form' do |form_title|
section_title = find('h3', text: form_title)
section = section_title.ancestor('section')
expect(section[:id]).to_not eq nil
within section do
find('.subrecord-form-remove').click
expect(page).to have_text 'Confirm Removal'
end
end
When 'the user fills in {string} with {string} in the {string} form' do |label, value, form_title|
section_title = find('h3', text: form_title)
section = section_title.ancestor('section')
expect(section[:id]).to_not eq nil
within section do
fill_in label, with: value
end
end
When 'the user fills in {string} with {string} and selects {string} in the {string} form' do |label, value, selected_value, form_title|
section_title = find('h3', text: form_title)
section = section_title.ancestor('section')
expect(section[:id]).to_not eq nil
within section do
fill_in label, with: value
dropdown_items = all('li.dropdown-item a', text: selected_value).select do |entry|
entry.text == selected_value
end
expect(dropdown_items.length).to eq 1
expect(dropdown_items[0].text).to eq selected_value
dropdown_items[0].click
end
end
When 'the user selects {string} from {string}' do |option, label|
select option, from: label, match: :first
end
When 'the user selects {string} in the modal' do |select_option|
within '.modal-content' do
find('#label').select select_option
end
end
When 'the user selects {string} from {string} in the modal' do |option, label|
wait_for_ajax
within '.modal-content' do
select option, from: label
end
end
When 'the user selects {string} from {string} in the {string} form' do |option, label, form_title|
section_title = find('h3', text: form_title)
section = section_title.ancestor('section')
expect(section[:id]).to_not eq nil
within section do
select option, from: label
end
end
When 'the user checks {string}' do |label|
check label, match: :first
end
When 'the user unchecks {string}' do |label|
uncheck label, match: :first
end
When 'the user changes the {string} field to {string}' do |field, value|
field = find_field(field, match: :first)
if field.tag_name == 'select'
field.select value.strip
else
field.fill_in with: value
end
end
When 'the user changes the {string} field' do |field|
fill_in field, with: SecureRandom.uuid, match: :first
end
Then('the {string} created message is displayed') do |string|
wait_for_ajax if current_url.include?('resources') || current_url.include?('digital_objects')
expect(find('.alert.alert-success.with-hide-alert').text).to match(/^#{string}.*created.*$/i)
@created_record_id = extract_created_record_id(string)
end
Then('the {string} updated message is displayed') do |string|
wait_for_ajax if current_url.include?('resources') || current_url.include?('digital_objects')
expect(find('.alert.alert-success.with-hide-alert').text).to match(/^#{string}.*updated$/i)
end
Then('the {string} saved message is displayed') do |string|
wait_for_ajax if current_url.include? 'resources'
expect(find('.alert.alert-success.with-hide-alert').text).to match(/^#{string}.*saved$/i)
end
Then('the {string} deleted message is displayed') do |string|
expect(find('.alert.alert-success.with-hide-alert').text).to match(/^#{string}.*deleted$/i)
end
Then('the {string} published message is displayed') do |string|
expect(find('.alert.alert-success.with-hide-alert').text).to match(/#{string} .* subrecords and components have been published.*$/i)
end
Then('the {string} unpublished message is displayed') do |string|
expect(find('.alert.alert-success.with-hide-alert').text).to match(/#{string} .* subrecords and components have been unpublished.*$/i)
end
Then('the {string} merged message is displayed') do |string|
expect(find('.alert.alert-success.with-hide-alert').text.downcase).to eq("#{string} Merged".downcase)
end
Then 'the following message is displayed' do |messages|
messages.raw.each do |message|
expect(page).to have_text message[0]
end
end
Then('the {string} duplicated message is displayed') do |string|
expect(find('.alert.alert-success.with-hide-alert').text).to match(/^#{string}.*duplicated.*$/i)
end
Then 'only the following info message is displayed' do |messages|
expect(messages.raw.length).to eq 1
messages.raw.each do |message|
expect(page).to have_text message[0]
end
end
Then 'the following error messages are displayed' do |messages|
messages.raw.each do |message|
expect(page).to have_text message[0]
end
end
Then 'the following error message is displayed' do |messages|
expect(messages.raw.length).to eq 1
messages.raw.each do |message|
expect(page).to have_text message[0]
end
end
Then 'the {string} has value {string}' do |label, value|
expect(page).to have_field(label, with: value)
end
Then 'the {string} has a unique value' do |label|
expect(page).to have_field(label, with: @uuid, match: :first)
end
Then 'the {string} has selected value {string}' do |label, value|
expect(page).to have_select(label, selected: value)
end
Then 'the {string} is checked' do |label|
expect(page).to have_field(label, checked: true)
end
Then 'only the following error message is displayed' do |messages|
expect(messages.raw.length).to eq 1
messages.raw.each do |message|
expect(page).to have_text message[0]
end
end
Then 'the {string} section is displayed' do |section_heading|
expect(all('section > h3').map(&:text)).to include(section_heading)
end
Given 'the Pre-populate Records option is checked in Repository Preferences' do
visit "#{STAFF_URL}/repositories/new"
fill_in 'repository_repository__repo_code_', with: "repository_test_default_values_#{@uuid}"
fill_in 'repository_repository__name_', with: "Repository Test Default Values #{@uuid}"
find('#repository_repository__publish_').check
click_on 'Save'
message = find('.alert')
expect(message.text).to eq 'Repository Created'
visit STAFF_URL
click_on 'Select Repository'
within '.dropdown-menu' do
find('select').select "repository_test_default_values_#{@uuid}"
click_on 'Select Repository'
end
expect(page).to have_text "The Repository repository_test_default_values_#{@uuid} is now active"
find('#user-menu-dropdown').click
within '.dropdown-menu' do
click_on 'Repository Preferences (admin)'
end
find('#preference_defaults__default_values_').check
click_on 'Save'
end
When 'the user clears {string} in the {string} form' do |label, form_title|
section_title = find('h3', text: form_title)
section = section_title.ancestor('section')
expect(section[:id]).to_not eq nil
within section do
select '', from: label
end
end