From af1dce29825fbd2a5c076241b331a75259d0021c Mon Sep 17 00:00:00 2001 From: Konstantina Dimopoulou <13031341+kdimopulu@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:42:22 +0200 Subject: [PATCH] Resource merge (#39) * gherkin scenarios for merge resources * Resource merge --------- Co-authored-by: blacksmith-welder --- helpers/helpers.rb | 16 ++ .../resources/resource_merge.feature | 34 ++++ .../step_definitions/resource_merge.rb | 179 ++++++++++++++++++ staff_features/shared/step_definitions.rb | 5 + 4 files changed, 234 insertions(+) create mode 100644 staff_features/resources/resource_merge.feature create mode 100644 staff_features/resources/step_definitions/resource_merge.rb diff --git a/helpers/helpers.rb b/helpers/helpers.rb index 0d84f9c..43ab88a 100644 --- a/helpers/helpers.rb +++ b/helpers/helpers.rb @@ -154,6 +154,22 @@ def ensure_test_subject_exists end end +def ensure_test_accession_exists + visit STAFF_URL + + fill_in 'global-search-box', with: 'test_accession' + find('#global-search-button').click + + begin + find 'tr', text: 'test_accession' + rescue Capybara::ElementNotFound + visit "#{STAFF_URL}/accessions/new" + fill_in 'accession_id_0_', with: 'test_accession' + fill_in 'accession_title_', with: 'test_accession' + click_on 'Save' + end +end + def ensure_test_classification_exists visit STAFF_URL diff --git a/staff_features/resources/resource_merge.feature b/staff_features/resources/resource_merge.feature new file mode 100644 index 0000000..c6ed584 --- /dev/null +++ b/staff_features/resources/resource_merge.feature @@ -0,0 +1,34 @@ +Feature: Resource merge + Background: + Given an administrator user is logged in + And two Resources A & B have been created + Scenario: Merge two Resources by browsing + Given the Resource A is opened in edit mode + When the user clicks on 'Merge' + And the user clicks on the dropdown in the merge dropdown form + And the user clicks on 'Browse' in the merge dropdown form + And the user filters by text with the Resource B title in the modal + And the user selects the Resource B from the search results in the modal + And the user clicks on 'Link' in the modal + And the user clicks on 'Merge' in the merge dropdown form + And the user clicks on 'Merge' in the modal + Then the 'Resource(s)' merged message is displayed + And the Resource B is deleted + And the following linked records from the Resource B are appended to the Resource A + | Related Accessions | + | Agent Links | + | Subjects | + | Classifications | + Scenario: Merge two Resources by searching + Given the Resource A is opened in edit mode + When the user clicks on 'Merge' + And the user fills in and selects the Resource B in the merge dropdown form + And the user clicks on 'Merge' in the merge dropdown form + And the user clicks on 'Merge' in the modal + Then the 'Resource(s)' merged message is displayed + And the Resource B is deleted + And the following linked records from the Resource B are appended to the Resource A + | Related Accessions | + | Agent Links | + | Subjects | + | Classifications | diff --git a/staff_features/resources/step_definitions/resource_merge.rb b/staff_features/resources/step_definitions/resource_merge.rb new file mode 100644 index 0000000..cbe652a --- /dev/null +++ b/staff_features/resources/step_definitions/resource_merge.rb @@ -0,0 +1,179 @@ +# frozen_string_literal: true + +Given 'two Resources A & B have been created' do + visit "#{STAFF_URL}/resources/new" + + fill_in 'resource_title_', with: "Resource A #{@uuid}" + fill_in 'resource_id_0_', with: "Resource A #{@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) + + find('button', text: 'Save Resource', match: :first).click + wait_for_ajax + expect(page).to have_text "Resource Resource A #{@uuid} created" + + uri_parts = current_url.split('/') + uri_parts.pop + @resource_first_id = uri_parts.pop + + visit "#{STAFF_URL}/resources/new" + + fill_in 'resource_title_', with: "Resource B #{@uuid}" + fill_in 'resource_id_0_', with: "Resource B #{@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 Agent Link' + select 'Creator', from: 'resource_linked_agents__0__role_' + fill_in 'resource_linked_agents__0__title_', with: "Resource #{@uuid} Agent Title" + fill_in 'resource_linked_agents__0__relator_', with: 'annotator' + dropdown_items = all('.typeahead.typeahead-long.dropdown-menu') + dropdown_items.first.click + fill_in 'token-input-resource_linked_agents__0__ref_', with: 'test_agent' + dropdown_items = all('li.token-input-dropdown-item2') + dropdown_items.first.click + + click_on 'Add Related Accession' + fill_in 'token-input-resource_related_accessions__0__ref_', with: 'test_accession' + dropdown_items = all('li.token-input-dropdown-item2') + dropdown_items.first.click + + click_on 'Add Subject' + fill_in 'token-input-resource_subjects__0__ref_', with: 'test_subject' + dropdown_items = all('li.token-input-dropdown-item2') + dropdown_items.first.click + + click_on 'Add Classification' + fill_in 'token-input-resource_classifications__0__ref_', with: 'test_classification' + dropdown_items = all('li.token-input-dropdown-item2') + dropdown_items.first.click + + find('button', text: 'Save Resource', match: :first).click + wait_for_ajax + expect(page).to have_text "Resource Resource B #{@uuid} created" + + uri_parts = current_url.split('/') + uri_parts.pop + @resource_second_id = uri_parts.pop +end + +Given 'the Resource A is opened in edit mode' do + visit "#{STAFF_URL}/resources/#{@resource_first_id}/edit" +end + +When 'the user clicks on the dropdown in the merge dropdown form' do + within '#merge-dropdown .dropdown-menu.merge-form' do + find('.btn.btn-default.dropdown-toggle').click + end +end + +When 'the user clicks on {string} in the merge dropdown form' do |string| + within '#merge-dropdown .dropdown-menu.merge-form' do + click_on string + end +end + +When 'the user selects the Resource B from the search results in the modal' do + within '.modal-content' do + within '#tabledSearchResults' do + rows = all('tr', text: "Resource B #{@uuid}") + expect(rows.length).to eq 1 + + find('input[type="radio"]').click + end + end +end + +When 'the user filters by text with the Resource B title in the modal' do + within '.modal-content' do + fill_in 'Filter by text', with: "Resource B #{@uuid}" + find('.search-filter button').click + + rows = [] + checks = 0 + + while checks < 5 + checks += 1 + + begin + rows = all('tr', text: "Resource B #{@uuid}") + rescue Selenium::WebDriver::Error::JavascriptError + sleep 1 + end + + break if rows.length == 1 + end + end +end + +When 'the user fills in and selects the Resource B in the merge dropdown form' do + fill_in 'token-input-merge_ref_', with: "Resource B #{@uuid}" + dropdown_items = all('li.token-input-dropdown-item2') + dropdown_items.first.click +end + +Then 'the Resource B is deleted' do + visit "#{STAFF_URL}/resources/#{@resource_second_id}" + + expect(page).to have_text 'Record Not Found' +end + +Then 'the following linked records from the Resource B are appended to the Resource A' do |forms| + visit "#{STAFF_URL}/resources/#{@resource_first_id}/edit" + + forms.raw.each do |form_title| + form_title = form_title[0] + + section_title = find('h3', text: form_title) + section = section_title.ancestor('section') + expect(section[:id]).to_not eq nil + + case form_title + when 'Agent Links' + expect(find('#resource_linked_agents__0__role_').value).to eq 'creator' + expect(find('#resource_linked_agents__0__title_').value).to eq "Resource #{@uuid} Agent Title" + expect(find('#resource_linked_agents__0__relator_').value).to eq 'Annotator' + expect(find('#resource_linked_agents__0__ref__combobox .token-input-token').text).to include 'test_agent' + when 'Related Accessions' + expect(find('#resource_related_accessions__0__ref__combobox').text).to include 'test_accession' + when 'Subjects' + expect(find('#resource_subjects__0_ .token-input-token').text).to include 'test_subject_term' + when 'Classifications' + expect(find('#resource_classifications__0__ref__combobox').text).to include 'test_classification' + else + raise "Invalid form provided: #{form_title}" + end + end +end diff --git a/staff_features/shared/step_definitions.rb b/staff_features/shared/step_definitions.rb index ff57109..a702da4 100644 --- a/staff_features/shared/step_definitions.rb +++ b/staff_features/shared/step_definitions.rb @@ -13,6 +13,7 @@ ensure_test_user_exists ensure_test_agent_exists ensure_test_subject_exists + ensure_test_accession_exists ensure_test_classification_exists end @@ -234,6 +235,10 @@ 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).to eq("#{string} Merged") +end + Then 'the following message is displayed' do |messages| messages.raw.each do |message| expect(page).to have_text message[0]