1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class UserProfileTest < ActionDispatch::IntegrationTest
7 headless = Headless.new
9 Capybara.current_driver = :selenium
11 @user_profile_form_fields = Rails.configuration.user_profile_form_fields
15 Rails.configuration.user_profile_form_fields = @user_profile_form_fields
18 def verify_homepage_with_profile user, invited, has_profile
19 profile_config = Rails.configuration.user_profile_form_fields
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'
28 assert page.has_text?('My projects'), 'Not found text - My projects'
29 assert page.has_no_text?('Save profile'), 'Found text - Save profile'
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'
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'
39 within('.navbar-fixed-top') do
41 assert page.has_link?('Log in'), 'Not found link - Log in'
44 assert page.has_link?("#{user['email']}"), 'Not found link - email'
45 find('a', text: "#{user['email']}").click
46 within('.dropdown-menu') do
48 assert page.has_no_link?('Not active'), 'Found link - Not active'
49 assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
51 assert page.has_link?('Manage account'), 'No link - Manage account'
54 assert page.has_link?('Manage profile'), 'No link - Manage profile'
56 assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
59 assert page.has_link?('Log out'), 'No link - Log out'
65 # Check manage profile page and add missing profile to the 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'
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'
77 # Using the default profile which has message and one required field
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'
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|
93 required_field_key = entry['key']
94 required_field_title = entry['form_field_title']
98 assert page.has_text? profile_message.gsub(/<.*?>/,'')
99 assert page.has_text?(required_field_title), 'No text - configured required field title'
101 page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
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!'
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'
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|
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
128 visit page_with_token(token)
131 verify_homepage_with_profile user, invited, has_profile
134 test "visit home page when profile not configured for user #{token}" do
135 Rails.configuration.user_profile_form_fields = false
140 visit page_with_token(token)
143 verify_homepage_with_profile user, invited, has_profile