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