@@ -296,4 +296,51 @@ describe('OrganizationManagementComponent', () => {
296296 const result = component . getValueState ( formControl ) ;
297297 expect ( result ) . toBe ( 'None' ) ;
298298 } ) ;
299+
300+ it ( 'should handle error when reading organizations' , ( ) => {
301+ const consoleSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ) ;
302+ const mockError = new Error ( 'Failed to fetch organizations' ) ;
303+
304+ resourceServiceMock . list . mockReturnValue ( throwError ( ( ) => mockError ) ) ;
305+
306+ component . readOrganizations ( ) ;
307+
308+ expect ( consoleSpy ) . toHaveBeenCalledWith (
309+ 'Error reading organizations' ,
310+ mockError ,
311+ ) ;
312+
313+ consoleSpy . mockRestore ( ) ;
314+ } ) ;
315+
316+ it ( 'should update existing organizationToSwitch when reading organizations' , ( ) => {
317+ const mockOrganizations = [
318+ {
319+ metadata : { name : 'org1' } ,
320+ status : { conditions : [ { type : 'Ready' , status : 'True' } ] } ,
321+ } ,
322+ {
323+ metadata : { name : 'org2' } ,
324+ status : { conditions : [ { type : 'Ready' , status : 'True' } ] } ,
325+ } ,
326+ ] ;
327+
328+ // Set an existing organization to switch
329+ component . organizationToSwitch . set ( { name : 'org2' , ready : false } ) ;
330+
331+ resourceServiceMock . list . mockReturnValue ( of ( mockOrganizations as any ) ) ;
332+
333+ component . readOrganizations ( ) ;
334+
335+ expect ( resourceServiceMock . list ) . toHaveBeenCalled ( ) ;
336+ expect ( component . organizations ( ) ) . toEqual ( [
337+ { name : 'org1' , ready : true } ,
338+ { name : 'org2' , ready : true } ,
339+ ] ) ;
340+ // Should find and update the existing organizationToSwitch
341+ expect ( component . organizationToSwitch ( ) ) . toEqual ( {
342+ name : 'org2' ,
343+ ready : true ,
344+ } ) ;
345+ } ) ;
299346} ) ;
0 commit comments