Skip to content

Commit

Permalink
fix(Release): add unit tests for overview tab and snapshot details view
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil143 committed Nov 27, 2024
1 parent c91faa2 commit 3608e4e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion codecv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ coverage:
project:
default:
target: auto
threshold: 0.2%
threshold: 1%
patch:
default:
informational: true
Expand Down
11 changes: 8 additions & 3 deletions src/components/Releases/__tests__/ReleaseOverviewTab.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ jest.mock('../../../hooks/useReleases', () => ({
const watchResourceMock = createK8sWatchResourceMock();

describe('ReleaseOverviewTab', () => {
beforeEach(() => {
watchResourceMock.mockReturnValue([{ spec: { application: 'test-app' } }, true]);
});
beforeEach(() => {});

createUseWorkspaceInfoMock({ namespace: 'test-ns', workspace: 'test-ws' });

it('should render loading indicator', () => {
watchResourceMock.mockReturnValue([{ spec: { application: 'test-app' } }, false]);
render(<ReleaseOverviewTab />);
expect(screen.getByRole('progressbar')).toBeVisible();
});

it('should render correct details', () => {
watchResourceMock.mockReturnValue([{ spec: { application: 'test-app' } }, true]);
render(<ReleaseOverviewTab />);
expect(screen.getByText('Duration')).toBeVisible();
expect(screen.getByText('10 seconds')).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ describe('SnapshotDetailsView', () => {
(useCommitStatus as jest.Mock).mockReturnValueOnce(['-', true]);
});

it('should render loading indicator', () => {
watchResourceMock.mockReturnValue([[], false]);
renderWithQueryClientAndRouter(<SnapshotDetails />);
screen.getByRole('progressbar');
});

it('should show error state if test cannot be loaded', () => {
watchResourceMock.mockReturnValue([
[],
Expand Down
26 changes: 26 additions & 0 deletions src/hooks/__tests__/useApplicationReleases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ const watchResourceMock = createK8sWatchResourceMock();
const useSnapshotsMock = useApplicationSnapshots as jest.Mock;

describe('useApplicationReleases', () => {
it('should return empty array incase release are not loaded', () => {
watchResourceMock.mockReturnValue([[], false]);
useSnapshotsMock.mockReturnValue([
[{ metadata: { name: 'my-snapshot' } }, { metadata: { name: 'my-snapshot-2' } }],
true,
]);

const { result } = renderHook(() => useApplicationReleases('test-app'));
const [results, loaded] = result.current;
expect(loaded).toEqual(false);
expect(results.length).toEqual(0);
});

it('should return empty array incase snapshots are not loaded', () => {
watchResourceMock.mockReturnValue([[], true]);
useSnapshotsMock.mockReturnValue([
[{ metadata: { name: 'my-snapshot' } }, { metadata: { name: 'my-snapshot-2' } }],
false,
]);

const { result } = renderHook(() => useApplicationReleases('test-app'));
const [results, loaded] = result.current;
expect(loaded).toEqual(false);
expect(results.length).toEqual(0);
});

it('should only return releases that are in the application', () => {
watchResourceMock.mockReturnValue([
[
Expand Down

0 comments on commit 3608e4e

Please sign in to comment.