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