Skip to content

Commit

Permalink
Resource merge (#39)
Browse files Browse the repository at this point in the history
* gherkin scenarios for merge resources

* Resource merge

---------

Co-authored-by: blacksmith-welder <[email protected]>
  • Loading branch information
kdimopulu and blacksmith-welder authored Dec 24, 2024
1 parent 691b730 commit af1dce2
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 0 deletions.
16 changes: 16 additions & 0 deletions helpers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 34 additions & 0 deletions staff_features/resources/resource_merge.feature
Original file line number Diff line number Diff line change
@@ -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 |
179 changes: 179 additions & 0 deletions staff_features/resources/step_definitions/resource_merge.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions staff_features/shared/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit af1dce2

Please sign in to comment.