1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'integration_helper'
7 class UserProfileTest < ActionDispatch::IntegrationTest
10 @user_profile_form_fields = Rails.configuration.Workbench.UserProfileFormFields
14 Rails.configuration.Workbench.UserProfileFormFields = @user_profile_form_fields
17 def verify_homepage_with_profile user, invited, has_profile
18 profile_config = Rails.configuration.Workbench.UserProfileFormFields
21 assert_text('Please log in')
22 elsif user['is_active']
23 if !profile_config.empty? && !has_profile
24 assert_text('Save profile')
27 assert_text('Recent processes')
28 assert_no_text('Save profile')
31 assert_text('Please check the box below to indicate that you have read and accepted the user agreement')
32 assert_no_text('Save profile')
34 assert_text('Your account is inactive')
35 assert_no_text('Save profile')
38 # If the user has not already seen getting_started modal, it will be shown on first visit.
39 if user and user['is_active'] and !user['prefs']['getting_started_shown']
40 within '.modal-content' do
41 assert_text 'Getting Started'
42 assert_selector 'button', text: 'Next'
43 assert_selector 'button', text: 'Prev'
44 first('button', text: 'x').click
48 within('.navbar-fixed-top') do
50 assert page.has_link?('Log in'), 'Not found link - Log in'
53 assert_selector("#notifications-menu")
54 page.find("#notifications-menu").click
55 within('.dropdown-menu') do
57 assert_no_selector('a', text: 'Not active')
58 assert_no_selector('a', text: 'Sign agreements')
60 assert_selector('a', text: 'Virtual machines')
61 assert_selector('a', text: 'Repositories')
62 assert_selector('a', text: 'Current token')
63 assert_selector('a', text: 'SSH keys')
65 if !profile_config.empty?
66 assert_selector('a', text: 'Manage profile')
68 assert_no_selector('a', text: 'Manage profile')
71 assert_selector('a', text: 'Log out')
77 # Check manage profile page and add missing profile to the user
79 assert_no_text('My projects')
80 assert_no_text('Projects shared with me')
82 assert_text('Profile')
83 assert_text('First Name')
84 assert_text('Last Name')
85 assert_text('Identity URL')
87 assert_text(user['email'])
89 # Using the default profile which has message and one required field
91 # Save profile without filling in the required field. Expect to be back in this profile page again
92 click_button "Save profile"
93 assert_text('Profile')
94 assert_text('First Name')
95 assert_text('Last Name')
96 assert_text('Save profile')
98 # This time fill in required field and then save. Expect to go to requested page after that.
99 profile_message = Rails.configuration.Workbench.UserProfileFormMessage
100 required_field_title = ''
101 required_field_key = ''
102 profile_config = Rails.configuration.Workbench.UserProfileFormFields
103 profile_config.each do |k, entry|
105 required_field_key = k.to_s
106 required_field_title = entry['FormFieldTitle']
111 assert page.has_text? profile_message.gsub(/<.*?>/,'')
112 assert_text(required_field_title)
114 page.find_field('user[prefs][profile]['+required_field_key+']').set 'value to fill required field'
116 click_button "Save profile"
117 # profile saved and in profile page now with success
118 assert_text('Thank you for filling in your profile')
119 assert_selector('input' +
120 '[name="user[prefs][profile]['+required_field_key+']"]' +
121 '[value="value to fill required field"]')
122 if user['prefs']['getting_started_shown']
123 click_link 'Back to work!'
125 click_link 'Get started'
128 # profile saved and in home page now
129 assert_text('Recent processes')
134 ['inactive', true, false],
135 ['inactive_uninvited', false, false],
136 ['active', true, true],
137 ['admin', true, true],
138 ['active_no_prefs', true, false],
139 ['active_no_prefs_profile_no_getting_started_shown', true, false],
140 ['active_no_prefs_profile_with_getting_started_shown', true, false],
141 ].each do |token, invited, has_profile|
142 [true, false].each do |profile_required|
143 test "visit #{token} home page when profile is #{'not ' if !profile_required}configured" do
145 Rails.configuration.Workbench.UserProfileFormFields = []
147 # Our test config enabled profile by default. So, no need to update config
149 Rails.configuration.Workbench.EnableGettingStartedPopup = true
154 visit page_with_token(token)
157 user = token && api_fixture('users')[token]
158 verify_homepage_with_profile user, invited, has_profile