|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +Then 'the Container Profile is in the search results' do |
| 4 | + expect(page).to have_css('tr', text: @uuid) |
| 5 | +end |
| 6 | + |
| 7 | +When 'the user filters by text with the Container Profile name' do |
| 8 | + fill_in 'Filter by text', with: @uuid |
| 9 | + |
| 10 | + find('#filter-text').send_keys(:enter) |
| 11 | + |
| 12 | + rows = [] |
| 13 | + checks = 0 |
| 14 | + |
| 15 | + while checks < 5 |
| 16 | + checks += 1 |
| 17 | + |
| 18 | + begin |
| 19 | + rows = all('tr', text: @uuid) |
| 20 | + rescue Selenium::WebDriver::Error::JavascriptError |
| 21 | + sleep 1 |
| 22 | + end |
| 23 | + |
| 24 | + break if rows.length == 1 |
| 25 | + end |
| 26 | +end |
| 27 | + |
| 28 | +Then 'the Container Profile view page is displayed' do |
| 29 | + expect(find('h2').text).to eq "Container Profile #{@uuid}" |
| 30 | +end |
| 31 | + |
| 32 | +Given 'two Container Profiles have been created with a common keyword in their name' do |
| 33 | + @shared_container_profile_uuid = SecureRandom.uuid |
| 34 | + @container_profile_a_uuid = SecureRandom.uuid |
| 35 | + @container_profile_b_uuid = SecureRandom.uuid |
| 36 | + |
| 37 | + visit "#{STAFF_URL}/container_profiles/new" |
| 38 | + fill_in 'container_profile_name_', with: "Container Profile A #{@shared_container_profile_uuid} #{@container_profile_a_uuid}" |
| 39 | + fill_in 'container_profile_depth_', with: '1.1' |
| 40 | + fill_in 'container_profile_height_', with: '2.2' |
| 41 | + fill_in 'container_profile_width_', with: '3.3' |
| 42 | + click_on 'Save' |
| 43 | + expect(find('.alert.alert-success.with-hide-alert').text).to eq 'Container Profile Created' |
| 44 | + url_parts = current_url.split('container_profiles/container_profile_person').pop.split('/') |
| 45 | + @container_profile_a_id = url_parts.pop |
| 46 | + |
| 47 | + visit "#{STAFF_URL}/container_profiles/new" |
| 48 | + fill_in 'container_profile_name_', with: "Container Profile B #{@shared_container_profile_uuid} #{@container_profile_b_uuid}" |
| 49 | + fill_in 'container_profile_depth_', with: '1.1' |
| 50 | + fill_in 'container_profile_height_', with: '2.2' |
| 51 | + fill_in 'container_profile_width_', with: '3.3' |
| 52 | + click_on 'Save' |
| 53 | + expect(find('.alert.alert-success.with-hide-alert').text).to eq 'Container Profile Created' |
| 54 | + url_parts = current_url.split('container_profiles/container_profile_person').pop.split('/') |
| 55 | + url_parts.pop |
| 56 | + @container_profile_b_id = url_parts.pop |
| 57 | +end |
| 58 | + |
| 59 | +Given 'the two Container Profiles are displayed sorted by ascending name' do |
| 60 | + visit "#{STAFF_URL}/container_profiles" |
| 61 | + |
| 62 | + fill_in 'filter-text', with: @shared_container_profile_uuid |
| 63 | + |
| 64 | + within '.search-filter' do |
| 65 | + find('button').click |
| 66 | + end |
| 67 | + |
| 68 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 69 | + |
| 70 | + expect(search_result_rows.length).to eq 2 |
| 71 | + expect(search_result_rows[0]).to have_text @container_profile_a_uuid |
| 72 | + expect(search_result_rows[1]).to have_text @container_profile_b_uuid |
| 73 | +end |
| 74 | + |
| 75 | +Then 'the two Container Profiles are displayed sorted by descending name' do |
| 76 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 77 | + |
| 78 | + expect(search_result_rows.length).to eq 2 |
| 79 | + expect(search_result_rows[1]).to have_text @container_profile_a_uuid |
| 80 | + expect(search_result_rows[0]).to have_text @container_profile_b_uuid |
| 81 | +end |
| 82 | + |
| 83 | +Given 'the two Container Profiles are displayed in the search results' do |
| 84 | + visit "#{STAFF_URL}/container_profiles" |
| 85 | + |
| 86 | + fill_in 'filter-text', with: @shared_container_profile_uuid |
| 87 | + |
| 88 | + within '.search-filter' do |
| 89 | + find('button').click |
| 90 | + end |
| 91 | + |
| 92 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 93 | + |
| 94 | + expect(search_result_rows.length).to eq 2 |
| 95 | + expect(search_result_rows[0]).to have_text @container_profile_a_uuid |
| 96 | + expect(search_result_rows[1]).to have_text @container_profile_b_uuid |
| 97 | +end |
| 98 | + |
| 99 | +Then 'a CSV file is downloaded with the two Container Profiles' do |
| 100 | + files = Dir.glob(File.join(Dir.tmpdir, '*.csv')) |
| 101 | + |
| 102 | + downloaded_file = nil |
| 103 | + files.each do |file| |
| 104 | + downloaded_file = file if file.include?('container profiles') |
| 105 | + end |
| 106 | + |
| 107 | + expect(downloaded_file).to_not eq nil |
| 108 | + |
| 109 | + load_file = File.read(downloaded_file) |
| 110 | + expect(load_file).to include @container_profile_a_uuid |
| 111 | + expect(load_file).to include @container_profile_b_uuid |
| 112 | + expect(load_file).to include "Container Profile A #{@shared_container_profile_uuid} #{@container_profile_a_uuid}" |
| 113 | + expect(load_file).to include "Container Profile B #{@shared_container_profile_uuid} #{@container_profile_b_uuid}" |
| 114 | +end |
0 commit comments