|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +Given 'a Repository has been created' do |
| 4 | + visit "#{STAFF_URL}/repositories/new" |
| 5 | + |
| 6 | + fill_in 'Repository Short Name', with: "repository_test_#{@uuid}" |
| 7 | + fill_in 'Repository Name', with: "repository_test_#{@uuid}" |
| 8 | + |
| 9 | + click_on 'Save' |
| 10 | + |
| 11 | + expect(find('.alert').text).to eq 'Repository Created' |
| 12 | + |
| 13 | + url_parts = current_url.split('repositories').pop.split('/') |
| 14 | + @repository_id = url_parts.pop |
| 15 | +end |
| 16 | + |
| 17 | +When 'the user filters by text with the Repository name' do |
| 18 | + fill_in 'Filter by text', with: "repository_test_#{@uuid}" |
| 19 | + |
| 20 | + find('#filter-text').send_keys(:enter) |
| 21 | + |
| 22 | + rows = [] |
| 23 | + checks = 0 |
| 24 | + |
| 25 | + while checks < 5 |
| 26 | + checks += 1 |
| 27 | + |
| 28 | + begin |
| 29 | + rows = all('tr', text: @uuid) |
| 30 | + rescue Selenium::WebDriver::Error::JavascriptError |
| 31 | + sleep 1 |
| 32 | + end |
| 33 | + |
| 34 | + break if rows.length == 1 |
| 35 | + end |
| 36 | +end |
| 37 | + |
| 38 | +Then 'the Repository view page is displayed' do |
| 39 | + expect(current_url).to eq "#{STAFF_URL}/repositories/#{@repository_id}" |
| 40 | +end |
| 41 | + |
| 42 | +Then 'the Repository is in the search results' do |
| 43 | + expect(page).to have_css('tr', text: @uuid) |
| 44 | +end |
| 45 | + |
| 46 | +Given 'two Repositories have been created with a common keyword in their title' do |
| 47 | + @shared_repository_uuid = SecureRandom.uuid |
| 48 | + @repository_a_uuid = SecureRandom.uuid |
| 49 | + @repository_b_uuid = SecureRandom.uuid |
| 50 | + |
| 51 | + visit "#{STAFF_URL}/repositories/new" |
| 52 | + fill_in 'Repository Short Name', with: "repository_test_a_#{@repository_a_uuid}_#{@shared_repository_uuid}" |
| 53 | + fill_in 'Repository Name', with: "Repository Test A #{@repository_a_uuid} #{@shared_repository_uuid}" |
| 54 | + click_on 'Save' |
| 55 | + |
| 56 | + uri_parts = current_url.split('/') |
| 57 | + uri_parts.pop |
| 58 | + @repository_first_id = uri_parts.pop |
| 59 | + |
| 60 | + visit "#{STAFF_URL}/repositories/new" |
| 61 | + fill_in 'Repository Short Name', with: "repository_test_b_#{@repository_b_uuid}_#{@shared_repository_uuid}" |
| 62 | + fill_in 'Repository Name', with: "Repository Test B #{@repository_b_uuid} #{@shared_repository_uuid}x" |
| 63 | + click_on 'Save' |
| 64 | + uri_parts = current_url.split('/') |
| 65 | + uri_parts.pop |
| 66 | + @repository_second_id = uri_parts.pop |
| 67 | +end |
| 68 | + |
| 69 | +Given 'the two Repositories are displayed sorted by ascending title in the searh results' do |
| 70 | + visit "#{STAFF_URL}/repositories" |
| 71 | + |
| 72 | + fill_in 'filter-text', with: @shared_repository_uuid |
| 73 | + |
| 74 | + within '.search-filter' do |
| 75 | + find('button').click |
| 76 | + end |
| 77 | + |
| 78 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 79 | + |
| 80 | + expect(search_result_rows.length).to eq 2 |
| 81 | + expect(search_result_rows[0]).to have_text @repository_a_uuid |
| 82 | + expect(search_result_rows[1]).to have_text @repository_b_uuid |
| 83 | +end |
| 84 | + |
| 85 | +Then 'the two Repositories are displayed sorted by ascending title' do |
| 86 | + search_result_rows = all('#tabledSearchResults tbody tr') |
| 87 | + |
| 88 | + expect(search_result_rows.length).to eq 2 |
| 89 | + expect(search_result_rows[0]).to have_text @repository_a_uuid |
| 90 | + expect(search_result_rows[1]).to have_text @repository_b_uuid |
| 91 | +end |
0 commit comments