5737: Merge branch 'master' into 5737-ruby231
[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   # Looks for the text_to_look_for for up to the max_time provided
25   def wait_until_page_has text_to_look_for, max_time=30
26     max_time = 30 if (!max_time || (max_time.to_s != max_time.to_i.to_s))
27     text_found = false
28     Timeout.timeout(max_time) do
29       until text_found do
30         visit_page_with_token 'active', current_path
31         text_found = has_text?(text_to_look_for)
32       end
33     end
34   end
35 end