Skip to content

Commit 40a31e7

Browse files
Accession edit step definitions
Accession edit step definitions
1 parent a5b844c commit 40a31e7

9 files changed

+261
-41
lines changed

.rubocop.yml

+6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ Metrics/AbcSize:
99
Metrics/MethodLength:
1010
Max: 50
1111

12+
Layout/LineLength:
13+
Max: 180
14+
1215
Layout/ElseAlignment:
1316
Enabled: false
1417

1518
Style/ConditionalAssignment:
1619
Enabled: false
20+
21+
Style/NumericPredicate:
22+
Enabled: false

env.rb

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
Capybara::Selenium::Driver.new(app, browser: :firefox, options:)
3030
end
3131

32+
Capybara.register_driver :firefox_alternative_session do |app|
33+
options = Selenium::WebDriver::Firefox::Options.new
34+
options.add_argument(HEADLESS)
35+
36+
Capybara::Selenium::Driver.new(app, browser: :firefox, options:)
37+
end
38+
3239
Capybara.default_driver = :firefox
3340
Capybara.default_max_wait_time = 10
3441

helpers/helpers.rb

+29-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ def login_archivist
6767
end
6868
end
6969

70+
# Ensure the system has at least one repository
7071
def ensure_test_repository_exists
71-
# Ensure the system has at least one repository
72-
7372
element = find('.alert.alert-info.with-hide-alert')
7473

7574
if element.text == 'To create your first Repository, click the System menu above and then Manage Repositories.'
@@ -91,6 +90,23 @@ def ensure_test_repository_exists
9190
# Continue
9291
end
9392

93+
def ensure_test_user_exists
94+
visit "#{STAFF_URL}/users/new"
95+
96+
fill_in 'user_username_', with: 'test'
97+
fill_in 'user_name_', with: 'test'
98+
fill_in 'user_password_', with: 'test'
99+
fill_in 'user_confirm_password_', with: 'test'
100+
check 'user_is_admin_'
101+
102+
click_on 'Create Account', match: :first
103+
104+
raise 'Could not create test user' if page.has_text?('User not created') &&
105+
!page.has_text?("Username - Username 'test' is already in use")
106+
107+
visit STAFF_URL
108+
end
109+
94110
def find_user_table_row_in_manage_user_access_page(username)
95111
loop do
96112
begin
@@ -134,6 +150,17 @@ def create_resource(uuid)
134150
expect(page).to have_text "Resource Resource #{uuid} created"
135151
end
136152

153+
def create_accession(uuid)
154+
visit "#{STAFF_URL}/accessions/new"
155+
156+
fill_in 'accession_id_0_', with: "Accession #{@uuid}"
157+
fill_in 'Title', with: "Accession Title #{@uuid}"
158+
fill_in 'Accession Date', with: '2000-01-01'
159+
160+
click_on 'Save'
161+
expect(page).to have_text "Accession Accession Title #{uuid} created"
162+
end
163+
137164
def expect_record_to_be_in_search_results(search_term)
138165
fill_in 'global-search-box', with: search_term
139166
find('#global-search-button').click

staff_features/accessions/accession_delete.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Feature: Accession Delete
1616
When the user clicks on 'Delete'
1717
And the user clicks on 'Delete' in the confirm popup
1818
Then the Accessions page is displayed
19-
And the 'Accession deleted' message is displayed
19+
And the 'Accession' deleted message is displayed
2020
And the Accession is deleted
2121
Scenario: Cancel Accession delete from the view page
2222
Given the user is on the Accession view page

staff_features/accessions/accession_edit.feature

+22-33
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,44 @@ Feature: Accession Edit
1414
And all fields become editable
1515
Scenario Outline: Accession is successfully updated
1616
Given the Accession is opened in edit mode
17-
When the user changes the <Field> field to <NewValue>
18-
And the user saves the changes
19-
Then the Accession is updated with the new <Field> as <NewValue>
20-
And the 'Accession updated' message is displayed
21-
And the updated value appears in the accession details
17+
When the user changes the '<Field>' field to '<NewValue>'
18+
And the user clicks on 'Save'
19+
Then the 'Accession' updated message is displayed
20+
Then the field '<Field>' has value '<NewValue>'
2221
Examples:
2322
| Field | NewValue |
2423
| Title | Updated Test Accession |
25-
| Date | 2024-10-03 |
24+
| Accession Date | 2024-10-03 |
2625
Scenario: Accession is not updated after changes are reverted
2726
Given the Accession is opened in edit mode
2827
When the user changes the 'Title' field
29-
And the user clicks on 'Revert changes'
30-
Then the Accession is not updated
31-
And the 'Title' field still shows the original title
28+
And the user clicks on 'Revert Changes'
29+
Then the 'Title' field has the original value
3230
Scenario: Accession update fails due to invalid date input
3331
Given the Accession is opened in edit mode
34-
When the user changes the 'Date' field to '2024-13-15'
35-
And the user saves the changes
36-
Then the following error message is displayed
32+
When the user fills in 'Date' with '2024-13-15'
33+
And the user clicks on 'Save'
34+
Then the following error messages are displayed
3735
| Accession Date - Not a valid date |
38-
And the Accession is not updated
39-
And the 'Date' field still shows the original date
36+
And the Accession Date field has the original value
4037
Scenario: Accession update succeeds for User A with a warning for other user editing it
4138
Given the Accession is opened in edit mode by User A
42-
And the Accession is also opened in edit mode by User B
39+
And the Accession is opened in edit mode by User B
4340
When User A changes the 'Title' field
44-
And User A saves the changes
45-
Then the 'Accession updated' message is displayed
46-
And User A sees the following conflict message
47-
| This record is currently being edited by another user. Please contact the following users to ensure no conflicts occur: B |
41+
Then User B sees a conflict message which indicates that User A is editing this record
4842
Scenario: Accession update fails due to concurrent edit by another user
4943
Given the Accession is opened in edit mode by User A
50-
And the Accession is also opened in edit mode by User B
51-
When User A changes the 'Title' field and saves the changes
52-
And User B changes the 'Title' field and saves the changes
44+
And the Accession is opened in edit mode by User B
45+
When User A changes the 'Title' field
46+
And User A clicks on 'Save'
47+
And User B changes the 'Title' field
48+
And User B clicks on 'Save'
5349
Then User B sees the following conflict message
5450
| Failed to save your changes - This record has been updated by another user. Please refresh the page to access the latest version.|
5551
Scenario: Accession update fails due to missing required field
5652
Given the Accession is opened in edit mode
57-
When the user clears the 'Identifier' field
58-
And the user saves the changes
59-
Then the following error message is displayed
53+
When the user fills in 'Identifier' with ''
54+
And the user clicks on 'Save'
55+
Then the following error messages are displayed
6056
| Identifier - Property is required but was missing |
61-
And the Accession is not updated
62-
Scenario: User is warned about unsaved changes when navigating away
63-
Given the Accession is opened in edit mode
64-
When the user changes the 'Title' field
65-
And the user attempts to navigate away without saving
66-
Then a confirmation dialog is displayed asking if the user wants to leave the site with unsaved changes
67-
When the user chooses to leave the page
68-
Then the Accession is not updated
57+
And the Identifier field has the original value

staff_features/accessions/step_definitions/accession_delete.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
end
6565

6666
Then 'the user is still on the Accession view page' do
67-
expect(find('h2').text).to eq "Accession #{@uuid} Accession"
67+
expect(find('h2').text).to eq "Accession Title #{@uuid} Accession"
6868
end
6969

7070
Then 'the Accessions page is displayed' do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# frozen_string_literal: true
2+
3+
Given 'the Accession appears in the search results list' 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+
end
21+
22+
Given 'the Accession is opened in the view mode' do
23+
visit "#{STAFF_URL}/accessions"
24+
25+
fill_in 'filter-text', with: @uuid
26+
27+
within '.search-filter' do
28+
find('button').click
29+
end
30+
31+
search_result_rows = all('#tabledSearchResults tbody tr')
32+
expect(search_result_rows.length).to eq 1
33+
34+
within search_result_rows[0] do
35+
element = find('a', text: 'View')
36+
37+
@accession_id = URI.decode_www_form_component(element[:href]).split('/').pop
38+
end
39+
40+
click_on 'View'
41+
end
42+
43+
Given 'the Accession is opened in edit mode' do
44+
visit "#{STAFF_URL}/accessions"
45+
46+
fill_in 'filter-text', with: @uuid
47+
48+
within '.search-filter' do
49+
find('button').click
50+
end
51+
52+
search_result_rows = all('#tabledSearchResults tbody tr')
53+
expect(search_result_rows.length).to eq 1
54+
55+
within search_result_rows[0] do
56+
element = find('a', text: 'Edit')
57+
58+
@accession_id = URI.decode_www_form_component(element[:href]).split('/').pop
59+
end
60+
61+
click_on 'Edit'
62+
end
63+
64+
When 'the user changes the {string} field to {string}' do |field, value|
65+
fill_in field, with: value
66+
end
67+
68+
When 'the user changes the {string} field' do |field|
69+
fill_in field, with: "Updated Title #{SecureRandom.uuid}"
70+
end
71+
72+
Then 'the {string} field has the original value' do |field|
73+
expect(page).to have_field(field, with: "Accession Title #{@uuid}")
74+
end
75+
76+
Then 'the Accession is updated with the new {string} as {string}' do |field, value|
77+
fill_in field, with: value
78+
end
79+
80+
Then 'the Accession is opened in the edit mode' do
81+
uri = current_url.split('/')
82+
uri.pop
83+
accession_id = uri.pop
84+
85+
expect(accession_id).to eq @accession_id
86+
end
87+
88+
Then 'all fields become editable' do
89+
fill_in 'Identifier', with: 'Identifier'
90+
end
91+
92+
Then 'the field {string} has value {string}' do |field, value|
93+
expect(page).to have_field(field, with: value)
94+
end
95+
96+
Then 'the Accession Date field has the original value' do
97+
visit "#{STAFF_URL}/accessions/#{@accession_id}/edit"
98+
99+
expect(page).to have_field('Accession Date', with: '2000-01-01')
100+
end
101+
102+
When 'the Identifier field has the original value' do
103+
visit "#{STAFF_URL}/accessions/#{@accession_id}/edit"
104+
105+
expect(page).to have_field('Identifier', with: "Accession #{@uuid}")
106+
end
107+
108+
Given 'the Accession is opened in edit mode by User A' do
109+
visit "#{STAFF_URL}/accessions"
110+
111+
fill_in 'filter-text', with: @uuid
112+
113+
within '.search-filter' do
114+
find('button').click
115+
end
116+
117+
search_result_rows = all('#tabledSearchResults tbody tr')
118+
expect(search_result_rows.length).to eq 1
119+
120+
within search_result_rows[0] do
121+
element = find('a', text: 'Edit')
122+
123+
@accession_id = URI.decode_www_form_component(element[:href]).split('/').pop
124+
end
125+
126+
click_on 'Edit'
127+
end
128+
129+
Given 'the Accession is opened in edit mode by User B' do
130+
@session = Capybara::Session.new(:firefox_alternative_session)
131+
132+
@session.visit(STAFF_URL)
133+
134+
@session.fill_in 'username', with: 'test'
135+
@session.fill_in 'password', with: 'test'
136+
@session.click_on 'Sign In'
137+
expect(@session).to have_text 'Welcome to ArchivesSpace'
138+
139+
@session.click_on 'Browse'
140+
@session.click_on 'Accessions'
141+
142+
@session.fill_in 'filter-text', with: @uuid
143+
144+
@session.find('.search-filter button').click
145+
146+
@session.click_on 'Edit'
147+
end
148+
149+
When 'User A clicks on {string}' do |string|
150+
click_on string
151+
end
152+
153+
When 'User A changes the {string} field' do |field|
154+
fill_in field, with: "Accession Title #{@uuid} updated"
155+
end
156+
157+
When 'User B changes the {string} field' do |field|
158+
@session.fill_in field, with: "Accession Title #{@uuid} updated"
159+
end
160+
161+
When 'User B clicks on {string}' do |string|
162+
@session.click_on string
163+
end
164+
165+
Then 'User B sees a conflict message which indicates that User A is editing this record' do
166+
tries = 6
167+
element = nil
168+
169+
loop do
170+
break if tries == 0
171+
172+
begin
173+
tries -= 1
174+
175+
element = @session.find('#form_messages .alert.alert-warning.update-monitor-error')
176+
expect(element.text).to eq 'This record is currently being edited by another user. Please contact the following users to ensure no conflicts occur: admin'
177+
break
178+
rescue Capybara::ElementNotFound
179+
sleep 3
180+
end
181+
end
182+
end
183+
184+
Then 'User B sees the following conflict message' do |messages|
185+
messages.raw.each do |message|
186+
expect(@session).to have_text message[0]
187+
end
188+
end

staff_features/accessions/step_definitions/accessions_search.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
# frozen_string_literal: true
22

33
Given 'an Accession has been created' do
4-
visit "#{STAFF_URL}/accessions/new"
5-
fill_in 'accession_id_0_', with: "Accession #{@uuid}"
6-
click_on 'Save'
4+
create_accession(@uuid)
75
end
86

97
Then 'the Accession is in the search results' do
108
expect(page).to have_css('tr', text: @uuid)
119
end
1210

1311
Then 'the Accession view page is displayed' do
14-
expect(find('h2').text).to eq "Accession #{@uuid} Accession"
12+
expect(find('h2').text).to eq "Accession Title #{@uuid} Accession"
1513
end
1614

1715
Given 'two Accessions have been created with a common keyword in their title' do

0 commit comments

Comments
 (0)