Skip to content

Commit 3508e38

Browse files
Accession Event create step definitions
1 parent 08b15d5 commit 3508e38

File tree

5 files changed

+135
-47
lines changed

5 files changed

+135
-47
lines changed

helpers/helpers.rb

+16
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ def ensure_test_repository_exists
9191
# Continue
9292
end
9393

94+
def ensure_test_agent_exists
95+
visit STAFF_URL
96+
97+
fill_in 'global-search-box', with: 'test_agent'
98+
find('#global-search-button').click
99+
100+
begin
101+
find 'tr', text: 'test_agent'
102+
rescue Capybara::ElementNotFound
103+
visit "#{STAFF_URL}/agents/agent_person/new"
104+
check 'Publish'
105+
fill_in 'Primary Part of Name', with: 'test_agent'
106+
click_on 'Save'
107+
end
108+
end
109+
94110
def find_user_table_row_in_manage_user_access_page(username)
95111
loop do
96112
begin

staff_features/accessions/accession_add_events.feature

-47
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Feature: Accession Event Create
2+
Background:
3+
Given an administrator user is logged in
4+
And an Accession has been created
5+
And the Accession is opened in edit mode
6+
Scenario: Accession Event create page
7+
When the user clicks on 'Add Event'
8+
And the user clicks on 'Add Event' in the dropdown menu
9+
Then the New Event page is displayed with the Accession linked
10+
Scenario: Accession Event is created
11+
Given the New Event page is open for an Accession
12+
When the user selects 'Single' from 'Type' in the 'Event Date/Time' form
13+
And the user fills in 'Begin' with '2020-01-01' in the 'Event Date/Time' form
14+
And the user links an Agent
15+
And the user clicks on 'Save'
16+
Then the 'Event Created' message is displayed
17+
Scenario: Accession Event is not created due to missing required fields
18+
Given the New Event page is open for an Accession
19+
When the user selects 'Single' from 'Type' in the 'Event Date/Time' form
20+
And the user clicks on 'Save'
21+
Then the following error messages are displayed
22+
| Expression - is required unless a begin or end date is given |
23+
| Begin - is required unless an expression or an end date is given |
24+
| Agents - Property is required but was missing |
25+
| Role - Property is required but was missing |
26+
Scenario: Accession Event is not created due to missing required fields, with Event Date/Time Expression filled in
27+
Given the New Event page is open for an Accession
28+
When the user selects 'Single' from 'Type' in the 'Event Date/Time' form
29+
And the user fills in 'Expression' with 'Date Expression' in the 'Event Date/Time' form
30+
And the user clicks on 'Save'
31+
Then the following error messages are displayed
32+
| Agents - Property is required but was missing |
33+
| Role - Property is required but was missing |
34+
Scenario: Accession Event is not created due to invalid date
35+
Given the New Event page is open for an Accession
36+
When the user selects 'Single' from 'Type' in the 'Event Date/Time' form
37+
And the user fills in 'Begin' with '2020-22-22' in the 'Event Date/Time' form
38+
And the user links an Agent
39+
And the user clicks on 'Save'
40+
Then the following error message is displayed
41+
| Begin - Not a valid date |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
Given 'the Accession is opened in edit mode' do
4+
visit "#{STAFF_URL}/accessions"
5+
6+
fill_in 'filter-text', with: @uuid
7+
8+
within '.search-filter' do
9+
find('button').click
10+
end
11+
12+
search_result_rows = all('#tabledSearchResults tbody tr')
13+
expect(search_result_rows.length).to eq 1
14+
15+
within search_result_rows[0] do
16+
element = find('a', text: 'Edit')
17+
18+
@accession_id = URI.decode_www_form_component(element[:href]).split('/').pop
19+
end
20+
21+
click_on 'Edit'
22+
end
23+
24+
Given 'the New Event page is open for an Accession' do
25+
click_on 'Add Event'
26+
27+
within '#form_add_event' do
28+
click_on 'Add Event'
29+
end
30+
end
31+
32+
When 'the user links an Agent' do
33+
select 'Authorizer', from: 'event_linked_agents__0__role_'
34+
fill_in 'token-input-event_linked_agents__0__ref_', with: 'test_agent'
35+
dropdown_items = all('li.token-input-dropdown-item2')
36+
dropdown_items.first.click
37+
end
38+
39+
Then 'the New Event page is displayed with the Accession linked' do
40+
expect(find('h2').text).to eq 'New Event Event'
41+
expect(find('#event_linked_records__0__ref__combobox')).to have_text @uuid
42+
end

staff_features/shared/step_definitions.rb

+36
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
login_admin
99

1010
ensure_test_repository_exists
11+
ensure_test_agent_exists
1112
end
1213

1314
Given 'an archivist user is logged in' do
@@ -18,6 +19,13 @@
1819
click_on_string string
1920
end
2021

22+
When 'the user clicks on {string} in the dropdown menu' do |string|
23+
within '.dropdown-menu' do
24+
elements = all(:xpath, "//*[contains(text(), '#{string}')]")
25+
elements[1].click
26+
end
27+
end
28+
2129
When 'the user clicks on {string} in the confirm popup' do |string|
2230
within '#confirmChangesModal' do
2331
click_on_string string
@@ -34,10 +42,30 @@
3442
fill_in label, with: value
3543
end
3644

45+
When 'the user fills in {string} with {string} in the {string} form' do |label, value, form_title|
46+
section_title = find('h3', text: form_title)
47+
section = section_title.ancestor('section')
48+
expect(section[:id]).to_not eq nil
49+
50+
within section do
51+
fill_in label, with: value
52+
end
53+
end
54+
3755
When 'the user selects {string} from {string}' do |option, label|
3856
select option, from: label
3957
end
4058

59+
When 'the user selects {string} from {string} in the {string} form' do |option, label, form_title|
60+
section_title = find('h3', text: form_title)
61+
section = section_title.ancestor('section')
62+
expect(section[:id]).to_not eq nil
63+
64+
within section do
65+
select option, from: label
66+
end
67+
end
68+
4169
When 'the user checks {string}' do |label|
4270
check label
4371
end
@@ -71,3 +99,11 @@
7199
Then 'the {string} is checked' do |label|
72100
expect(page).to have_field(label, checked: true)
73101
end
102+
103+
Then 'the following error message is displayed' do |messages|
104+
expect(messages.raw.length).to eq 1
105+
106+
messages.raw.each do |message|
107+
expect(page).to have_text message[0]
108+
end
109+
end

0 commit comments

Comments
 (0)