2021-04-18 13:34:55 +02:00
# frozen_string_literal: true
2023-02-26 11:00:48 +01:00
require File . expand_path '../../test_helper' , __FILE__
2019-12-30 16:09:04 +01:00
class AutoCompletesControllerTest < Additionals :: ControllerTest
fixtures :projects , :email_addresses ,
:enumerations , :users , :groups_users ,
:roles ,
:members , :member_roles ,
:enabled_modules
2022-01-30 14:21:43 +01:00
def setup
prepare_tests
Setting . default_language = 'en'
end
2019-12-30 16:09:04 +01:00
def test_fontawesome_default
get :fontawesome
assert_response :success
2021-04-18 13:34:55 +02:00
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2019-12-30 16:09:04 +01:00
assert_kind_of Array , json
icon = json . first
2022-10-30 17:08:52 +01:00
2019-12-30 16:09:04 +01:00
assert_kind_of Hash , icon
assert_equal 'far_address-book' , icon [ 'id' ]
assert_equal 'Address Book' , icon [ 'text' ]
end
def test_fontawesome_search
get :fontawesome ,
params : { q : 'sun' }
assert_response :success
2021-04-18 13:34:55 +02:00
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2019-12-30 16:09:04 +01:00
assert_kind_of Array , json
assert_equal 5 , json . count
icon = json . first
2022-10-30 17:08:52 +01:00
2019-12-30 16:09:04 +01:00
assert_kind_of Hash , icon
assert_equal 'fas_cloud-sun' , icon [ 'id' ]
assert_equal 'Cloud with Sun' , icon [ 'text' ]
end
def test_fontawesome_search_without_result
get :fontawesome ,
params : { q : 'doesnotexist' }
assert_response :success
2021-04-18 13:34:55 +02:00
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2019-12-30 16:09:04 +01:00
assert_kind_of Array , json
assert_equal 0 , json . count
end
2022-01-30 14:21:43 +01:00
def test_issue_assignee
with_settings issue_group_assignment : '0' do
2023-11-22 17:49:46 +01:00
get :issue_assignee , xhr : true
2022-01-30 14:21:43 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_kind_of Array , json
assert_equal 2 , json . count
assert_equal 'me' , json . first [ 'id' ]
assert_equal 'active' , json . second [ 'text' ]
assert_equal 4 , json . second [ 'children' ] . count
end
end
def test_assignee
2023-11-22 17:49:46 +01:00
get :assignee , xhr : true
2022-01-30 14:21:43 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_kind_of Array , json
assert_equal 3 , json . count
assert_equal 'me' , json . first [ 'id' ]
assert_equal 'active' , json . second [ 'text' ]
assert_equal 7 , json . second [ 'children' ] . count
assert_equal 'Groups' , json . third [ 'text' ]
assert_equal 2 , json . third [ 'children' ] . count
end
def test_grouped_principals
2023-11-22 17:49:46 +01:00
get :grouped_principals , xhr : true
2022-01-30 14:21:43 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_kind_of Array , json
2022-01-30 15:30:58 +01:00
assert_equal 2 , json . count
2022-01-30 14:21:43 +01:00
2022-01-30 15:30:58 +01:00
assert_equal 'active' , json . first [ 'text' ]
assert_equal 7 , json . first [ 'children' ] . count
assert_equal 'Groups' , json . second [ 'text' ]
assert_equal 2 , json . second [ 'children' ] . count
2022-01-30 14:21:43 +01:00
end
2022-02-01 20:07:35 +01:00
def test_grouped_principals_with_me
get :grouped_principals ,
2023-11-22 17:49:46 +01:00
params : { with_me : true } ,
xhr : true
2022-02-01 20:07:35 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-02-01 20:07:35 +01:00
assert_kind_of Array , json
assert_equal 3 , json . count
assert_equal 'me' , json . first [ 'id' ]
assert_equal 'active' , json . second [ 'text' ]
assert_equal 7 , json . second [ 'children' ] . count
assert_equal 'Groups' , json . third [ 'text' ]
assert_equal 2 , json . third [ 'children' ] . count
end
2022-01-30 14:21:43 +01:00
def test_grouped_users
2023-11-22 17:49:46 +01:00
get :grouped_users , xhr : true
2022-01-30 14:21:43 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_kind_of Array , json
2022-01-30 15:30:58 +01:00
assert_equal 1 , json . count
2022-01-30 14:21:43 +01:00
2022-01-30 15:30:58 +01:00
assert_equal 'active' , json . first [ 'text' ]
assert_equal 7 , json . first [ 'children' ] . count
2022-01-30 14:21:43 +01:00
end
2022-01-30 16:01:06 +01:00
def test_grouped_users_with_me
get :grouped_users ,
2023-11-22 17:49:46 +01:00
params : { with_me : true } ,
xhr : true
2022-01-30 16:01:06 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 16:01:06 +01:00
assert_kind_of Array , json
assert_equal 2 , json . count
assert_equal 'me' , json . first [ 'id' ]
assert_equal 'active' , json . second [ 'text' ]
assert_equal 7 , json . second [ 'children' ] . count
end
2022-02-01 17:56:30 +01:00
def test_grouped_users_with_ano
2022-01-30 14:21:43 +01:00
get :grouped_users ,
2023-11-22 17:49:46 +01:00
params : { with_ano : true } ,
xhr : true
2022-01-30 14:21:43 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_kind_of Array , json
2022-02-01 17:56:30 +01:00
assert_equal 2 , json . count
2022-01-30 14:21:43 +01:00
2022-01-30 15:30:58 +01:00
assert_equal 'active' , json . first [ 'text' ]
2022-02-01 17:56:30 +01:00
assert_equal 7 , json . first [ 'children' ] . count
assert_equal 'Anonymous' , json . second [ 'text' ]
2022-01-30 14:21:43 +01:00
end
2022-02-01 17:56:30 +01:00
def test_grouped_users_for_project
2022-01-30 14:21:43 +01:00
get :grouped_users ,
2023-11-22 17:49:46 +01:00
params : { project_id : 1 } ,
xhr : true
2022-01-30 14:21:43 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_kind_of Array , json
2022-01-30 15:30:58 +01:00
assert_equal 1 , json . count
2022-01-30 14:21:43 +01:00
2022-01-30 15:30:58 +01:00
assert_equal 'active' , json . first [ 'text' ]
2022-02-01 17:56:30 +01:00
assert_equal 2 , json . first [ 'children' ] . count
2022-01-30 14:21:43 +01:00
end
2022-02-01 17:56:30 +01:00
def test_grouped_users_with_excluded_user
get :grouped_users ,
2023-11-22 17:49:46 +01:00
params : { user_id : 2 } ,
xhr : true
2022-01-30 14:21:43 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_kind_of Array , json
2022-01-30 15:30:58 +01:00
assert_equal 1 , json . count
2022-01-30 14:21:43 +01:00
2022-01-30 15:30:58 +01:00
assert_equal 'active' , json . first [ 'text' ]
2022-02-01 17:56:30 +01:00
assert_equal 6 , json . first [ 'children' ] . count
assert_not ( json . first [ 'children' ] . detect { | u | u [ 'id' ] == 2 } )
2022-01-30 14:21:43 +01:00
end
2022-02-01 17:56:30 +01:00
def test_grouped_users_with_search
get :grouped_users ,
2023-11-22 17:49:46 +01:00
params : { q : 'john' } ,
xhr : true
2022-01-30 14:21:43 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_kind_of Array , json
assert_equal 1 , json . count
children = json . first [ 'children' ]
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_equal 1 , children . count
entry = children . first
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_equal 2 , entry [ 'id' ]
assert_equal 'John Smith' , entry [ 'text' ]
assert_equal 'John Smith' , entry [ 'name' ]
assert_equal 2 , entry [ 'value' ]
end
2022-02-01 17:56:30 +01:00
def test_grouped_users_scope
Role . anonymous . update! users_visibility : 'members_of_visible_projects'
@request . session [ :user_id ] = nil
2023-11-22 17:49:46 +01:00
get :grouped_users , xhr : true
2022-01-30 14:21:43 +01:00
assert_response :success
json = ActiveSupport :: JSON . decode response . body
2022-10-30 17:08:52 +01:00
2022-01-30 14:21:43 +01:00
assert_kind_of Array , json
assert_equal 1 , json . count
2022-02-01 17:56:30 +01:00
assert_equal 'active' , json . first [ 'text' ]
assert_equal 2 , json . first [ 'children' ] . count
2022-01-30 14:21:43 +01:00
end
2019-12-30 16:09:04 +01:00
end