b85977f213099cd6427fad00dc5eff5335c42dee
[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 page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
28       end
29     elsif invited
30       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 . . .'
31     else
32       assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
33     end
34
35     within('.navbar-fixed-top') do
36       if !user
37         assert_text Rails.configuration.site_name.downcase
38         assert_no_selector 'a', text: Rails.configuration.site_name.downcase
39         assert page.has_link?('Log in'), 'Not found link - Log in'
40       else
41         # my account menu
42         assert_selector 'a', text: Rails.configuration.site_name.downcase
43         assert page.has_link?("#{user['email']}"), 'Not found link - email'
44         find('a', text: "#{user['email']}").click
45         within('.dropdown-menu') do
46           if user['is_active']
47             assert page.has_no_link?('Not active'), 'Found link - Not active'
48             assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
49
50             assert page.has_link?('Manage account'), 'No link - Manage account'
51
52             if profile_config
53               assert page.has_link?('Manage profile'), 'No link - Manage profile'
54             else
55               assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
56             end
57           else
58             assert page.has_no_link?('Manage account'), 'Found link - Manage account'
59             assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
60           end
61           assert page.has_link?('Log out'), 'No link - Log out'
62         end
63       end
64     end
65   end
66
67   # test the help menu
68   def check_help_menu
69     within('.navbar-fixed-top') do
70       page.find("#arv-help").click
71       within('.dropdown-menu') do
72         assert_selector 'a', text:'Getting Started ...'
73         assert_selector 'a', text:'Public Pipelines and Data sets'
74         assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
75         assert page.has_link?('API Reference'), 'No link - API Reference'
76         assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
77         assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
78         assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
79         # Version info and Report a problem are tested in "report_issue_test.rb"
80       end
81     end
82   end
83
84   def verify_system_menu user
85     if user && user['is_admin']
86       assert page.has_link?('system-menu'), 'No link - system menu'
87       within('.navbar-fixed-top') do
88         page.find("#system-menu").click
89         within('.dropdown-menu') do
90           assert page.has_text?('Groups'), 'No text - Groups'
91           assert page.has_link?('Repositories'), 'No link - Repositories'
92           assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
93           assert page.has_link?('SSH keys'), 'No link - SSH keys'
94           assert page.has_link?('API tokens'), 'No link - API tokens'
95           find('a', text: 'Users').click
96         end
97       end
98       assert page.has_text? 'Add a new user'
99     else
100       assert page.has_no_link?('system-menu'), 'Found link - system menu'
101     end
102   end
103
104   [
105     [nil, nil, false, false],
106     ['inactive', api_fixture('users')['inactive'], true, false],
107     ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
108     ['active', api_fixture('users')['active'], true, true],
109     ['admin', api_fixture('users')['admin'], true, true],
110     ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
111     ['active_no_prefs_profile_no_getting_started_shown',
112         api_fixture('users')['active_no_prefs_profile_no_getting_started_shown'], true, false],
113     ['active_no_prefs_profile_with_getting_started_shown',
114         api_fixture('users')['active_no_prefs_profile_with_getting_started_shown'], true, false],
115   ].each do |token, user, invited, has_profile|
116
117     test "visit home page for user #{token}" do
118       if !token
119         visit ('/')
120       else
121         visit page_with_token(token)
122       end
123
124       verify_homepage user, invited, has_profile
125     end
126
127     test "check help for user #{token}" do
128       if !token
129         visit ('/')
130       else
131         visit page_with_token(token)
132       end
133
134       check_help_menu
135     end
136
137     test "test system menu for user #{token}" do
138       if !token
139         visit ('/')
140       else
141         visit page_with_token(token)
142       end
143
144       verify_system_menu user
145     end
146   end
147
148   test "test getting started help menu item" do
149     visit page_with_token('active')
150     within '.navbar-fixed-top' do
151       find('.help-menu > a').click
152       find('.help-menu .dropdown-menu a', text: 'Getting Started ...').click
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       click_button 'Next'
160       assert_selector 'button:not([disabled])', text: 'Prev'  # Prev button is now enabled
161       click_button 'Prev'
162       assert_no_selector 'button:not([disabled])', text: 'Prev'  # Prev button is again disabled
163       first('button', text: 'x').click
164     end
165     assert_text 'Active pipelines' # seeing dashboard now
166   end
167
168   test "test arvados_public_data_doc_url config unset" do
169     Rails.configuration.arvados_public_data_doc_url = false
170
171     visit page_with_token('active')
172     within '.navbar-fixed-top' do
173       find('.help-menu > a').click
174
175       assert_no_selector 'a', text:'Public Pipelines and Data sets'
176
177       assert_selector 'a', text:'Getting Started ...'
178       assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
179       assert page.has_link?('API Reference'), 'No link - API Reference'
180       assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
181       assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
182       assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
183     end
184   end
185 end