1 require 'integration_helper'
3 class UserProfileTest < ActionDispatch::IntegrationTest
6 @user_profile_form_fields = Rails.configuration.user_profile_form_fields
10 Rails.configuration.user_profile_form_fields = @user_profile_form_fields
13 def verify_homepage_with_profile user, invited, has_profile
14 profile_config = Rails.configuration.user_profile_form_fields
17 assert_text('Please log in')
18 elsif user['is_active']
19 if profile_config && !has_profile
20 assert_text('Save profile')
23 assert_text('Recent pipelines and processes')
24 assert_no_text('Save profile')
27 assert_text('Please check the box below to indicate that you have read and accepted the user agreement')
28 assert_no_text('Save profile')
30 assert_text('Your account is inactive')
31 assert_no_text('Save profile')
34 # If the user has not already seen getting_started modal, it will be shown on first visit.
35 if user and user['is_active'] and !user['prefs']['getting_started_shown']
36 within '.modal-content' do
37 assert_text 'Getting Started'
38 assert_selector 'button', text: 'Next'
39 assert_selector 'button', text: 'Prev'
40 first('button', text: 'x').click
44 within('.navbar-fixed-top') do
46 assert page.has_link?('Log in'), 'Not found link - Log in'
49 assert_selector("#notifications-menu")
50 page.find("#notifications-menu").click
51 within('.dropdown-menu') do
53 assert_no_selector('a', text: 'Not active')
54 assert_no_selector('a', text: 'Sign agreements')
56 assert_selector('a', text: 'Virtual machines')
57 assert_selector('a', text: 'Repositories')
58 assert_selector('a', text: 'Current token')
59 assert_selector('a', text: 'SSH keys')
62 assert_selector('a', text: 'Manage profile')
64 assert_no_selector('a', text: 'Manage profile')
67 assert_selector('a', text: 'Log out')
73 # Check manage profile page and add missing profile to the user
75 assert_no_text('My projects')
76 assert_no_text('Projects shared with me')
78 assert_text('Profile')
79 assert_text('First Name')
80 assert_text('Last Name')
81 assert_text('Identity URL')
83 assert_text(user['email'])
85 # Using the default profile which has message and one required field
87 # Save profile without filling in the required field. Expect to be back in this profile page again
88 click_button "Save profile"
89 assert_text('Profile')
90 assert_text('First Name')
91 assert_text('Last Name')
92 assert_text('Save profile')
94 # This time fill in required field and then save. Expect to go to requested page after that.
95 profile_message = Rails.configuration.user_profile_form_message
96 required_field_title = ''
97 required_field_key = ''
98 profile_config = Rails.configuration.user_profile_form_fields
99 profile_config.each do |entry|
101 required_field_key = entry['key']
102 required_field_title = entry['form_field_title']
107 assert page.has_text? profile_message.gsub(/<.*?>/,'')
108 assert_text(required_field_title)
110 page.find_field('user[prefs][profile]['+required_field_key+']').set 'value to fill required field'
112 click_button "Save profile"
113 # profile saved and in profile page now with success
114 assert_text('Thank you for filling in your profile')
115 assert_selector('input' +
116 '[name="user[prefs][profile]['+required_field_key+']"]' +
117 '[value="value to fill required field"]')
118 if user['prefs']['getting_started_shown']
119 click_link 'Back to work!'
121 click_link 'Get started'
124 # profile saved and in home page now
125 assert_text('Recent pipelines and processes')
130 ['inactive', true, false],
131 ['inactive_uninvited', false, false],
132 ['active', true, true],
133 ['admin', true, true],
134 ['active_no_prefs', true, false],
135 ['active_no_prefs_profile_no_getting_started_shown', true, false],
136 ['active_no_prefs_profile_with_getting_started_shown', true, false],
137 ].each do |token, invited, has_profile|
138 [true, false].each do |profile_required|
139 test "visit #{token} home page when profile is #{'not ' if !profile_required}configured" do
141 Rails.configuration.user_profile_form_fields = false
143 # Our test config enabled profile by default. So, no need to update config
145 Rails.configuration.enable_getting_started_popup = true
150 visit page_with_token(token)
153 user = token && api_fixture('users')[token]
154 verify_homepage_with_profile user, invited, has_profile