Skip to content

Commit

Permalink
Subject merge
Browse files Browse the repository at this point in the history
  • Loading branch information
blacksmith-welder committed Jan 23, 2025
1 parent 5e3d946 commit 6cacdfb
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 12 deletions.
12 changes: 0 additions & 12 deletions staff_features/resources/step_definitions/resource_merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,6 @@
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
Expand Down
12 changes: 12 additions & 0 deletions staff_features/shared/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,15 @@
Then 'the {string} section is displayed' do |section_heading|
expect(all('section > h3').map(&:text)).to include(section_heading)
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
106 changes: 106 additions & 0 deletions staff_features/subjects/step_definitions/subject_merge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# frozen_string_literal: true

Given 'two Subjects A & B have been created' do
visit "#{STAFF_URL}/subjects/new"

fill_in 'subject_terms__0__term_', with: "subject_term_A_#{@uuid}"
select 'Art & Architecture Thesaurus', from: 'subject_source_'
select 'Cultural context', from: 'subject_terms__0__term_type_'

click_on 'Save'
expect(find('.alert.alert-success.with-hide-alert').text).to eq 'Subject Created'

uri_parts = current_url.split('/')
uri_parts.pop
@subject_first_id = uri_parts.pop

visit "#{STAFF_URL}/subjects/new"

fill_in 'subject_terms__0__term_', with: "subject_term_B_#{@uuid}"
select 'Art & Architecture Thesaurus', from: 'subject_source_'
select 'Cultural context', from: 'subject_terms__0__term_type_'

click_on 'Save'
expect(find('.alert.alert-success.with-hide-alert').text).to eq 'Subject Created'

uri_parts = current_url.split('/')
uri_parts.pop
@subject_second_id = uri_parts.pop
end

Given 'the Subject A is opened in edit mode' do
visit "#{STAFF_URL}/subjects/#{@subject_first_id}/edit"
end

When 'the user selects the Subject B from the search results in the modal' do
within '.modal-content' do
within '#tabledSearchResults' do
rows = all('tr', text: "subject_term_B_#{@uuid}")
expect(rows.length).to eq 1

rows.first.click
end
end
end

When 'the user filters by text with the Subject B title in the modal' do
within '.modal-content' do
fill_in 'Filter by text', with: "subject_term_B_#{@uuid}"
find('.search-filter button').click

rows = []
checks = 0

while checks < 5
checks += 1

begin
rows = all('tr', text: "subject_term_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 Subject B in the merge dropdown form' do
fill_in 'token-input-merge_ref_', with: "subject_term_B_#{@uuid}"
dropdown_items = all('li.token-input-dropdown-item2')
dropdown_items.first.click
end

Then 'the Subject B is deleted' do
visit "#{STAFF_URL}/subjects/#{@subject_second_id}"

expect(page).to have_text 'Record Not Found'
end

Then 'the following linked records from the Subject B are appended to the Subject A' do |forms|
visit "#{STAFF_URL}/subjects/#{@subject_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('#subject_linked_agents__0__role_').value).to eq 'creator'
expect(find('#subject_linked_agents__0__title_').value).to eq "Subject #{@uuid} Agent Title"
expect(find('#subject_linked_agents__0__relator_').value).to eq 'Annotator'
expect(find('#subject_linked_agents__0__ref__combobox .token-input-token').text).to include 'test_agent'
when 'Related Accessions'
expect(find('#subject_related_accessions__0__ref__combobox').text).to include 'test_accession'
when 'Subjects'
expect(find('#subject_subjects__0_ .token-input-token').text).to include 'test_subject_term'
when 'Classifications'
expect(find('#subject_classifications__0__ref__combobox').text).to include 'test_classification'
else
raise "Invalid form provided: #{form_title}"
end
end
end

0 comments on commit 6cacdfb

Please sign in to comment.