Fix Canceled -> Cancelled (american vs canadian spelling, canada wins)
[arvados.git] / apps / workbench / test / integration / user_profile_test.rb
1 require 'integration_helper'
2 require 'selenium-webdriver'
3 require 'headless'
4
5 class UserProfileTest < ActionDispatch::IntegrationTest
6   setup do
7     headless = Headless.new
8     headless.start
9     Capybara.current_driver = :selenium
10
11     @user_profile_form_fields = Rails.configuration.user_profile_form_fields
12   end
13
14   teardown do
15     Rails.configuration.user_profile_form_fields = @user_profile_form_fields
16   end
17
18   def verify_homepage_with_profile user, invited, has_profile
19     profile_config = Rails.configuration.user_profile_form_fields
20
21     if !user
22       assert page.has_text?('Please log in'), 'Not found text - Please log in'
23     elsif user['is_active']
24       if profile_config && !has_profile
25         assert page.has_text?('Save profile'), 'No text - Save profile'
26         add_profile user
27       else
28         assert page.has_text?('My projects'), 'Not found text - My projects'
29         assert page.has_no_text?('Save profile'), 'Found text - Save profile'
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       assert page.has_no_text?('Save profile'), 'Found text - Save profile'
34     else
35       assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
36       assert page.has_no_text?('Save profile'), 'Found text - Save profile'
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           end
59           assert page.has_link?('Log out'), 'No link - Log out'
60         end
61       end
62     end
63   end
64
65   # Check manage profile page and add missing profile to the user
66   def add_profile user
67     assert page.has_no_text?('My projects'), 'Found text - My projects'
68     assert page.has_no_text?('Projects shared with me'), 'Found text - Projects shared with me'
69
70     assert page.has_text?('Profile'), 'No text - Profile'
71     assert page.has_text?('First name'), 'No text - First name'
72     assert page.has_text?('Last name'), 'No text - Last name'
73     assert page.has_text?('Identity URL'), 'No text - Identity URL'
74     assert page.has_text?('Email'), 'No text - Email'
75     assert page.has_text?(user['email']), 'No text - user email'
76
77     # Using the default profile which has message and one required field
78
79     # Save profile without filling in the required field. Expect to be back in this profile page again
80     click_button "Save profile"
81     assert page.has_text?('Profile'), 'No text - Profile'
82     assert page.has_text?('First name'), 'No text - First name'
83     assert page.has_text?('Last name'), 'No text - Last name'
84     assert page.has_text?('Save profile'), 'No text - Save profile'
85
86     # This time fill in required field and then save. Expect to go to requested page after that.
87     profile_message = Rails.configuration.user_profile_form_message
88     required_field_title = ''
89     required_field_key = ''
90     profile_config = Rails.configuration.user_profile_form_fields
91     profile_config.andand.each do |entry|
92       if entry['required']
93         required_field_key = entry['key']
94         required_field_title = entry['form_field_title']
95       end
96     end
97
98     assert page.has_text? profile_message.gsub(/<.*?>/,'')
99     assert page.has_text?(required_field_title), 'No text - configured required field title'
100
101     page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
102
103     click_button "Save profile"
104     # profile saved and in profile page now with success
105     assert page.has_text?('Thank you for filling in your profile'), 'No text - Thank you for filling'
106     click_link 'Back to work!'
107
108     # profile saved and in home page now
109     assert page.has_text?('My projects'), 'No text - My projects'
110     assert page.has_text?('Projects shared with me'), 'No text - Projects shared with me'
111   end
112
113   [
114     [nil, nil, false, false],
115     ['inactive', api_fixture('users')['inactive'], true, false],
116     ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
117     ['active', api_fixture('users')['active'], true, true],
118     ['admin', api_fixture('users')['admin'], true, true],
119     ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
120     ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
121   ].each do |token, user, invited, has_profile|
122
123     test "visit home page when profile is configured for user #{token}" do
124       # Our test config enabled profile by default. So, no need to update config
125       if !token
126         visit ('/')
127       else
128         visit page_with_token(token)
129       end
130
131       verify_homepage_with_profile user, invited, has_profile
132     end
133
134     test "visit home page when profile not configured for user #{token}" do
135       Rails.configuration.user_profile_form_fields = false
136
137       if !token
138         visit ('/')
139       else
140         visit page_with_token(token)
141       end
142
143       verify_homepage_with_profile user, invited, has_profile
144     end
145
146   end
147
148 end