Skip to content

Commit

Permalink
Agent merge (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdimopulu authored Feb 24, 2025
1 parent 0ffdc66 commit bb6a2a1
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ Style/NumericPredicate:

Style/ZeroLengthPredicate:
Enabled: false

Style/HashSyntax:
Enabled: false
26 changes: 26 additions & 0 deletions staff_features/agents/agent_merge.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Feature: Agent merge
Background:
Given an administrator user is logged in
And two Agents A & B have been created
Scenario: Merge two Agents by browsing
Given the Agent 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 Agent B name in the modal
And the user selects the Agent 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 'Compare Agents' in the modal
And the user clicks on 'Merge' in the Compare Agents form
Then the 'Agent(s)' merged message is displayed
And the Agent B is deleted
Scenario: Merge two Agents by searching
Given the Agent A is opened in edit mode
When the user clicks on 'Merge'
And the user fills in and selects the Agent B in the merge dropdown form
And the user clicks on 'Merge' in the merge dropdown form
And the user clicks on 'Compare Agents' in the modal
And the user clicks on 'Merge' in the Compare Agents form
Then the 'Agent(s)' merged message is displayed
And the Agent B is deleted
95 changes: 95 additions & 0 deletions staff_features/agents/step_definitions/agent_merge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# frozen_string_literal: true

Given 'two Agents A & B have been created' do
visit "#{STAFF_URL}/agents/agent_person/new"

fill_in 'Primary Part of Name', with: "Agent A #{@uuid}"
find('button', text: 'Save Person', match: :first).click

expect(page).to have_text 'Agent Created'

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

visit "#{STAFF_URL}/agents/agent_person/new"

fill_in 'Primary Part of Name', with: "Agent B #{@uuid}"
find('button', text: 'Save Person', match: :first).click
expect(page).to have_text 'Agent Created'

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

Given 'the Agent A is opened in edit mode' do
visit "#{STAFF_URL}/agents/agent_person/#{@agent_first_id}/edit"
end

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

rows[0].click
end
end
end

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

rows = []
checks = 0

while checks < 5
checks += 1

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

Then 'the Agent B is deleted' do
visit "#{STAFF_URL}/resources/#{@agent_second_id}"

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

When 'the user clicks on {string} in the Compare Agents form' do |text|
tries = 0

loop do
buttons = all('button', text: text, match: :first)

buttons.each do |button|
if button.text == text
button.click
break
end
end

break
rescue Capybara::ElementNotFound => e
tries += 1
sleep 1

raise e if tries == 5
end
end
3 changes: 2 additions & 1 deletion staff_features/shared/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
click_on_string string

wait_for_ajax if current_url.include?("resources/#{@resource_id}/edit") ||
current_url.include?("digital_objects/#{@digital_object_id}/edit")
current_url.include?("digital_objects/#{@digital_object_id}/edit") ||
current_url.include?('merge_selector')
end

When 'the user hovers on {string} in the dropdown menu' do |string|
Expand Down

0 comments on commit bb6a2a1

Please sign in to comment.