8784: Fix test for latest firefox.
[arvados.git] / apps / workbench / test / diagnostics_test_helper.rb
1 require 'integration_helper'
2 require 'yaml'
3
4 # Diagnostics tests are executed when "RAILS_ENV=diagnostics" is used.
5 # When "RAILS_ENV=test" is used, tests in the "diagnostics" directory
6 # will not be executed.
7
8 # Command to run diagnostics tests:
9 #   RAILS_ENV=diagnostics bundle exec rake TEST=test/diagnostics/**/*.rb
10
11 class DiagnosticsTest < ActionDispatch::IntegrationTest
12
13   # Prepends workbench URL to the path provided and visits that page
14   # Expects path parameters such as "/collections/<uuid>"
15   def visit_page_with_token token_name, path='/'
16     workbench_url = Rails.configuration.arvados_workbench_url
17     if workbench_url.end_with? '/'
18       workbench_url = workbench_url[0, workbench_url.size-1]
19     end
20     tokens = Rails.configuration.user_tokens
21     visit page_with_token(tokens[token_name], (workbench_url + path))
22   end
23
24   def select_input look_for
25     inputs_needed = page.all('.btn', text: 'Choose')
26     return if (!inputs_needed || !inputs_needed.any?)
27
28     look_for_uuid = nil
29     look_for_file = nil
30     if look_for.andand.index('/').andand.>0
31       partitions = look_for.partition('/')
32       look_for_uuid = partitions[0]
33       look_for_file = partitions[2]
34     else
35       look_for_uuid = look_for
36       look_for_file = nil
37     end
38
39     assert_triggers_dom_event 'shown.bs.modal' do
40       inputs_needed[0].click
41     end
42
43     within('.modal-dialog') do
44       if look_for_uuid
45         fill_in('Search', with: look_for_uuid, exact: true)
46         wait_for_ajax
47       end
48
49       page.all('.selectable').first.click
50       wait_for_ajax
51       # ajax reload is wiping out input selection after search results; so, select again.
52       page.all('.selectable').first.click
53       wait_for_ajax
54
55       if look_for_file
56         wait_for_ajax
57         within('.collection_files_name', text: look_for_file) do
58           find('.fa-file').click
59         end
60       end
61
62       find('button', text: 'OK').click
63       wait_for_ajax
64     end
65   end
66
67   # Looks for the text_to_look_for for up to the max_time provided
68   def wait_until_page_has text_to_look_for, max_time=30
69     max_time = 30 if (!max_time || (max_time.to_s != max_time.to_i.to_s))
70     text_found = false
71     Timeout.timeout(max_time) do
72       until text_found do
73         visit_page_with_token 'active', current_path
74         text_found = has_text?(text_to_look_for)
75       end
76     end
77   end
78 end