@@ -91,15 +91,15 @@ describe('agentActivation', () => {
9191 } ) ;
9292
9393 describe ( 'getAgentChoices' , ( ) => {
94- it ( 'should enable agent when ANY version is available for activation' , ( ) => {
94+ it ( 'should filter out agent when any version is already active ( for activation) ' , ( ) => {
9595 const agents : BotMetadata [ ] = [
9696 {
9797 Id : 'agent1' ,
9898 DeveloperName : 'Test_Agent' ,
9999 BotVersions : {
100100 records : [
101101 { Status : 'Active' , VersionNumber : 1 } as BotVersionMetadata ,
102- { Status : 'Inactive' , VersionNumber : 2 } as BotVersionMetadata , // Can be activated
102+ { Status : 'Inactive' , VersionNumber : 2 } as BotVersionMetadata ,
103103 { Status : 'Inactive' , VersionNumber : 3 } as BotVersionMetadata ,
104104 ] ,
105105 } ,
@@ -108,12 +108,10 @@ describe('agentActivation', () => {
108108
109109 const choices = getAgentChoices ( agents , 'Active' ) ;
110110
111- expect ( choices ) . to . have . lengthOf ( 1 ) ;
112- expect ( choices [ 0 ] . disabled ) . to . equal ( false ) ; // Has inactive versions that can be activated
113- expect ( choices [ 0 ] . value . DeveloperName ) . to . equal ( 'Test_Agent' ) ;
111+ expect ( choices ) . to . have . lengthOf ( 0 ) ; // Filtered out because it already has an active version
114112 } ) ;
115113
116- it ( 'should enable agent when ANY version is available for deactivation' , ( ) => {
114+ it ( 'should include agent when it has an active version ( for deactivation) ' , ( ) => {
117115 const agents : BotMetadata [ ] = [
118116 {
119117 Id : 'agent1' ,
@@ -131,31 +129,31 @@ describe('agentActivation', () => {
131129 const choices = getAgentChoices ( agents , 'Inactive' ) ;
132130
133131 expect ( choices ) . to . have . lengthOf ( 1 ) ;
134- expect ( choices [ 0 ] . disabled ) . to . equal ( false ) ; // Has active version that can be deactivated
132+ expect ( choices [ 0 ] . value . DeveloperName ) . to . equal ( 'Test_Agent' ) ;
135133 } ) ;
136134
137- it ( 'should disable agent when ALL versions are already in target state ' , ( ) => {
135+ it ( 'should include agent when all versions are inactive (for activation) ' , ( ) => {
138136 const agents : BotMetadata [ ] = [
139137 {
140138 Id : 'agent1' ,
141139 DeveloperName : 'Test_Agent' ,
142140 BotVersions : {
143141 records : [
144- { Status : 'Active ' , VersionNumber : 1 } as BotVersionMetadata ,
145- { Status : 'Active ' , VersionNumber : 2 } as BotVersionMetadata ,
146- { Status : 'Active ' , VersionNumber : 3 } as BotVersionMetadata ,
142+ { Status : 'Inactive ' , VersionNumber : 1 } as BotVersionMetadata ,
143+ { Status : 'Inactive ' , VersionNumber : 2 } as BotVersionMetadata ,
144+ { Status : 'Inactive ' , VersionNumber : 3 } as BotVersionMetadata ,
147145 ] ,
148146 } ,
149147 } as BotMetadata ,
150148 ] ;
151149
152150 const choices = getAgentChoices ( agents , 'Active' ) ;
153151
154- expect ( choices ) . to . have . lengthOf ( 1 ) ;
155- expect ( choices [ 0 ] . disabled ) . to . equal ( '(Already Active) ' ) ; // All versions are already active
152+ expect ( choices ) . to . have . lengthOf ( 1 ) ; // All versions are inactive, so can activate one
153+ expect ( choices [ 0 ] . value . DeveloperName ) . to . equal ( 'Test_Agent ' ) ;
156154 } ) ;
157155
158- it ( 'should disable agent when ALL versions are inactive for deactivation' , ( ) => {
156+ it ( 'should filter out agent when all versions are inactive ( for deactivation) ' , ( ) => {
159157 const agents : BotMetadata [ ] = [
160158 {
161159 Id : 'agent1' ,
@@ -171,11 +169,10 @@ describe('agentActivation', () => {
171169
172170 const choices = getAgentChoices ( agents , 'Inactive' ) ;
173171
174- expect ( choices ) . to . have . lengthOf ( 1 ) ;
175- expect ( choices [ 0 ] . disabled ) . to . equal ( '(Already Inactive)' ) ; // All versions are already inactive
172+ expect ( choices ) . to . have . lengthOf ( 0 ) ; // All versions are already inactive, nothing to deactivate
176173 } ) ;
177174
178- it ( 'should disable unsupported agents' , ( ) => {
175+ it ( 'should filter out unsupported agents' , ( ) => {
179176 const agents : BotMetadata [ ] = [
180177 {
181178 Id : 'agent1' ,
@@ -188,41 +185,86 @@ describe('agentActivation', () => {
188185
189186 const choices = getAgentChoices ( agents , 'Active' ) ;
190187
191- expect ( choices ) . to . have . lengthOf ( 1 ) ;
192- expect ( choices [ 0 ] . disabled ) . to . equal ( '(Not Supported)' ) ;
188+ expect ( choices ) . to . have . lengthOf ( 0 ) ; // Unsupported agents are filtered out
193189 } ) ;
194190
195- it ( 'should handle multiple agents with mixed states ' , ( ) => {
191+ it ( 'should filter out unavailable agents and sort remaining alphabetically ' , ( ) => {
196192 const agents : BotMetadata [ ] = [
197193 {
198194 Id : 'agent1' ,
199- DeveloperName : 'Agent_All_Active ' ,
195+ DeveloperName : 'Zebra_Agent ' ,
200196 BotVersions : {
201197 records : [
202198 { Status : 'Active' , VersionNumber : 1 } as BotVersionMetadata ,
203- { Status : 'Active ' , VersionNumber : 2 } as BotVersionMetadata ,
199+ { Status : 'Inactive ' , VersionNumber : 2 } as BotVersionMetadata ,
204200 ] ,
205201 } ,
206202 } as BotMetadata ,
207203 {
208204 Id : 'agent2' ,
209- DeveloperName : 'Agent_Mixed ' ,
205+ DeveloperName : 'Beta_Agent ' ,
210206 BotVersions : {
211207 records : [
212208 { Status : 'Active' , VersionNumber : 1 } as BotVersionMetadata ,
213209 { Status : 'Inactive' , VersionNumber : 2 } as BotVersionMetadata ,
214210 ] ,
215211 } ,
216212 } as BotMetadata ,
213+ {
214+ Id : 'agent3' ,
215+ DeveloperName : 'Alpha_Agent' ,
216+ BotVersions : {
217+ records : [
218+ { Status : 'Inactive' , VersionNumber : 1 } as BotVersionMetadata ,
219+ { Status : 'Inactive' , VersionNumber : 2 } as BotVersionMetadata ,
220+ ] ,
221+ } ,
222+ } as BotMetadata ,
217223 ] ;
218224
219225 const choices = getAgentChoices ( agents , 'Active' ) ;
220226
221- expect ( choices ) . to . have . lengthOf ( 2 ) ;
222- expect ( choices [ 0 ] . value . DeveloperName ) . to . equal ( 'Agent_All_Active' ) ;
223- expect ( choices [ 0 ] . disabled ) . to . equal ( '(Already Active)' ) ;
224- expect ( choices [ 1 ] . value . DeveloperName ) . to . equal ( 'Agent_Mixed' ) ;
225- expect ( choices [ 1 ] . disabled ) . to . equal ( false ) ;
227+ expect ( choices ) . to . have . lengthOf ( 1 ) ; // Only Alpha_Agent has no active version (all inactive)
228+ expect ( choices [ 0 ] . value . DeveloperName ) . to . equal ( 'Alpha_Agent' ) ;
229+ } ) ;
230+
231+ it ( 'should sort multiple available agents alphabetically' , ( ) => {
232+ const agents : BotMetadata [ ] = [
233+ {
234+ Id : 'agent1' ,
235+ DeveloperName : 'Zebra_Agent' ,
236+ BotVersions : {
237+ records : [
238+ { Status : 'Inactive' , VersionNumber : 1 } as BotVersionMetadata ,
239+ { Status : 'Inactive' , VersionNumber : 2 } as BotVersionMetadata ,
240+ ] ,
241+ } ,
242+ } as BotMetadata ,
243+ {
244+ Id : 'agent2' ,
245+ DeveloperName : 'Alpha_Agent' ,
246+ BotVersions : {
247+ records : [
248+ { Status : 'Inactive' , VersionNumber : 1 } as BotVersionMetadata ,
249+ { Status : 'Inactive' , VersionNumber : 2 } as BotVersionMetadata ,
250+ ] ,
251+ } ,
252+ } as BotMetadata ,
253+ {
254+ Id : 'agent3' ,
255+ DeveloperName : 'Beta_Agent' ,
256+ BotVersions : {
257+ records : [ { Status : 'Inactive' , VersionNumber : 1 } as BotVersionMetadata ] ,
258+ } ,
259+ } as BotMetadata ,
260+ ] ;
261+
262+ const choices = getAgentChoices ( agents , 'Active' ) ;
263+
264+ expect ( choices ) . to . have . lengthOf ( 3 ) ;
265+ expect ( choices [ 0 ] . value . DeveloperName ) . to . equal ( 'Alpha_Agent' ) ;
266+ expect ( choices [ 1 ] . value . DeveloperName ) . to . equal ( 'Beta_Agent' ) ;
267+ expect ( choices [ 2 ] . value . DeveloperName ) . to . equal ( 'Zebra_Agent' ) ;
226268 } ) ;
227269 } ) ;
228270} ) ;
0 commit comments