Add 'apps/arv-web/' from commit 'f9732ad8460d013c2f28363655d0d1b91894dca5'
[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 page.has_link?('Log in'), 'Not found link - Log in'
38       else
39         # my account menu
40         assert page.has_link?("#{user['email']}"), 'Not found link - email'
41         find('a', text: "#{user['email']}").click
42         within('.dropdown-menu') do
43           if user['is_active']
44             assert page.has_no_link?('Not active'), 'Found link - Not active'
45             assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
46
47             assert page.has_link?('Manage account'), 'No link - Manage account'
48
49             if profile_config
50               assert page.has_link?('Manage profile'), 'No link - Manage profile'
51             else
52               assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
53             end
54           else
55             assert page.has_no_link?('Manage account'), 'Found link - Manage account'
56             assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
57           end
58           assert page.has_link?('Log out'), 'No link - Log out'
59         end
60       end
61     end
62   end
63
64   # test the help menu
65   def check_help_menu
66     within('.navbar-fixed-top') do
67       page.find("#arv-help").click
68       within('.dropdown-menu') do
69         assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
70         assert page.has_link?('API Reference'), 'No link - API Reference'
71         assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
72         assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
73         assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
74         # Version info and Report a problem are tested in "report_issue_test.rb"
75       end
76     end
77   end
78
79   def verify_system_menu user
80     if user && user['is_admin']
81       assert page.has_link?('system-menu'), 'No link - system menu'
82       within('.navbar-fixed-top') do
83         page.find("#system-menu").click
84         within('.dropdown-menu') do
85           assert page.has_text?('Groups'), 'No text - Groups'
86           assert page.has_link?('Repositories'), 'No link - Repositories'
87           assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
88           assert page.has_link?('SSH keys'), 'No link - SSH keys'
89           assert page.has_link?('API tokens'), 'No link - API tokens'
90           find('a', text: 'Users').click
91         end
92       end
93       assert page.has_text? 'Add a new user'
94     else
95       assert page.has_no_link?('system-menu'), 'Found link - system menu'
96     end
97   end
98
99   [
100     [nil, nil, false, false],
101     ['inactive', api_fixture('users')['inactive'], true, false],
102     ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
103     ['active', api_fixture('users')['active'], true, true],
104     ['admin', api_fixture('users')['admin'], true, true],
105     ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
106     ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
107   ].each do |token, user, invited, has_profile|
108
109     test "visit home page for user #{token}" do
110       if !token
111         visit ('/')
112       else
113         visit page_with_token(token)
114       end
115
116       verify_homepage user, invited, has_profile
117     end
118
119     test "check help for user #{token}" do
120       if !token
121         visit ('/')
122       else
123         visit page_with_token(token)
124       end
125
126       check_help_menu
127     end
128
129     test "test system menu for user #{token}" do
130       if !token
131         visit ('/')
132       else
133         visit page_with_token(token)
134       end
135
136       verify_system_menu user
137     end
138   end
139 end