@@ -75,22 +75,36 @@ def create_and_generate_report_for_user(report_name, user)
7575 expect ( helper . visibility_options ( widget ) ) . to eq ( 'To All Users' )
7676 end
7777
78- it 'converts role IDs to role names for display ' do
78+ it 'converts role IDs to role names and sorts alphabetically by name ' do
7979 widget = FactoryBot . create ( :miq_widget , :visibility => { :roles => [ role1 . id , role2 . id ] } )
8080 result = helper . visibility_options ( widget )
81- expect ( result ) . to include ( 'EvmRole-auditor' )
82- expect ( result ) . to include ( 'EvmRole-desktop' )
83- expect ( result ) . to include ( 'By Roles:' )
81+ expect ( result ) . to eq ( 'By Roles: EvmRole-auditor, EvmRole-desktop' )
8482 end
8583
86- it 'converts group IDs to group descriptions for display' do
84+ it 'sorts role names alphabetically regardless of ID order' do
85+ role3 = FactoryBot . create ( :miq_user_role , :name => 'EvmRole-zebra' )
86+ role4 = FactoryBot . create ( :miq_user_role , :name => 'EvmRole-alpha' )
87+ widget = FactoryBot . create ( :miq_widget , :visibility => { :roles => [ role3 . id , role4 . id ] } )
88+ result = helper . visibility_options ( widget )
89+ # IDs are in order [zebra, alpha] but output should be alphabetically sorted
90+ expect ( result ) . to eq ( 'By Roles: EvmRole-alpha, EvmRole-zebra' )
91+ end
92+
93+ it 'converts group IDs to group descriptions and sorts alphabetically by description' do
8794 group1 = FactoryBot . create ( :miq_group , :description => 'Group1' )
8895 group2 = FactoryBot . create ( :miq_group , :description => 'Group2' )
8996 widget = FactoryBot . create ( :miq_widget , :visibility => { :groups => [ group1 . id , group2 . id ] } )
9097 result = helper . visibility_options ( widget )
91- expect ( result ) . to include ( 'Group1' )
92- expect ( result ) . to include ( 'Group2' )
93- expect ( result ) . to include ( 'By Groups:' )
98+ expect ( result ) . to eq ( 'By Groups: Group1, Group2' )
99+ end
100+
101+ it 'sorts group descriptions alphabetically regardless of ID order' do
102+ group3 = FactoryBot . create ( :miq_group , :description => 'Zebra Group' )
103+ group4 = FactoryBot . create ( :miq_group , :description => 'Alpha Group' )
104+ widget = FactoryBot . create ( :miq_widget , :visibility => { :groups => [ group3 . id , group4 . id ] } )
105+ result = helper . visibility_options ( widget )
106+ # IDs are in order [Zebra, Alpha] but output should be alphabetically sorted
107+ expect ( result ) . to eq ( 'By Groups: Alpha Group, Zebra Group' )
94108 end
95109 end
96110end
0 commit comments