| 
 | 1 | +# frozen_string_literal: true  | 
 | 2 | + | 
 | 3 | +Given 'two Digital Objects A & B have been created' do  | 
 | 4 | +  visit "#{STAFF_URL}/digital_objects/new"  | 
 | 5 | + | 
 | 6 | +  fill_in 'digital_object_digital_object_id_', with: "Digital Object A #{@uuid}"  | 
 | 7 | +  fill_in 'digital_object_title_', with: "Digital Object A #{@uuid}"  | 
 | 8 | + | 
 | 9 | +  click_on 'Save'  | 
 | 10 | +  wait_for_ajax  | 
 | 11 | + | 
 | 12 | +  expect(find('.alert.alert-success.with-hide-alert').text).to have_text "Digital Object Digital Object A #{@uuid} Created"  | 
 | 13 | +  @digital_object_first_id = current_url.split('::digital_object_').pop  | 
 | 14 | + | 
 | 15 | +  visit "#{STAFF_URL}/digital_objects/new"  | 
 | 16 | + | 
 | 17 | +  fill_in 'digital_object_digital_object_id_', with: "Digital Object B #{@uuid}"  | 
 | 18 | +  fill_in 'digital_object_title_', with: "Digital Object B #{@uuid}"  | 
 | 19 | + | 
 | 20 | +  click_on 'Add Agent Link'  | 
 | 21 | +  select 'Creator', from: 'digital_object_linked_agents__0__role_'  | 
 | 22 | +  fill_in 'digital_object_linked_agents__0__title_', with: "Resource #{@uuid} Agent Title"  | 
 | 23 | +  fill_in 'digital_object_linked_agents__0__relator_', with: 'annotator'  | 
 | 24 | +  dropdown_items = all('.typeahead.typeahead-long.dropdown-menu')  | 
 | 25 | +  dropdown_items.first.click  | 
 | 26 | +  fill_in 'token-input-digital_object_linked_agents__0__ref_', with: 'test_agent'  | 
 | 27 | +  dropdown_items = all('li.token-input-dropdown-item2')  | 
 | 28 | +  dropdown_items.first.click  | 
 | 29 | + | 
 | 30 | +  click_on 'Add Subject'  | 
 | 31 | +  fill_in 'token-input-digital_object_subjects__0__ref_', with: 'test_subject'  | 
 | 32 | +  dropdown_items = all('li.token-input-dropdown-item2')  | 
 | 33 | +  dropdown_items.first.click  | 
 | 34 | + | 
 | 35 | +  click_on 'Add Classification'  | 
 | 36 | +  fill_in 'token-input-digital_object_classifications__0__ref_', with: 'test_classification'  | 
 | 37 | +  dropdown_items = all('li.token-input-dropdown-item2')  | 
 | 38 | +  dropdown_items.first.click  | 
 | 39 | + | 
 | 40 | +  click_on 'Save'  | 
 | 41 | +  wait_for_ajax  | 
 | 42 | + | 
 | 43 | +  expect(find('.alert.alert-success.with-hide-alert').text).to have_text "Digital Object Digital Object B #{@uuid} Created"  | 
 | 44 | +  @digital_object_second_id = current_url.split('::digital_object_').pop  | 
 | 45 | +end  | 
 | 46 | + | 
 | 47 | +Given 'the Digital Object A is opened in edit mode' do  | 
 | 48 | +  visit "#{STAFF_URL}/digital_objects/#{@digital_object_first_id}/edit"  | 
 | 49 | +end  | 
 | 50 | + | 
 | 51 | +When 'the user selects the Digital Object B from the search results in the modal' do  | 
 | 52 | +  within '.modal-content' do  | 
 | 53 | +    within '#tabledSearchResults' do  | 
 | 54 | +      rows = all('tr', text: "Digital Object B #{@uuid}")  | 
 | 55 | +      expect(rows.length).to eq 1  | 
 | 56 | + | 
 | 57 | +      find('input[type="radio"]').click  | 
 | 58 | +    end  | 
 | 59 | +  end  | 
 | 60 | +end  | 
 | 61 | + | 
 | 62 | +When 'the user filters by text with the Digital Object B title in the modal' do  | 
 | 63 | +  within '.modal-content' do  | 
 | 64 | +    fill_in 'Filter by text', with: "Digital Object B #{@uuid}"  | 
 | 65 | +    find('.search-filter button').click  | 
 | 66 | + | 
 | 67 | +    rows = []  | 
 | 68 | +    checks = 0  | 
 | 69 | + | 
 | 70 | +    while checks < 5  | 
 | 71 | +      checks += 1  | 
 | 72 | + | 
 | 73 | +      begin  | 
 | 74 | +        rows = all('tr', text: "Digital Object B #{@uuid}")  | 
 | 75 | +      rescue Selenium::WebDriver::Error::JavascriptError  | 
 | 76 | +        sleep 1  | 
 | 77 | +      end  | 
 | 78 | + | 
 | 79 | +      break if rows.length == 1  | 
 | 80 | +    end  | 
 | 81 | +  end  | 
 | 82 | +end  | 
 | 83 | + | 
 | 84 | +When 'the user fills in and selects the Digital Object B in the merge dropdown form' do  | 
 | 85 | +  fill_in 'token-input-merge_ref_', with: "Digital Object B #{@uuid}"  | 
 | 86 | +  dropdown_items = all('li.token-input-dropdown-item2')  | 
 | 87 | +  dropdown_items.first.click  | 
 | 88 | +end  | 
 | 89 | + | 
 | 90 | +Then 'the Digital Object B is deleted' do  | 
 | 91 | +  visit "#{STAFF_URL}/digital_objects/#{@digital_object_second_id}"  | 
 | 92 | + | 
 | 93 | +  expect(page).to have_text 'Record Not Found'  | 
 | 94 | +end  | 
 | 95 | + | 
 | 96 | +Then 'the following linked records from the Digital Object B are appended to the Digital Object A' do |forms|  | 
 | 97 | +  visit "#{STAFF_URL}/digital_objects/#{@digital_object_first_id}/edit"  | 
 | 98 | + | 
 | 99 | +  forms.raw.each do |form_title|  | 
 | 100 | +    form_title = form_title[0]  | 
 | 101 | + | 
 | 102 | +    section_title = find('h3', text: form_title)  | 
 | 103 | +    section = section_title.ancestor('section')  | 
 | 104 | +    expect(section[:id]).to_not eq nil  | 
 | 105 | + | 
 | 106 | +    case form_title  | 
 | 107 | +    when 'Agent Links'  | 
 | 108 | +      expect(find('#digital_object_linked_agents__0__role_').value).to eq 'creator'  | 
 | 109 | +      expect(find('#digital_object_linked_agents__0__title_').value).to eq "Resource #{@uuid} Agent Title"  | 
 | 110 | +      expect(find('#digital_object_linked_agents__0__relator_').value).to eq 'Annotator'  | 
 | 111 | +      expect(find('#digital_object_linked_agents__0__ref__combobox .token-input-token').text).to include 'test_agent'  | 
 | 112 | +    when 'Related Accessions'  | 
 | 113 | +      expect(find('#digital_object_related_accessions__0__ref__combobox').text).to include 'test_accession'  | 
 | 114 | +    when 'Subjects'  | 
 | 115 | +      expect(find('#digital_object_subjects__0_ .token-input-token').text).to include 'test_subject_term'  | 
 | 116 | +    when 'Classifications'  | 
 | 117 | +      expect(find('#digital_object_classifications__0__ref__combobox').text).to include 'test_classification'  | 
 | 118 | +    else  | 
 | 119 | +      raise "Invalid form provided: #{form_title}"  | 
 | 120 | +    end  | 
 | 121 | +  end  | 
 | 122 | +end  | 
0 commit comments