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