|
| 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 |
0 commit comments