Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / test / integration / search_box_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'integration_helper'
6
7 class SearchBoxTest < ActionDispatch::IntegrationTest
8   setup do
9     need_javascript
10   end
11
12   # test the search box
13   def verify_search_box user
14     if user && user['is_active']
15       aproject_uuid = api_fixture('groups')['aproject']['uuid']
16       # let's search for aproject by uuid
17       within('.navbar-fixed-top') do
18         page.has_field?('search this site')
19         page.find_field('search this site').set aproject_uuid
20         page.find('.glyphicon-search').click
21       end
22
23       # we should now be in aproject as a result of search
24       assert_selector 'a', text:'Data collections'
25       click_link 'Data collections'
26       assert_selector "#Data_collections[data-object-uuid='#{aproject_uuid}']", "Expected to be in user page after search click"
27
28       # let's search again for an invalid uuid
29       within('.navbar-fixed-top') do
30         search_for = String.new user['uuid']
31         search_for[0]='1'
32         page.find_field('search this site').set search_for
33         page.find('.glyphicon-search').click
34       end
35
36       # we should see 'not found' error page
37       assert page.has_text?('Not Found'), 'No text - Not Found'
38       assert page.has_link?('Report problem'), 'No text - Report problem'
39       click_link 'Report problem'
40       within '.modal-content' do
41         assert page.has_text?('Report a problem'), 'No text - Report a problem'
42         assert page.has_no_text?('Version / debugging info'), 'No text - Version / debugging info'
43         assert page.has_text?('Describe the problem'), 'No text - Describe the problem'
44         assert page.has_text?('Send problem report'), 'Send problem report button text is not found'
45         assert page.has_no_button?('Send problem report'), 'Send problem report button is not disabled before entering problem description'
46         assert page.has_button?('Cancel'), 'No button - Cancel'
47
48         # enter a report text and click on report
49         page.find_field('report_issue_text').set 'my test report text'
50         assert page.has_button?('Send problem report'), 'Send problem report button not enabled after entering text'
51         click_button 'Send problem report'
52
53         # ajax success updated button texts and added footer message
54         assert page.has_no_text?('Send problem report'), 'Found button - Send problem report'
55         assert page.has_no_button?('Cancel'), 'Found button - Cancel'
56         assert page.has_text?('Report sent'), 'No text - Report sent'
57         assert page.has_button?('Close'), 'No text - Close'
58         assert page.has_text?('Thanks for reporting this issue'), 'No text - Thanks for reporting this issue'
59
60         click_button 'Close'
61       end
62
63       # let's search for the anonymously accessible project
64       publicly_accessible_project = api_fixture('groups')['anonymously_accessible_project']
65
66       within('.navbar-fixed-top') do
67         # search again for the anonymously accessible project
68         page.find_field('search this site').set publicly_accessible_project['name'][0,10]
69         page.find('.glyphicon-search').click
70       end
71
72       within '.modal-content' do
73         assert page.has_text?('All projects'), 'No text - All projects'
74         assert page.has_text?('Search'), 'No text - Search'
75         assert page.has_text?('Cancel'), 'No text - Cancel'
76         assert_selector('div', text: publicly_accessible_project['name'])
77         find(:xpath, '//div[./span[contains(.,publicly_accessible_project["uuid"])]]').click
78
79         click_button 'Show'
80       end
81
82       # seeing "Unrestricted public data" now
83       assert page.has_text?(publicly_accessible_project['name']), 'No text - publicly accessible project name'
84       assert page.has_text?(publicly_accessible_project['description']), 'No text - publicly accessible project description'
85     else
86       within('.navbar-fixed-top') do
87         page.has_no_field?('search this site')
88       end
89     end
90   end
91
92   [
93     [nil, nil],
94     ['inactive', api_fixture('users')['inactive']],
95     ['inactive_uninvited', api_fixture('users')['inactive_uninvited']],
96     ['active', api_fixture('users')['active']],
97     ['admin', api_fixture('users')['admin']],
98   ].each do |token, user|
99
100     test "test search box for user #{token}" do
101       visit page_with_token(token)
102
103       verify_search_box user
104     end
105
106   end
107
108 end