1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class UserProfileTest < ActionDispatch::IntegrationTest
6 reset_api_fixtures :after_suite
9 headless = Headless.new
11 Capybara.current_driver = :selenium
13 @user_profile_form_fields = Rails.configuration.user_profile_form_fields
17 Rails.configuration.user_profile_form_fields = @user_profile_form_fields
20 def verify_homepage_with_profile user, invited, has_profile
21 profile_config = Rails.configuration.user_profile_form_fields
24 assert page.has_text?('Please log in'), 'Not found text - Please log in'
25 elsif user['is_active']
26 if profile_config && !has_profile
27 assert page.has_text?('Save profile'), 'No text - Save profile'
30 assert page.has_text?('Active pipelines'), 'Not found text - Active pipelines'
31 assert page.has_no_text?('Save profile'), 'Found text - Save profile'
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 assert page.has_no_text?('Save profile'), 'Found text - Save profile'
37 assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
38 assert page.has_no_text?('Save profile'), 'Found text - Save profile'
41 within('.navbar-fixed-top') do
43 assert page.has_link?('Log in'), 'Not found link - Log in'
46 assert page.has_link?("#{user['email']}"), 'Not found link - email'
47 find('a', text: "#{user['email']}").click
48 within('.dropdown-menu') do
50 assert page.has_no_link?('Not active'), 'Found link - Not active'
51 assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
53 assert page.has_link?('Manage account'), 'No link - Manage account'
56 assert page.has_link?('Manage profile'), 'No link - Manage profile'
58 assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
61 assert page.has_link?('Log out'), 'No link - Log out'
67 # Check manage profile page and add missing profile to the user
69 assert page.has_no_text?('My projects'), 'Found text - My projects'
70 assert page.has_no_text?('Projects shared with me'), 'Found text - Projects shared with me'
72 assert page.has_text?('Profile'), 'No text - Profile'
73 assert page.has_text?('First name'), 'No text - First name'
74 assert page.has_text?('Last name'), 'No text - Last name'
75 assert page.has_text?('Identity URL'), 'No text - Identity URL'
76 assert page.has_text?('Email'), 'No text - Email'
77 assert page.has_text?(user['email']), 'No text - user email'
79 # Using the default profile which has message and one required field
81 # Save profile without filling in the required field. Expect to be back in this profile page again
82 click_button "Save profile"
83 assert page.has_text?('Profile'), 'No text - Profile'
84 assert page.has_text?('First name'), 'No text - First name'
85 assert page.has_text?('Last name'), 'No text - Last name'
86 assert page.has_text?('Save profile'), 'No text - Save profile'
88 # This time fill in required field and then save. Expect to go to requested page after that.
89 profile_message = Rails.configuration.user_profile_form_message
90 required_field_title = ''
91 required_field_key = ''
92 profile_config = Rails.configuration.user_profile_form_fields
93 profile_config.andand.each do |entry|
95 required_field_key = entry['key']
96 required_field_title = entry['form_field_title']
100 assert page.has_text? profile_message.gsub(/<.*?>/,'')
101 assert page.has_text?(required_field_title), 'No text - configured required field title'
103 page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
105 click_button "Save profile"
106 # profile saved and in profile page now with success
107 assert page.has_text?('Thank you for filling in your profile'), 'No text - Thank you for filling'
108 click_link 'Back to work!'
110 # profile saved and in home page now
111 assert page.has_text?('Active pipelines'), 'No text - Active pipelines'
115 [nil, nil, false, false],
116 ['inactive', api_fixture('users')['inactive'], true, false],
117 ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
118 ['active', api_fixture('users')['active'], true, true],
119 ['admin', api_fixture('users')['admin'], true, true],
120 ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
121 ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
122 ].each do |token, user, invited, has_profile|
124 test "visit home page when profile is configured for user #{token}" do
125 # Our test config enabled profile by default. So, no need to update config
129 visit page_with_token(token)
132 verify_homepage_with_profile user, invited, has_profile
135 test "visit home page when profile not configured for user #{token}" do
136 Rails.configuration.user_profile_form_fields = false
141 visit page_with_token(token)
144 verify_homepage_with_profile user, invited, has_profile