8784: Fix test for latest firefox.
[arvados.git] / apps / workbench / test / integration / application_layout_test.rb
1 require 'integration_helper'
2
3 class ApplicationLayoutTest < ActionDispatch::IntegrationTest
4   # These tests don't do state-changing API calls. Save some time by
5   # skipping the database reset.
6   reset_api_fixtures :after_each_test, false
7   reset_api_fixtures :after_suite, true
8
9   setup do
10     need_javascript
11   end
12
13   def verify_homepage user, invited, has_profile
14     profile_config = Rails.configuration.user_profile_form_fields
15
16     if !user
17       assert page.has_text?('Please log in'), 'Not found text - Please log in'
18       assert page.has_text?('The "Log in" button below will show you a Google sign-in page'), 'Not found text - google sign in page'
19       assert page.has_no_text?('My projects'), 'Found text - My projects'
20       assert page.has_link?("Log in to #{Rails.configuration.site_name}"), 'Not found text - log in to'
21     elsif user['is_active']
22       if profile_config && !has_profile
23         assert page.has_text?('Save profile'), 'No text - Save profile'
24       else
25         assert page.has_link?("Projects"), 'Not found link - Projects'
26         page.find("#projects-menu").click
27         assert_selector 'a', text: 'Search all projects'
28         assert_no_selector 'a', text: 'Browse public projects'
29         assert_selector 'a', text: 'Add a new project'
30         assert_selector 'li[class="dropdown-header"]', text: 'My projects'
31       end
32     elsif invited
33       assert page.has_text?('Please check the box below to indicate that you have read and accepted the user agreement'), 'Not found text - Please check the box below . . .'
34     else
35       assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
36     end
37
38     within('.navbar-fixed-top') do
39       if !user
40         assert_text Rails.configuration.site_name.downcase
41         assert_no_selector 'a', text: Rails.configuration.site_name.downcase
42         assert page.has_link?('Log in'), 'Not found link - Log in'
43       else
44         # my account menu
45         assert_selector 'a', text: Rails.configuration.site_name.downcase
46         assert(page.has_link?("notifications-menu"), 'no user menu')
47         page.find("#notifications-menu").click
48         within('.dropdown-menu') do
49           if user['is_active']
50             assert page.has_no_link?('Not active'), 'Found link - Not active'
51             assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
52
53             assert_selector "a[href=\"/projects/#{user['uuid']}\"]", text: 'Home project'
54             assert_selector "a[href=\"/users/#{user['uuid']}/virtual_machines\"]", text: 'Virtual machines'
55             assert_selector "a[href=\"/users/#{user['uuid']}/repositories\"]", text: 'Repositories'
56             assert_selector "a[href=\"/current_token\"]", text: 'Current token'
57             assert_selector "a[href=\"/users/#{user['uuid']}/ssh_keys\"]", text: 'SSH keys'
58
59             if profile_config
60               assert_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
61             else
62               assert_no_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
63             end
64           else
65             assert_no_selector 'a', text: 'Home project'
66             assert page.has_no_link?('Virtual machines'), 'Found link - Virtual machines'
67             assert page.has_no_link?('Repositories'), 'Found link - Repositories'
68             assert page.has_no_link?('Current token'), 'Found link - Current token'
69             assert page.has_no_link?('SSH keys'), 'Found link - SSH keys'
70             assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
71           end
72           assert page.has_link?('Log out'), 'No link - Log out'
73         end
74       end
75     end
76   end
77
78   # test the help menu
79   def check_help_menu
80     within('.navbar-fixed-top') do
81       page.find("#arv-help").click
82       within('.dropdown-menu') do
83         assert_no_selector 'a', text:'Getting Started ...'
84         assert_selector 'a', text:'Public Pipelines and Data sets'
85         assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
86         assert page.has_link?('API Reference'), 'No link - API Reference'
87         assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
88         assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
89         assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
90         # Version info and Report a problem are tested in "report_issue_test.rb"
91       end
92     end
93   end
94
95   def verify_system_menu user
96     if user && user['is_admin']
97       assert page.has_link?('system-menu'), 'No link - system menu'
98       within('.navbar-fixed-top') do
99         page.find("#system-menu").click
100         within('.dropdown-menu') do
101           assert page.has_text?('Groups'), 'No text - Groups'
102           assert page.has_link?('Repositories'), 'No link - Repositories'
103           assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
104           assert page.has_link?('SSH keys'), 'No link - SSH keys'
105           assert page.has_link?('API tokens'), 'No link - API tokens'
106           find('a', text: 'Users').click
107         end
108       end
109       assert page.has_text? 'Add a new user'
110     else
111       assert page.has_no_link?('system-menu'), 'Found link - system menu'
112     end
113   end
114
115   [
116     [nil, nil, false, false],
117     ['inactive', api_fixture('users')['inactive'], true, false],
118     ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
119     ['active', api_fixture('users')['active'], true, true],
120     ['admin', api_fixture('users')['admin'], true, true],
121     ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
122     ['active_no_prefs_profile_no_getting_started_shown',
123         api_fixture('users')['active_no_prefs_profile_no_getting_started_shown'], true, false],
124   ].each do |token, user, invited, has_profile|
125
126     test "visit home page for user #{token}" do
127       if !token
128         visit ('/')
129       else
130         visit page_with_token(token)
131       end
132
133       check_help_menu
134       verify_homepage user, invited, has_profile
135       verify_system_menu user
136     end
137   end
138
139   [
140     ['active', true],
141     ['active_with_prefs_profile_no_getting_started_shown', false],
142   ].each do |token, getting_started_shown|
143     test "getting started help menu item #{getting_started_shown}" do
144       Rails.configuration.enable_getting_started_popup = true
145
146       visit page_with_token(token)
147
148       if getting_started_shown
149         within '.navbar-fixed-top' do
150           find('.help-menu > a').click
151           find('.help-menu .dropdown-menu a', text: 'Getting Started ...').click
152         end
153       end
154
155       within '.modal-content' do
156         assert_text 'Getting Started'
157         assert_selector 'button:not([disabled])', text: 'Next'
158         assert_no_selector 'button:not([disabled])', text: 'Prev'
159
160         # Use Next button to enable Prev button
161         click_button 'Next'
162         assert_selector 'button:not([disabled])', text: 'Prev'  # Prev button is now enabled
163         click_button 'Prev'
164         assert_no_selector 'button:not([disabled])', text: 'Prev'  # Prev button is again disabled
165
166         # Click Next until last page is reached and verify that it is disabled
167         (0..20).each do |i|   # currently we only have 4 pages, and don't expect to have more than 20 in future
168           click_button 'Next'
169           begin
170             find('button:not([disabled])', text: 'Next')
171           rescue => e
172             break
173           end
174         end
175         assert_no_selector 'button:not([disabled])', text: 'Next'  # Next button is disabled
176         assert_selector 'button:not([disabled])', text: 'Prev'     # Prev button is enabled
177         click_button 'Prev'
178         assert_selector 'button:not([disabled])', text: 'Next'     # Next button is now enabled
179
180         first('button', text: 'x').click
181       end
182       assert_text 'Recent pipelines and processes' # seeing dashboard now
183     end
184   end
185
186   test "test arvados_public_data_doc_url config unset" do
187     Rails.configuration.arvados_public_data_doc_url = false
188
189     visit page_with_token('active')
190     within '.navbar-fixed-top' do
191       find('.help-menu > a').click
192
193       assert_no_selector 'a', text:'Public Pipelines and Data sets'
194       assert_no_selector 'a', text:'Getting Started ...'
195
196       assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
197       assert page.has_link?('API Reference'), 'No link - API Reference'
198       assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
199       assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
200       assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
201     end
202   end
203
204   test "no SSH public key notification when shell_in_a_box_url is configured" do
205     Rails.configuration.shell_in_a_box_url = 'example.com'
206     visit page_with_token('job_reader')
207     click_link 'notifications-menu'
208     assert_no_selector 'a', text:'Click here to set up an SSH public key for use with Arvados.'
209     assert_selector 'a', text:'Click here to learn how to run an Arvados Crunch pipeline'
210   end
211
212    [
213     ['Repositories', nil, 's0uqq'],
214     ['Virtual machines', nil, 'testvm.shell'],
215     ['SSH keys', nil, 'public_key'],
216     ['Links', nil, 'link_class'],
217     ['Groups', nil, 'All users'],
218     ['Compute nodes', nil, 'ping_secret'],
219     ['Keep services', nil, 'service_ssl_flag'],
220     ['Keep disks', nil, 'bytes_free'],
221   ].each do |page_name, add_button_text, look_for|
222     test "test system menu #{page_name} link" do
223       visit page_with_token('admin')
224       within('.navbar-fixed-top') do
225         page.find("#system-menu").click
226         within('.dropdown-menu') do
227           assert_selector 'a', text: page_name
228           find('a', text: page_name).click
229         end
230       end
231
232       # click the add button if it exists
233       if add_button_text
234         assert_selector 'button', text: "Add a new #{add_button_text}"
235         find('button', text: "Add a new #{add_button_text}").click
236       else
237         assert_no_selector 'button', text:"Add a new"
238       end
239
240       # look for unique property in the current page
241       assert_text look_for
242     end
243   end
244
245   [
246     ['active', false],
247     ['admin', true],
248   ].each do |token, is_admin|
249     test "visit dashboard as #{token}" do
250       visit page_with_token(token)
251
252       assert_text 'Recent pipelines and processes' # seeing dashboard now
253       within('.recent-processes-actions') do
254         assert page.has_link?('Run a process')
255         assert page.has_link?('All processes')
256       end
257
258       within('.recent-processes') do
259         assert_text 'running'
260
261         within('.row-zzzzz-xvhdp-cr4runningcntnr') do
262           assert_text 'requester_for_running_cr'
263         end
264
265         assert_text 'zzzzz-d1hrv-twodonepipeline'
266         within('.row-zzzzz-d1hrv-twodonepipeline')do
267           assert_text 'No output'
268         end
269
270         assert_text 'completed container request'
271         within('.row-zzzzz-xvhdp-cr4completedctr')do
272           assert page.has_link? 'foo_file'
273         end
274       end
275
276       within('.compute-node-actions') do
277         if is_admin
278           assert page.has_link?('All nodes')
279         else
280           assert page.has_no_link?('All nodes')
281         end
282       end
283
284       within('.compute-node-summary-pane') do
285         click_link 'Details'
286         assert_text 'compute0'
287       end
288     end
289   end
290 end