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