Skip to content

Commit 56462be

Browse files
committed
fix(Release): add unit tests for overview tab and snapshot details view
1 parent c91faa2 commit 56462be

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/components/Releases/__tests__/ReleaseOverviewTab.spec.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ jest.mock('../../../hooks/useReleases', () => ({
1919
const watchResourceMock = createK8sWatchResourceMock();
2020

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

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

26+
it('should render loading indicator', () => {
27+
watchResourceMock.mockReturnValue([{ spec: { application: 'test-app' } }, false]);
28+
render(<ReleaseOverviewTab />);
29+
expect(screen.getByRole('progressbar')).toBeVisible();
30+
});
31+
2832
it('should render correct details', () => {
33+
watchResourceMock.mockReturnValue([{ spec: { application: 'test-app' } }, true]);
2934
render(<ReleaseOverviewTab />);
3035
expect(screen.getByText('Duration')).toBeVisible();
3136
expect(screen.getByText('10 seconds')).toBeVisible();

src/components/SnapshotDetails/__tests__/SnapshotDetailsView.spec.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ describe('SnapshotDetailsView', () => {
6767
(useCommitStatus as jest.Mock).mockReturnValueOnce(['-', true]);
6868
});
6969

70+
it('should render loading indicator', () => {
71+
watchResourceMock.mockReturnValue([[], false]);
72+
renderWithQueryClientAndRouter(<SnapshotDetails />);
73+
screen.getByRole('progressbar');
74+
});
75+
7076
it('should show error state if test cannot be loaded', () => {
7177
watchResourceMock.mockReturnValue([
7278
[],

src/hooks/__tests__/useApplicationReleases.spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@ const watchResourceMock = createK8sWatchResourceMock();
1515
const useSnapshotsMock = useApplicationSnapshots as jest.Mock;
1616

1717
describe('useApplicationReleases', () => {
18+
it('should return empty array incase release are not loaded', () => {
19+
watchResourceMock.mockReturnValue([[], false]);
20+
useSnapshotsMock.mockReturnValue([
21+
[{ metadata: { name: 'my-snapshot' } }, { metadata: { name: 'my-snapshot-2' } }],
22+
true,
23+
]);
24+
25+
const { result } = renderHook(() => useApplicationReleases('test-app'));
26+
const [results, loaded] = result.current;
27+
expect(loaded).toEqual(false);
28+
expect(results.length).toEqual(0);
29+
});
30+
31+
it('should return empty array incase snapshots are not loaded', () => {
32+
watchResourceMock.mockReturnValue([[], true]);
33+
useSnapshotsMock.mockReturnValue([
34+
[{ metadata: { name: 'my-snapshot' } }, { metadata: { name: 'my-snapshot-2' } }],
35+
false,
36+
]);
37+
38+
const { result } = renderHook(() => useApplicationReleases('test-app'));
39+
const [results, loaded] = result.current;
40+
expect(loaded).toEqual(false);
41+
expect(results.length).toEqual(0);
42+
});
43+
1844
it('should only return releases that are in the application', () => {
1945
watchResourceMock.mockReturnValue([
2046
[

0 commit comments

Comments
 (0)