Merge branch 'master' into 3112-report-bug
[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.find_field('search').set user['uuid']
18         page.find('.glyphicon-search').click
19       end
20
21       # we should now be in the user's home project as a result of search
22       assert_selector "#Data_collections[data-object-uuid='#{user['uuid']}']", "Expected to be in user page after search click"
23
24       # let's search again for an invalid valid uuid
25       within('.navbar-fixed-top') do
26         search_for = String.new user['uuid']
27         search_for[0]='1'
28         page.find_field('search').set search_for
29         page.find('.glyphicon-search').click
30       end
31
32       # we should see 'not found' error page
33       assert page.has_text?('Not Found'), 'No text - Not Found'
34       assert page.has_link?('Report problem'), 'No text - Report problem'
35       click_link 'Report problem'
36       within '.modal-content' do
37         assert page.has_text?('Report a problem'), 'No text - Report a problem'
38         assert page.has_no_text?('Version / debugging info'), 'No text - Version / debugging info'
39         assert page.has_text?('Describe the problem'), 'No text - Describe the problem'
40         assert page.has_button?('Send problem report'), 'No button - Send problem report'
41         assert page.has_button?('Cancel'), 'No button - Cancel'
42
43         # enter a report text and click on report
44         page.find_field('report_issue_text').set 'my test report text'
45         click_button 'Send problem report'
46
47         # ajax success updated button texts and added footer message
48         assert page.has_no_button?('Send problem report'), 'Found button - Send problem report'
49         assert page.has_no_button?('Cancel'), 'Found button - Cancel'
50         assert page.has_text?('Report sent'), 'No text - Report sent'
51         assert page.has_button?('Close'), 'No text - Close'
52         assert page.has_text?('Thanks for reporting this issue'), 'No text - Thanks for reporting this issue'
53
54         click_button 'Close'
55       end
56
57       # let's search for the anonymously accessible project
58       publicly_accessible_project = api_fixture('groups')['anonymously_accessible_project']
59
60       within('.navbar-fixed-top') do
61         # search again for the anonymously accessible project
62         page.find_field('search').set publicly_accessible_project['name'][0,10]
63         page.find('.glyphicon-search').click
64       end
65
66       within '.modal-content' do
67         assert page.has_text?('All projects'), 'No text - All projects'
68         assert page.has_text?('Search'), 'No text - Search'
69         assert page.has_text?('Cancel'), 'No text - Cancel'
70         assert_selector('div', text: publicly_accessible_project['name'])
71         find(:xpath, '//div[./span[contains(.,publicly_accessible_project["uuid"])]]').click
72
73         click_button 'Show'
74       end
75
76       # seeing "Unrestricted public data" now
77       assert page.has_text?(publicly_accessible_project['name']), 'No text - publicly accessible project name'
78       assert page.has_text?(publicly_accessible_project['description']), 'No text - publicly accessible project description'
79     end
80   end
81
82   [
83     ['active', api_fixture('users')['active']],
84     ['admin', api_fixture('users')['admin']],
85   ].each do |token, user|
86
87     test "test search box for user #{token}" do
88       visit page_with_token(token)
89
90       verify_search_box user
91     end
92
93   end
94
95 end