Merge branch '4836-first-tab-load-wip'
[arvados.git] / apps / workbench / test / integration / application_layout_test.rb
1 require 'integration_helper'
2 require 'selenium-webdriver'
3 require 'headless'
4
5 class ApplicationLayoutTest < ActionDispatch::IntegrationTest
6   # These tests don't do state-changing API calls. Save some time by
7   # skipping the database reset.
8   reset_api_fixtures :after_each_test, false
9   reset_api_fixtures :after_suite, true
10
11   setup do
12     headless = Headless.new
13     headless.start
14     Capybara.current_driver = :selenium
15   end
16
17   def verify_homepage user, invited, has_profile
18     profile_config = Rails.configuration.user_profile_form_fields
19
20     if !user
21       assert page.has_text?('Please log in'), 'Not found text - Please log in'
22       assert page.has_text?('The "Log in" button below will show you a Google sign-in page'), 'Not found text - google sign in page'
23       assert page.has_no_text?('My projects'), 'Found text - My projects'
24       assert page.has_link?("Log in to #{Rails.configuration.site_name}"), 'Not found text - log in to'
25     elsif user['is_active']
26       if profile_config && !has_profile
27         assert page.has_text?('Save profile'), 'No text - Save profile'
28       else
29         assert page.has_link?("Projects"), 'Not found link - Projects'
30         page.find("#projects-menu").click
31         assert page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
32       end
33     elsif invited
34       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 . . .'
35     else
36       assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
37     end
38
39     within('.navbar-fixed-top') do
40       if !user
41         assert page.has_link?('Log in'), 'Not found link - Log in'
42       else
43         # my account menu
44         assert page.has_link?("#{user['email']}"), 'Not found link - email'
45         find('a', text: "#{user['email']}").click
46         within('.dropdown-menu') do
47           if user['is_active']
48             assert page.has_no_link?('Not active'), 'Found link - Not active'
49             assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
50
51             assert page.has_link?('Manage account'), 'No link - Manage account'
52
53             if profile_config
54               assert page.has_link?('Manage profile'), 'No link - Manage profile'
55             else
56               assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
57             end
58           else
59             assert page.has_no_link?('Manage account'), 'Found link - Manage account'
60             assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
61           end
62           assert page.has_link?('Log out'), 'No link - Log out'
63         end
64       end
65     end
66   end
67
68   # test the help menu
69   def check_help_menu
70     within('.navbar-fixed-top') do
71       page.find("#arv-help").click
72       within('.dropdown-menu') do
73         assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
74         assert page.has_link?('API Reference'), 'No link - API Reference'
75         assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
76         assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
77         assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
78         # Version info and Report a problem are tested in "report_issue_test.rb"
79       end
80     end
81   end
82
83   def verify_system_menu user
84     if user && user['is_admin']
85       assert page.has_link?('system-menu'), 'No link - system menu'
86       within('.navbar-fixed-top') do
87         page.find("#system-menu").click
88         within('.dropdown-menu') do
89           assert page.has_text?('Groups'), 'No text - Groups'
90           assert page.has_link?('Repositories'), 'No link - Repositories'
91           assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
92           assert page.has_link?('SSH keys'), 'No link - SSH keys'
93           assert page.has_link?('API tokens'), 'No link - API tokens'
94           find('a', text: 'Users').click
95         end
96       end
97       assert page.has_text? 'Add a new user'
98     else
99       assert page.has_no_link?('system-menu'), 'Found link - system menu'
100     end
101   end
102
103   [
104     [nil, nil, false, false],
105     ['inactive', api_fixture('users')['inactive'], true, false],
106     ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
107     ['active', api_fixture('users')['active'], true, true],
108     ['admin', api_fixture('users')['admin'], true, true],
109     ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
110     ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
111   ].each do |token, user, invited, has_profile|
112
113     test "visit home page for user #{token}" do
114       if !token
115         visit ('/')
116       else
117         visit page_with_token(token)
118       end
119
120       verify_homepage user, invited, has_profile
121     end
122
123     test "check help for user #{token}" do
124       if !token
125         visit ('/')
126       else
127         visit page_with_token(token)
128       end
129
130       check_help_menu
131     end
132
133     test "test system menu for user #{token}" do
134       if !token
135         visit ('/')
136       else
137         visit page_with_token(token)
138       end
139
140       verify_system_menu user
141     end
142   end
143 end