Skip to content

Commit

Permalink
fix(components): add unit test for useAllComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil143 committed Mar 6, 2024
1 parent 7c69142 commit a58d847
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/hooks/__tests__/useComponents.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useK8sWatchResource } from '@openshift/dynamic-plugin-sdk-utils';
import { renderHook } from '@testing-library/react-hooks';
import { mockComponentsData } from '../../components/ApplicationDetails/__data__/WorkflowComponentsData';
import { useComponents } from '../useComponents';
import { useAllComponents, useComponents } from '../useComponents';

jest.mock('@openshift/dynamic-plugin-sdk-utils', () => ({
useK8sWatchResource: jest.fn(() => [[], true]),
Expand Down Expand Up @@ -32,3 +32,29 @@ describe('useComponents', () => {
expect(components).toHaveLength(3);
});
});

describe('useAllComponents', () => {
it('should return empty array when call is inflight', () => {
useK8sWatchResourceMock.mockReturnValue([[], false, undefined]);
const { result } = renderHook(() => useAllComponents('test-ns'));
expect(result.current).toEqual([[], false, undefined]);
});

it('should return all components in a namespace', () => {
useK8sWatchResourceMock.mockReturnValue([mockComponentsData, true, undefined]);
const { result } = renderHook(() => useAllComponents('test-ns'));
const [components] = result.current;
expect(components).toHaveLength(3);
});

it('should filter out deleted componets', () => {
useK8sWatchResourceMock.mockReturnValue([
[...mockComponentsData, { metadata: { name: 'sdfs', deletionTimestamp: 'sad-wqe' } }],
true,
undefined,
]);
const { result } = renderHook(() => useAllComponents('test-ns'));
const [components] = result.current;
expect(components).toHaveLength(3);
});
});

0 comments on commit a58d847

Please sign in to comment.