From 361b1c3a574dbcd4868625ecee1102e085c6d68c Mon Sep 17 00:00:00 2001 From: blacksmith-welder Date: Mon, 24 Feb 2025 16:47:04 +0200 Subject: [PATCH] Top containers bulk operations --- helpers/helpers.rb | 25 ++ staff_features/shared/step_definitions.rb | 25 +- .../top_containers_bulk_operations.rb | 307 ++++++++++++++++++ .../top_containers_bulk_operations.feature | 131 ++++---- 4 files changed, 412 insertions(+), 76 deletions(-) create mode 100644 staff_features/top_containers/step_definitions/top_containers_bulk_operations.rb diff --git a/helpers/helpers.rb b/helpers/helpers.rb index a9429b01..fa657bd6 100644 --- a/helpers/helpers.rb +++ b/helpers/helpers.rb @@ -171,6 +171,23 @@ def ensure_test_accession_exists end def ensure_test_classification_exists + visit "#{STAFF_URL}/container_profiles/new" + + fill_in 'Name', with: 'test_container_profile' + fill_in 'Depth', with: '1.1' + fill_in 'Height', with: '1.2' + fill_in 'Width', with: '1.3' + + click_on 'Save' + + message = find('.alert').text + error_message = message == 'Name - Container Profile name must be unique' + success_message = message == 'Container Profile Created' + + expect(success_message || error_message).to eq true +end + +def ensure_test_container_profile_exists visit STAFF_URL fill_in 'global-search-box', with: 'test_classification' @@ -186,6 +203,14 @@ def ensure_test_classification_exists end end +def ensure_test_location_exists + visit "#{STAFF_URL}/locations/new" + fill_in 'Building', with: 'test_location' + fill_in 'Barcode', with: 'test_location' + fill_in 'Classification', with: 'test_location' + click_on 'Save', match: :first +end + def find_user_table_row_in_manage_user_access_page(username) loop do begin diff --git a/staff_features/shared/step_definitions.rb b/staff_features/shared/step_definitions.rb index 59820b79..169c759e 100644 --- a/staff_features/shared/step_definitions.rb +++ b/staff_features/shared/step_definitions.rb @@ -15,6 +15,7 @@ ensure_test_subject_exists ensure_test_accession_exists ensure_test_classification_exists + ensure_test_container_profile_exists end Given 'an archivist user is logged in' do @@ -86,7 +87,7 @@ elements = dropdown_menu.all(:xpath, ".//*[contains(text(), '#{string}')]") elements.each do |element| - if (element.tag_name == 'button' || element.tag_name == 'a') && element.text == string + if (element.tag_name == 'button' || element.tag_name == 'a' || element.tag_name == 'span') && element.text == string element.click break end @@ -276,9 +277,11 @@ end Then('the {string} updated message is displayed') do |string| - wait_for_ajax if current_url.include?('resources') || current_url.include?('digital_objects') + wait_for_ajax if current_url.include?('resources') || + current_url.include?('digital_objects') || + current_url.include?('top_containers') - expect(find('.alert.alert-success.with-hide-alert').text).to match(/^#{string}.*updated$/i) + expect(find('.alert.alert-success', match: :first).text).to match(/^#{string}.*updated$/i) end Then('the {string} saved message is displayed') do |string| @@ -427,3 +430,19 @@ find('.btn.btn-default.navbar-btn.dropdown-toggle').click end end + +Then 'the {string} button is enabled' do |text| + buttons = all('button', text: text) + + buttons.each do |button| + expect(button.disabled?).to eq false + end +end + +Then 'the {string} button is disabled' do |text| + buttons = all('button', text: text) + + buttons.each do |button| + expect(button.disabled?).to eq true + end +end diff --git a/staff_features/top_containers/step_definitions/top_containers_bulk_operations.rb b/staff_features/top_containers/step_definitions/top_containers_bulk_operations.rb new file mode 100644 index 00000000..f44a9286 --- /dev/null +++ b/staff_features/top_containers/step_definitions/top_containers_bulk_operations.rb @@ -0,0 +1,307 @@ +# frozen_string_literal: true + +Given 'a Resource with two Top Containers has been created' do + visit "#{STAFF_URL}/resources/new" + + fill_in 'resource_title_', with: "Resource #{@uuid}" + fill_in 'resource_id_0_', with: "Resource #{@uuid}" + select 'Class', from: 'resource_level_' + element = find('#resource_lang_materials__0__language_and_script__language_') + element.send_keys('AU') + element.send_keys(:tab) + + select 'Single', from: 'resource_dates__0__date_type_' + fill_in 'resource_dates__0__begin_', with: '2024' + + fill_in 'resource_extents__0__number_', with: '10' + select 'Cassettes', from: 'resource_extents__0__extent_type_' + + element = find('#resource_finding_aid_language_') + element.send_keys('ENG') + element.send_keys(:tab) + + element = find('#resource_finding_aid_script_') + element.send_keys('Latin') + element.send_keys(:tab) + + click_on 'Add Container Instance' + select 'Accession', from: 'resource_instances__0__instance_type_' + find('#resource_instances__0__sub_container__top_container__ref__combobox .btn.btn-default.dropdown-toggle').click + within '#resource_instances__0__sub_container__top_container__ref__combobox' do + click_on 'Create' + end + fill_in 'Indicator', with: "Indicator A #{@uuid}" + + click_on 'Add Location' + fill_in 'token-input-top_container_container_locations__0__ref_', with: 'test_location' + dropdown_items = all('li.token-input-dropdown-item2') + dropdown_items.first.click + + click_on 'Create and Link' + + sleep 3 + + click_on 'Add Container Instance' + select 'Accession', from: 'resource_instances__1__instance_type_' + find('#resource_instances__1__sub_container__top_container__ref__combobox .btn.btn-default.dropdown-toggle').click + within '#resource_instances__1__sub_container__top_container__ref__combobox' do + click_on 'Create' + end + + fill_in 'Indicator', with: "Indicator B #{@uuid}" + click_on 'Add Location' + fill_in 'token-input-top_container_container_locations__0__ref_', with: 'test_location' + dropdown_items = all('li.token-input-dropdown-item2') + dropdown_items.first.click + click_on 'Create and Link' + + find('button', text: 'Save Resource', match: :first).click + + wait_for_ajax + expect(page).to have_text "Resource Resource #{@uuid} created" + + url_parts = current_url.split('/') + url_parts.pop + @resource_id = url_parts.pop + + top_containers = all('.top_container') + data_content = top_containers[0][:'data-content'] + split = data_content.split('/') + split.pop + text_containing_id = split.pop + @top_container_first_id = text_containing_id.scan(/\d+/).first + + data_content = top_containers[1][:'data-content'] + split = data_content.split('/') + split.pop + text_containing_id = split.pop + @top_container_second_id = text_containing_id.scan(/\d+/).first +end + +Given 'the user is on the Top Containers page' do + visit "#{STAFF_URL}/top_containers" +end + +When 'the user fills in {string} with the Resource title' do |label| + fill_in label, with: @uuid +end + +When 'the user checks the checkbox in the header row' do + within '#bulk_operation_results' do + find('#select_all').click + end +end + +Then 'all the Top Containers are selected' do + checkboxes = all('#bulk_operation_results tbody tr input') + + checkboxes.each do |checkbox| + expect(checkbox.checked?).to eq true + end +end + +Given 'all Top Containers are selected' do + find('#select_all').click +end + +Then 'all the Top Containers are not selected' do + checkboxes = all('#bulk_operation_results tbody tr input') + + checkboxes.each do |checkbox| + expect(checkbox.checked?).to eq false + end +end + +Given 'the Top Container A is selected' do + checkboxes = all('#bulk_operation_results tbody tr input') + + checkboxes[0].check +end + +Given 'the the two Top Containers are displayed in the search results' do + fill_in 'Keyword', with: @uuid + + click_on 'Search' +end + +When 'the user fills in and selects Container Profile in the modal' do + fill_in 'token-input-container_profile', with: 'test_container_profile' +end + +When 'the user selects Location in the modal' do + rows = all('#tabledSearchResults tbody tr') + + rows.first.click +end + +When 'the user clicks on the dropdown in the Bulk Update form' do + find('#bulk_update_form .btn.btn-default.dropdown-toggle').click +end + +When 'the user selects Container Profile in the modal' do + rows = all('#tabledSearchResults input') + + rows[0].click +end + +When 'the user clicks on {string} in the Browse Container Profiles modal' do |string| + wait_for_ajax + + within '#container_profile_modal' do + click_on_string string + end +end + +Then 'the Top Container A profile is linked to the Container Profile' do + visit "#{STAFF_URL}/top_containers/#{@top_container_first_id}/edit" + + element = find('.container_profile') + expect(element.text).to include 'test_container_profile' +end + +When 'the user fills in {string} with {string} in the Create Container Profiles modal' do |label, value| + within '#container_profile_modal' do + fill_in label, with: value, match: :first + end +end + +When 'the user fills in {string} in the Create Container Profiles modal' do |label| + within '#container_profile_modal' do + fill_in label, with: @uuid, match: :first + end +end + +Then 'the Top Container A profile is linked to the created Container Profile' do + visit "#{STAFF_URL}/top_containers/#{@top_container_first_id}/edit" + + element = find('.container_profile') + expect(element.text).to include @uuid +end + +When 'the user clicks on {string} in the Browse Locations modal' do |string| + wait_for_ajax + + within '#location_modal' do + click_on_string string + end +end + +Then 'the Top Container profile is linked to the Location' do + visit "#{STAFF_URL}/top_containers/#{@top_container_first_id}/edit" + + element = find('.location') + expect(element.text).to include 'test_location' +end + +When 'the user fills in {string} with {string} in the Create Location modal' do |label, value| + within '#location_modal' do + fill_in label, with: value, match: :first + end +end + +When 'the user clicks on {string} in the Create Location modal' do |string| + wait_for_ajax + + within '#location_modal' do + click_on_string string + end +end + +Then 'the Top Container profile is linked to the created Location' do + visit "#{STAFF_URL}/top_containers/#{@top_container_first_id}/edit" + + element = find('.location') + expect(element.text).to include 'Test Building' +end + +Given 'the two Top Containers are selected' do + rows = all('#bulk_operation_results tbody tr') + + rows.each do |row| + row.all('td')[1].click + end + + tries = 0 + + loop do + buttons = all('button', text: 'Bulk Operations') + expect(buttons[0].disabled?).to eq false + expect(buttons[1].disabled?).to eq false + + break + rescue RSpec::Expectations::ExpectationNotMetError => e + sleep 1 + tries += 1 + + raise e if tries == 3 + end +end + +Then 'the Locations are removed from the Top Containers' do + visit "#{STAFF_URL}/top_containers/#{@top_container_first_id}/edit" + expect(page).to_not have_css '.location' + + visit "#{STAFF_URL}/top_containers/#{@top_container_second_id}/edit" + expect(page).to_not have_css '.location' +end + +When 'the user fills in New Barcode for Top Container A' do + row = find('#bulkActionBarcodeRapidEntryModal tr', text: "Indicator A #{@uuid}") + + @top_container_first_barcode = SecureRandom.uuid + row.find('input').fill_in with: @top_container_first_barcode +end + +When 'the user fills in New Barcode for Top Container B' do + row = find('#bulkActionBarcodeRapidEntryModal tr', text: "Indicator B #{@uuid}") + + @top_container_second_barcode = SecureRandom.uuid + row.find('input').fill_in with: @top_container_second_barcode +end + +Then 'the Top Containers have new Barcodes' do + visit "#{STAFF_URL}/top_containers/#{@top_container_first_id}/edit" + expect(find_field('Barcode').value).to eq @top_container_first_barcode + + visit "#{STAFF_URL}/top_containers/#{@top_container_second_id}/edit" + expect(find_field('Barcode').value).to eq @top_container_second_barcode +end + +When 'the user fills in New Barcode for Top Container A with {string}' do |value| + row = find('#bulkActionBarcodeRapidEntryModal tr', text: "Indicator A #{@uuid}") + + row.find('input').fill_in with: value +end + +When 'the user fills in New Barcode for Top Container B with {string}' do |value| + row = find('#bulkActionBarcodeRapidEntryModal tr', text: "Indicator A #{@uuid}") + + row.find('input').fill_in with: value +end + +When 'the user selects the Top Container B in the Merge Top Containers modal' do + find('#chkPref', text: "Indicator B #{@uuid}").find('input').click +end + +When 'the user clicks on {string} in the Confirm Merge Top Containers modal' do |string| + within '#bulkMergeConfirmModal' do + click_on_string string + end +end + +Then 'the Top Container A is deleted' do + visit "#{STAFF_URL}/top_containers/#{@top_container_first_id}/edit" + + expect(page).to have_text 'Record Not Found' + expect(page).to have_text "The record you've tried to access may no longer exist or you may not have permission to view it." +end + +Then 'the two Top Containers are deleted' do + visit "#{STAFF_URL}/top_containers/#{@top_container_first_id}/edit" + expect(page).to have_text 'Record Not Found' + expect(page).to have_text "The record you've tried to access may no longer exist or you may not have permission to view it." + + visit "#{STAFF_URL}/top_containers/#{@top_container_second_id}/edit" + expect(page).to have_text 'Record Not Found' + expect(page).to have_text "The record you've tried to access may no longer exist or you may not have permission to view it." +end diff --git a/staff_features/top_containers/top_containers_bulk_operations.feature b/staff_features/top_containers/top_containers_bulk_operations.feature index 73e485ff..ca84c79d 100644 --- a/staff_features/top_containers/top_containers_bulk_operations.feature +++ b/staff_features/top_containers/top_containers_bulk_operations.feature @@ -1,120 +1,105 @@ -Feature: Top Container bulk operations +Feature: Top Containers Bulk Operations Background: Given an administrator user is logged in - And a Resource with 2 Top Containers has been created + And a Resource with two Top Containers has been created And the user is on the Top Containers page - And the user fills in 'Keyword' with the Resource title - And the user clicks on 'Search' + And the the two Top Containers are displayed in the search results Scenario: Select all Top Containers When the user checks the checkbox in the header row - Then all Top Containers are selected - And the 'Bulk Operations' button is active + Then all the Top Containers are selected + And the 'Bulk Operations' button is enabled Scenario: Unselect all Top Containers Given all Top Containers are selected When the user checks the checkbox in the header row - Then all Top Containers are unselected - And the 'Bulk Operations' button is not active - Scenario: Select Top Container - When the user checks the checkbox in the left-hand column of Top container - Then the Top Container is selected - And the 'Bulk Operations' button is active + Then all the Top Containers are not selected + And the 'Bulk Operations' button is disabled Scenario: Update ILS holdings IDs of a Top Container - Given a Top Container is selected + Given the Top Container A is selected When the user clicks on 'Bulk Operations' - And the user clicks on 'Update ILS holdings IDs' in the dropdown menu + And the user clicks on 'Update ILS Holding IDs' in the dropdown menu And the user fills in 'ILS Holding ID' with '123456789' - And the user clicks on 'Update 1 records' button + And the user clicks on 'Update 1 records' Then the 'Top Containers' updated message is displayed - And the 'ILS Holding ID' has value '123456789' Scenario: Update Container Profile of a Top Container by browsing - Given a Top Container is selected - And a Container Profile has been created + Given the Top Container A is selected When the user clicks on 'Bulk Operations' - And the user clicks on 'Update Container Profile' in the dropdown menu + And the user clicks on 'Update Container Profiles' in the dropdown menu + And the user clicks on the dropdown in the Bulk Update form And the user clicks on 'Browse' in the dropdown menu And the user selects Container Profile in the modal - And the user clicks on 'Link' in the modal - And the user clicks on 'Update 1 records' button - Then the 'Top Containers' updated message is displayed - And the Top Container profile is linked to the selected Container Profile + And the user clicks on 'Link' in the Browse Container Profiles modal + And the user clicks on 'Update 1 records' + And the Top Container A profile is linked to the Container Profile Scenario: Update Container Profile of a Top Container by creating Container Profile - Given a Top Container is selected + Given the Top Container A is selected When the user clicks on 'Bulk Operations' - And the user clicks on 'Update Container Profile' in the dropdown menu + And the user clicks on 'Update Container Profiles' in the dropdown menu + And the user clicks on the dropdown in the Bulk Update form And the user clicks on 'Create' in the dropdown menu - And the user fills in 'Name' with 'Test Container Profile' in the modal - And the user fills in 'Depth' with '90' in the modal - And the user fills in 'Height' with '90' in the modal - And the user fills in 'Width' with '90' in the modal - And the user clicks on 'Create and Link' in the modal - And the user clicks on 'Update 1 records' button - Then the 'Top Containers' updated message is displayed - And the 'Top Container Profile' has Name 'Test Container Profile' + And the user fills in 'Name' in the Create Container Profiles modal + And the user fills in 'Depth' with '1.1' in the Create Container Profiles modal + And the user fills in 'Height' with '1.2' in the Create Container Profiles modal + And the user fills in 'Width' with '1.3' in the Create Container Profiles modal + And the user clicks on 'Create and Link' + And the user clicks on 'Update 1 records' + And the Top Container A profile is linked to the created Container Profile Scenario: Update Single Location of a Top Container by browsing - Given a Top Container is selected - And a Location has been created + Given the Top Container A is selected When the user clicks on 'Bulk Operations' And the user clicks on 'Update Locations: Single Location' in the dropdown menu + And the user clicks on the dropdown in the Bulk Update form And the user clicks on 'Browse' in the dropdown menu And the user selects Location in the modal - And the user clicks on 'Link' in the modal - And the user clicks on 'Update 1 records' button - Then the 'Top Containers' updated message is displayed - And the Top Container profile is linked to the selected Location + And the user clicks on 'Link' in the Browse Locations modal + And the user clicks on 'Update 1 records' + And the Top Container profile is linked to the Location Scenario: Update Single Location of a Top Container by creating Location - Given a Top Container is selected + Given the Top Container A is selected When the user clicks on 'Bulk Operations' And the user clicks on 'Update Locations: Single Location' in the dropdown menu + And the user clicks on the dropdown in the Bulk Update form And the user clicks on 'Create' in the dropdown menu - And the user fills in 'Building' with 'test building' in the modal - And the user fills in 'Barcode' with '1234543' in the modal - And the user clicks on 'Create and Link' in the modal - And the user clicks on 'Update 1 records' button - Then the 'Top Containers' updated message is displayed + And the user fills in 'Building' with 'Test Building' in the Create Location modal + And the user fills in 'Barcode' with '123456789' in the Create Location modal + And the user clicks on 'Create and Link' in the Create Location modal + And the user clicks on 'Update 1 records' And the Top Container profile is linked to the created Location Scenario: Remove Locations from Top Containers without replacing the Locations - Given two Top Containers A&B are created with Locations are created And the two Top Containers are selected When the user clicks on 'Bulk Operations' And the user clicks on 'Update Locations: Multiple Locations' in the dropdown menu - And the user clicks on 'Update 2 records' button - Then the 'Top Containers' updated message is displayed - And the Locations are removed from the Top Containers - Scenario: Add Barcodes associated with Top Containers successfully - Given two Top Containers A&B are created - And the two Top Containers are selected - When the user clicks on 'Bulk Operations' - And the user clicks on 'Rapid Barcode Entry' in the dropdown menu - And the user fills in 'New Barcode' with '123456' for A Top Container - And the user fills in 'New Barcode' with '678901' for B Top Container - And the user clicks on 'Update 2 records' button - Then the 'Top Containers' updated message is displayed - And the Top Containers have new Barcodes - Scenario: Barcodes associated with Top Containers are not added - Given two Top Containers A&B are created + And the user clicks on 'Update 2 records' + Then the Locations are removed from the Top Containers + Scenario: Add Barcodes associated with Top Containers successfully And the two Top Containers are selected When the user clicks on 'Bulk Operations' And the user clicks on 'Rapid Barcode Entry' in the dropdown menu - And the user fills in 'New Barcode' with '123456' for A Top Container - And the user fills in 'New Barcode' with '123456' for B Top Container - And the user clicks on 'Update 2 records' button + And the user fills in New Barcode for Top Container A + And the user fills in New Barcode for Top Container B + And the user clicks on 'Update 2 records' + And the Top Containers have new Barcodes + Scenario: Barcodes associated with Top Containers are not added + Given the two Top Containers are selected + When the user clicks on 'Bulk Operations' + And the user clicks on 'Rapid Barcode Entry' in the dropdown menu + And the user fills in New Barcode for Top Container A with '123456789' + And the user fills in New Barcode for Top Container B with '123456789' + And the user clicks on 'Update 2 records' Then the following error message is displayed |Barcode - A barcode must be unique within a repository| Scenario: Merge two Top Containers - Given two Top Containers A&B are created - And the two Top Containers are selected + Given the two Top Containers are selected When the user clicks on 'Bulk Operations' And the user clicks on 'Merge Top Containers' in the dropdown menu - And the user selects the Top Container B in the modal - And the user clicks on 'Select merge target' in the modal - And the user clicks on 'Merge 2 records' in the modal - Then the 'Top Containers' merged message is displayed + And the user selects the Top Container B in the Merge Top Containers modal + And the user clicks on 'Select merge destination' in the modal + And the user clicks on 'Merge 2 records' in the Confirm Merge Top Containers modal + Then the 'Top Container(s)' merged message is displayed And the Top Container A is deleted Scenario: Delete two Top Containers - Given two Top Containers A&B are created - And the two Top Containers are selected + Given the two Top Containers are selected When the user clicks on 'Bulk Operations' And the user clicks on 'Delete Top Containers' in the dropdown menu And the user clicks on 'Delete 2 records' in the modal Then the 'Top Containers' deleted message is displayed - And the Top Containers A&B are deleted \ No newline at end of file + And the two Top Containers are deleted