429e811a8c50bf7a78cd0ad7688dae4f2085951c
[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: 'Add a new project'
28         assert_no_selector 'a', text: 'Browse public projects'
29         assert page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
30       end
31     elsif invited
32       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 . . .'
33     else
34       assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
35     end
36
37     within('.navbar-fixed-top') do
38       if !user
39         assert_text Rails.configuration.site_name.downcase
40         assert_no_selector 'a', text: Rails.configuration.site_name.downcase
41         assert page.has_link?('Log in'), 'Not found link - Log in'
42       else
43         # my account menu
44         assert_selector 'a', text: Rails.configuration.site_name.downcase
45         assert(page.has_link?("notifications-menu"), 'no user menu')
46         page.find("#notifications-menu").click
47         within('.dropdown-menu') do
48           if user['is_active']
49             assert page.has_no_link?('Not active'), 'Found link - Not active'
50             assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
51
52             assert_selector "a[href=\"/projects/#{user['uuid']}\"]", text: 'Home project'
53             assert_selector "a[href=\"/users/#{user['uuid']}/virtual_machines\"]", text: 'Virtual machines'
54             assert_selector "a[href=\"/users/#{user['uuid']}/repositories\"]", text: 'Repositories'
55             assert_selector "a[href=\"/current_token\"]", text: 'Current token'
56             assert_selector "a[href=\"/users/#{user['uuid']}/ssh_keys\"]", text: 'SSH keys'
57
58             if profile_config
59               assert_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
60             else
61               assert_no_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
62             end
63           else
64             assert_no_selector 'a', text: 'Home project'
65             assert page.has_no_link?('Virtual machines'), 'Found link - Virtual machines'
66             assert page.has_no_link?('Repositories'), 'Found link - Repositories'
67             assert page.has_no_link?('Current token'), 'Found link - Current token'
68             assert page.has_no_link?('SSH keys'), 'Found link - SSH keys'
69             assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
70           end
71           assert page.has_link?('Log out'), 'No link - Log out'
72         end
73       end
74     end
75   end
76
77   # test the help menu
78   def check_help_menu
79     within('.navbar-fixed-top') do
80       page.find("#arv-help").click
81       within('.dropdown-menu') do
82         assert_selector 'a', text:'Getting Started ...'
83         assert_selector 'a', text:'Public Pipelines and Data sets'
84         assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
85         assert page.has_link?('API Reference'), 'No link - API Reference'
86         assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
87         assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
88         assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
89         # Version info and Report a problem are tested in "report_issue_test.rb"
90       end
91     end
92   end
93
94   def verify_system_menu user
95     if user && user['is_admin']
96       assert page.has_link?('system-menu'), 'No link - system menu'
97       within('.navbar-fixed-top') do
98         page.find("#system-menu").click
99         within('.dropdown-menu') do
100           assert page.has_text?('Groups'), 'No text - Groups'
101           assert page.has_link?('Repositories'), 'No link - Repositories'
102           assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
103           assert page.has_link?('SSH keys'), 'No link - SSH keys'
104           assert page.has_link?('API tokens'), 'No link - API tokens'
105           find('a', text: 'Users').click
106         end
107       end
108       assert page.has_text? 'Add a new user'
109     else
110       assert page.has_no_link?('system-menu'), 'Found link - system menu'
111     end
112   end
113
114   [
115     [nil, nil, false, false],
116     ['inactive', api_fixture('users')['inactive'], true, false],
117     ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
118     ['active', api_fixture('users')['active'], true, true],
119     ['admin', api_fixture('users')['admin'], true, true],
120     ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
121     ['active_no_prefs_profile_no_getting_started_shown',
122         api_fixture('users')['active_no_prefs_profile_no_getting_started_shown'], true, false],
123   ].each do |token, user, invited, has_profile|
124
125     test "visit home page for user #{token}" do
126       if !token
127         visit ('/')
128       else
129         visit page_with_token(token)
130       end
131
132       verify_homepage user, invited, has_profile
133     end
134
135     test "check help for user #{token}" do
136       if !token
137         visit ('/')
138       else
139         visit page_with_token(token)
140       end
141
142       check_help_menu
143     end
144
145     test "test system menu for user #{token}" do
146       if !token
147         visit ('/')
148       else
149         visit page_with_token(token)
150       end
151
152       verify_system_menu user
153     end
154   end
155
156   test "test getting started help menu item" do
157     visit page_with_token('active')
158     within '.navbar-fixed-top' do
159       find('.help-menu > a').click
160       find('.help-menu .dropdown-menu a', text: 'Getting Started ...').click
161     end
162
163     within '.modal-content' do
164       assert_text 'Getting Started'
165       assert_selector 'button:not([disabled])', text: 'Next'
166       assert_no_selector 'button:not([disabled])', text: 'Prev'
167
168       # Use Next button to enable Prev button
169       click_button 'Next'
170       assert_selector 'button:not([disabled])', text: 'Prev'  # Prev button is now enabled
171       click_button 'Prev'
172       assert_no_selector 'button:not([disabled])', text: 'Prev'  # Prev button is again disabled
173
174       # Click Next until last page is reached and verify that it is disabled
175       (0..20).each do |i|   # currently we only have 4 pages, and don't expect to have more than 20 in future
176         click_button 'Next'
177         begin
178           find('button:not([disabled])', text: 'Next')
179         rescue => e
180           break
181         end
182       end
183       assert_no_selector 'button:not([disabled])', text: 'Next'  # Next button is disabled
184       assert_selector 'button:not([disabled])', text: 'Prev'     # Prev button is enabled
185       click_button 'Prev'
186       assert_selector 'button:not([disabled])', text: 'Next'     # Next button is now enabled
187
188       first('button', text: 'x').click
189     end
190     assert_text 'Active pipelines' # seeing dashboard now
191   end
192
193   test "test arvados_public_data_doc_url config unset" do
194     Rails.configuration.arvados_public_data_doc_url = false
195
196     visit page_with_token('active')
197     within '.navbar-fixed-top' do
198       find('.help-menu > a').click
199
200       assert_no_selector 'a', text:'Public Pipelines and Data sets'
201
202       assert_selector 'a', text:'Getting Started ...'
203       assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
204       assert page.has_link?('API Reference'), 'No link - API Reference'
205       assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
206       assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
207       assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
208     end
209   end
210
211   test "no SSH public key notification when shell_in_a_box_url is configured" do
212     Rails.configuration.shell_in_a_box_url = 'example.com'
213     visit page_with_token('job_reader')
214     click_link 'notifications-menu'
215     assert_no_selector 'a', text:'Click here to set up an SSH public key for use with Arvados.'
216     assert_selector 'a', text:'Click here to learn how to run an Arvados Crunch pipeline'
217   end
218
219    [
220     ['Repositories',nil,'s0uqq'],
221     ['Virtual machines','virtual machine','current_user_logins'],
222     ['SSH keys',nil,'public_key'],
223     ['Links','link','link_class'],
224     ['Groups','group','group_class'],
225     ['Compute nodes','node','info[ping_secret'],
226     ['Keep services','keep service','service_ssl_flag'],
227     ['Keep disks', 'keep disk','bytes_free'],
228   ].each do |page_name, add_button_text, look_for|
229     test "test system menu #{page_name} link" do
230       visit page_with_token('admin')
231       within('.navbar-fixed-top') do
232         page.find("#system-menu").click
233         within('.dropdown-menu') do
234           assert_selector 'a', text: page_name
235           find('a', text: page_name).click
236         end
237       end
238
239       # click the add button if it exists
240       if add_button_text
241         assert_selector 'button', text: "Add a new #{add_button_text}"
242         find('button', text: "Add a new #{add_button_text}").click
243       end
244
245       # look for unique property in the current page
246       assert page.has_text? look_for
247     end
248   end
249 end