|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +When 'the user filters by text with the Event record link title' do |
| 4 | + fill_in 'Filter by text', with: @uuid |
| 5 | + |
| 6 | + find('#filter-text').send_keys(:enter) |
| 7 | + |
| 8 | + rows = [] |
| 9 | + checks = 0 |
| 10 | + |
| 11 | + while checks < 5 |
| 12 | + checks += 1 |
| 13 | + |
| 14 | + begin |
| 15 | + rows = all('tr', text: @uuid) |
| 16 | + rescue Selenium::WebDriver::Error::JavascriptError |
| 17 | + sleep 1 |
| 18 | + end |
| 19 | + |
| 20 | + break if rows.length == 1 |
| 21 | + end |
| 22 | +end |
| 23 | + |
| 24 | +Then 'the Event view page is displayed' do |
| 25 | + expect(current_url).to eq "#{STAFF_URL}/events/#{@event_id}" |
| 26 | +end |
| 27 | + |
| 28 | +Then 'the Event is in the search results' do |
| 29 | + expect(page).to have_css('tr', text: 'test_agent') |
| 30 | +end |
| 31 | + |
| 32 | +Given 'two Events have been created with a common keyword in their record link title' do |
| 33 | + @shared_accession_uuid = SecureRandom.uuid |
| 34 | + @accession_a_uuid = SecureRandom.uuid |
| 35 | + @accession_b_uuid = SecureRandom.uuid |
| 36 | + |
| 37 | + visit "#{STAFF_URL}/accessions/new" |
| 38 | + fill_in 'accession_title_', with: "Accession A #{@accession_a_uuid} #{@shared_accession_uuid}" |
| 39 | + fill_in 'accession_id_0_', with: "Accession A #{@accession_a_uuid}" |
| 40 | + click_on 'Save' |
| 41 | + |
| 42 | + visit "#{STAFF_URL}/accessions/new" |
| 43 | + fill_in 'accession_title_', with: "Accession B #{@accession_b_uuid} #{@shared_accession_uuid}" |
| 44 | + fill_in 'accession_id_0_', with: "Accession B #{@accession_b_uuid}" |
| 45 | + click_on 'Save' |
| 46 | + |
| 47 | + visit "#{STAFF_URL}/events/new" |
| 48 | + fill_in 'Outcome Note', with: "A #{@shared_accession_uuid}" |
| 49 | + within '#event_date' do |
| 50 | + select 'Single', from: 'Type' |
| 51 | + fill_in 'Begin', with: '2020-01-01' |
| 52 | + end |
| 53 | + select 'Authorizer', from: 'event_linked_agents__0__role_' |
| 54 | + fill_in 'token-input-event_linked_agents__0__ref_', with: 'test_agent' |
| 55 | + dropdown_items = all('li.token-input-dropdown-item2') |
| 56 | + dropdown_items.first.click |
| 57 | + select 'Outcome', from: 'event_linked_records__0__role_' |
| 58 | + fill_in 'token-input-event_linked_records__0__ref_', with: "Accession A #{@accession_a_uuid} #{@shared_accession_uuid}" |
| 59 | + dropdown_items = all('li.token-input-dropdown-item2') |
| 60 | + dropdown_items.first.click |
| 61 | + find('button', text: 'Save Event', match: :first).click |
| 62 | + expect(find('.alert.alert-success').text).to eq 'Event Created' |
| 63 | + url_parts = current_url.split('events').pop.split('/') |
| 64 | + url_parts.pop |
| 65 | + @event_first_id = url_parts.pop |
| 66 | + |
| 67 | + visit "#{STAFF_URL}/events/new" |
| 68 | + fill_in 'Outcome Note', with: "B #{@shared_accession_uuid}" |
| 69 | + within '#event_date' do |
| 70 | + select 'Single', from: 'Type' |
| 71 | + fill_in 'Begin', with: '2020-01-01' |
| 72 | + end |
| 73 | + select 'Authorizer', from: 'event_linked_agents__0__role_' |
| 74 | + fill_in 'token-input-event_linked_agents__0__ref_', with: 'test_agent' |
| 75 | + dropdown_items = all('li.token-input-dropdown-item2') |
| 76 | + dropdown_items.first.click |
| 77 | + select 'Outcome', from: 'event_linked_records__0__role_' |
| 78 | + fill_in 'token-input-event_linked_records__0__ref_', with: "Accession B #{@accession_b_uuid} #{@shared_accession_uuid}" |
| 79 | + dropdown_items = all('li.token-input-dropdown-item2') |
| 80 | + dropdown_items.first.click |
| 81 | + select 'Accumulation', from: 'event_event_type_' |
| 82 | + find('button', text: 'Save Event', match: :first).click |
| 83 | + expect(find('.alert.alert-success').text).to eq 'Event Created' |
| 84 | + url_parts = current_url.split('events').pop.split('/') |
| 85 | + url_parts.pop |
| 86 | + @event_first_id = url_parts.pop |
| 87 | +end |
| 88 | + |
| 89 | +Then 'the two Events are displayed sorted by descending type' do |
| 90 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 91 | + |
| 92 | + expect(search_result_rows.length).to eq 2 |
| 93 | + expect(search_result_rows[1]).to have_text @accession_a_uuid |
| 94 | + expect(search_result_rows[0]).to have_text @accession_b_uuid |
| 95 | +end |
| 96 | + |
| 97 | +Then 'the two Events are displayed sorted by ascending outcome' do |
| 98 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 99 | + |
| 100 | + expect(search_result_rows.length).to eq 2 |
| 101 | + expect(search_result_rows[0]).to have_text @accession_a_uuid |
| 102 | + expect(search_result_rows[1]).to have_text @accession_b_uuid |
| 103 | +end |
| 104 | + |
| 105 | +Then 'the two Events are displayed sorted by ascending created date' do |
| 106 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 107 | + |
| 108 | + expect(search_result_rows.length).to eq 2 |
| 109 | + expect(search_result_rows[0]).to have_text @accession_a_uuid |
| 110 | + expect(search_result_rows[1]).to have_text @accession_b_uuid |
| 111 | +end |
| 112 | + |
| 113 | +Then 'the two Events are displayed sorted by ascending modified date' do |
| 114 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 115 | + |
| 116 | + expect(search_result_rows.length).to eq 2 |
| 117 | + expect(search_result_rows[0]).to have_text @accession_a_uuid |
| 118 | + expect(search_result_rows[1]).to have_text @accession_b_uuid |
| 119 | +end |
| 120 | + |
| 121 | +Given 'the two Events are displayed sorted by ascending type' do |
| 122 | + visit "#{STAFF_URL}/events" |
| 123 | + |
| 124 | + fill_in 'filter-text', with: @shared_accession_uuid |
| 125 | + |
| 126 | + within '.search-filter' do |
| 127 | + find('button').click |
| 128 | + end |
| 129 | + |
| 130 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 131 | + |
| 132 | + expect(search_result_rows.length).to eq 2 |
| 133 | + expect(search_result_rows[0]).to have_text @accession_a_uuid |
| 134 | + expect(search_result_rows[1]).to have_text @accession_b_uuid |
| 135 | +end |
0 commit comments