closes #6587
[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 page.has_link?('Manage account'), 'No link - Manage account'
54
55             if profile_config
56               assert page.has_link?('Manage profile'), 'No link - Manage profile'
57             else
58               assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
59             end
60           else
61             assert_no_selector 'a', text: 'Home project'
62             assert page.has_no_link?('Manage account'), 'Found link - Manage account'
63             assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
64           end
65           assert page.has_link?('Log out'), 'No link - Log out'
66         end
67       end
68     end
69   end
70
71   # test the help menu
72   def check_help_menu
73     within('.navbar-fixed-top') do
74       page.find("#arv-help").click
75       within('.dropdown-menu') do
76         assert_selector 'a', text:'Getting Started ...'
77         assert_selector 'a', text:'Public Pipelines and Data sets'
78         assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
79         assert page.has_link?('API Reference'), 'No link - API Reference'
80         assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
81         assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
82         assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
83         # Version info and Report a problem are tested in "report_issue_test.rb"
84       end
85     end
86   end
87
88   def verify_system_menu user
89     if user && user['is_admin']
90       assert page.has_link?('system-menu'), 'No link - system menu'
91       within('.navbar-fixed-top') do
92         page.find("#system-menu").click
93         within('.dropdown-menu') do
94           assert page.has_text?('Groups'), 'No text - Groups'
95           assert page.has_link?('Repositories'), 'No link - Repositories'
96           assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
97           assert page.has_link?('SSH keys'), 'No link - SSH keys'
98           assert page.has_link?('API tokens'), 'No link - API tokens'
99           find('a', text: 'Users').click
100         end
101       end
102       assert page.has_text? 'Add a new user'
103     else
104       assert page.has_no_link?('system-menu'), 'Found link - system menu'
105     end
106   end
107
108   [
109     [nil, nil, false, false],
110     ['inactive', api_fixture('users')['inactive'], true, false],
111     ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
112     ['active', api_fixture('users')['active'], true, true],
113     ['admin', api_fixture('users')['admin'], true, true],
114     ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
115     ['active_no_prefs_profile_no_getting_started_shown',
116         api_fixture('users')['active_no_prefs_profile_no_getting_started_shown'], true, false],
117   ].each do |token, user, invited, has_profile|
118
119     test "visit home page for user #{token}" do
120       if !token
121         visit ('/')
122       else
123         visit page_with_token(token)
124       end
125
126       verify_homepage user, invited, has_profile
127     end
128
129     test "check help for user #{token}" do
130       if !token
131         visit ('/')
132       else
133         visit page_with_token(token)
134       end
135
136       check_help_menu
137     end
138
139     test "test system menu for user #{token}" do
140       if !token
141         visit ('/')
142       else
143         visit page_with_token(token)
144       end
145
146       verify_system_menu user
147     end
148   end
149
150   test "test getting started help menu item" do
151     visit page_with_token('active')
152     within '.navbar-fixed-top' do
153       find('.help-menu > a').click
154       find('.help-menu .dropdown-menu a', text: 'Getting Started ...').click
155     end
156
157     within '.modal-content' do
158       assert_text 'Getting Started'
159       assert_selector 'button:not([disabled])', text: 'Next'
160       assert_no_selector 'button:not([disabled])', text: 'Prev'
161
162       # Use Next button to enable Prev button
163       click_button 'Next'
164       assert_selector 'button:not([disabled])', text: 'Prev'  # Prev button is now enabled
165       click_button 'Prev'
166       assert_no_selector 'button:not([disabled])', text: 'Prev'  # Prev button is again disabled
167
168       # Click Next until last page is reached and verify that it is disabled
169       (0..20).each do |i|   # currently we only have 4 pages, and don't expect to have more than 20 in future
170         click_button 'Next'
171         begin
172           find('button:not([disabled])', text: 'Next')
173         rescue => e
174           break
175         end
176       end
177       assert_no_selector 'button:not([disabled])', text: 'Next'  # Next button is disabled
178       assert_selector 'button:not([disabled])', text: 'Prev'     # Prev button is enabled
179       click_button 'Prev'
180       assert_selector 'button:not([disabled])', text: 'Next'     # Next button is now enabled
181
182       first('button', text: 'x').click
183     end
184     assert_text 'Active pipelines' # seeing dashboard now
185   end
186
187   test "test arvados_public_data_doc_url config unset" do
188     Rails.configuration.arvados_public_data_doc_url = false
189
190     visit page_with_token('active')
191     within '.navbar-fixed-top' do
192       find('.help-menu > a').click
193
194       assert_no_selector 'a', text:'Public Pipelines and Data sets'
195
196       assert_selector 'a', text:'Getting Started ...'
197       assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
198       assert page.has_link?('API Reference'), 'No link - API Reference'
199       assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
200       assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
201       assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
202     end
203   end
204
205   test "no SSH public key notification when shell_in_a_box_url is configured" do
206     Rails.configuration.shell_in_a_box_url = 'example.com'
207     visit page_with_token('job_reader')
208     click_link 'notifications-menu'
209     assert_no_selector 'a', text:'Click here to set up an SSH public key for use with Arvados.'
210     assert_selector 'a', text:'Click here to learn how to run an Arvados Crunch pipeline'
211   end
212 end