Skip to content

Commit 5e1ffb3

Browse files
committed
feat: add tests
1 parent 2e52f74 commit 5e1ffb3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

projects/wc/src/app/components/organization-management/organization-management.component.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)