Skip to content

Commit 9bbbb03

Browse files
committed
3955 DataTables - client - Update tests
1 parent 7416143 commit 9bbbb03

18 files changed

+287
-520
lines changed

client/src/pages/automation/datatable/components/tests/DataTableActionsMenu.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('DataTableActionsMenu', () => {
105105
expect(onExportCsv).toHaveBeenCalledTimes(1);
106106
});
107107

108-
it('should call onRenameTable when Rename table is clicked', async () => {
108+
it('should call onRenameTable when Rename Table is clicked', async () => {
109109
const user = userEvent.setup();
110110
const onRenameTable = vi.fn();
111111

client/src/pages/automation/datatable/components/tests/DataTableLeftSidebar.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useDeleteDataTableDialogStore} from '@/pages/automation/datatable/stores/useDeleteDataTableDialogStore';
1+
import {useDeleteDataTableAlertDialogStore} from '@/pages/automation/datatable/stores/useDeleteDataTableAlertDialogStore';
22
import {useRenameDataTableDialogStore} from '@/pages/automation/datatable/stores/useRenameDataTableDialogStore';
33
import {render, resetAll, screen, userEvent, windowResizeObserver} from '@/shared/util/test-utils';
44
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
@@ -114,7 +114,7 @@ afterEach(() => {
114114
queryClient.clear();
115115

116116
// Reset zustand stores
117-
useDeleteDataTableDialogStore.getState().clearTableToDelete();
117+
useDeleteDataTableAlertDialogStore.getState().clearTableToDelete();
118118
useRenameDataTableDialogStore.getState().clearTableToRename();
119119
});
120120

@@ -236,7 +236,7 @@ describe('DataTableLeftSidebar', () => {
236236

237237
await user.click(deleteOption);
238238

239-
expect(screen.getByText('Delete Table')).toBeInTheDocument();
239+
expect(screen.getByText('Are you absolutely sure?')).toBeInTheDocument();
240240
});
241241

242242
it('should close delete dialog when cancel is clicked', async () => {

client/src/pages/automation/datatable/components/tests/DataTableLeftSidebarDropdownMenu.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const hoisted = vi.hoisted(() => {
1010
};
1111
});
1212

13-
vi.mock('../../hooks/useDeleteDataTableDialog', () => ({
13+
vi.mock('../../hooks/useDeleteDataTableAlertDialog', () => ({
1414
default: () => ({
1515
handleOpen: hoisted.mockHandleDeleteOpen,
1616
}),
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import {render, resetAll, screen, userEvent, windowResizeObserver} from '@/shared/util/test-utils';
2+
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
3+
4+
import DeleteDataTableAlertDialog from '../DeleteDataTableAlertDialog';
5+
6+
const hoisted = vi.hoisted(() => {
7+
return {
8+
mockHandleClose: vi.fn(),
9+
mockHandleDelete: vi.fn(),
10+
storeState: {
11+
open: true,
12+
},
13+
};
14+
});
15+
16+
vi.mock('../../hooks/useDeleteDataTableAlertDialog', () => ({
17+
default: () => ({
18+
handleClose: hoisted.mockHandleClose,
19+
handleDelete: hoisted.mockHandleDelete,
20+
open: hoisted.storeState.open,
21+
}),
22+
}));
23+
24+
beforeEach(() => {
25+
windowResizeObserver();
26+
hoisted.storeState.open = true;
27+
});
28+
29+
afterEach(() => {
30+
resetAll();
31+
vi.clearAllMocks();
32+
});
33+
34+
describe('DeleteDataTableAlertDialog', () => {
35+
describe('rendering', () => {
36+
it('should render the dialog when open', () => {
37+
render(<DeleteDataTableAlertDialog />);
38+
39+
expect(screen.getByText('Are you absolutely sure?')).toBeInTheDocument();
40+
});
41+
42+
it('should render cancel and delete buttons', () => {
43+
render(<DeleteDataTableAlertDialog />);
44+
45+
expect(screen.getByRole('button', {name: 'Cancel'})).toBeInTheDocument();
46+
expect(screen.getByRole('button', {name: 'Delete'})).toBeInTheDocument();
47+
});
48+
49+
it('should not render when not open', () => {
50+
hoisted.storeState.open = false;
51+
52+
render(<DeleteDataTableAlertDialog />);
53+
54+
expect(screen.queryByText('Are you absolutely sure?')).not.toBeInTheDocument();
55+
});
56+
});
57+
58+
describe('interactions', () => {
59+
it('should call handleDelete when delete button is clicked', async () => {
60+
const user = userEvent.setup();
61+
62+
render(<DeleteDataTableAlertDialog />);
63+
64+
const deleteButton = screen.getByRole('button', {name: 'Delete'});
65+
66+
await user.click(deleteButton);
67+
68+
expect(hoisted.mockHandleDelete).toHaveBeenCalledTimes(1);
69+
});
70+
71+
it('should call handleClose when cancel is clicked', async () => {
72+
const user = userEvent.setup();
73+
74+
render(<DeleteDataTableAlertDialog />);
75+
76+
const cancelButton = screen.getByRole('button', {name: 'Cancel'});
77+
78+
await user.click(cancelButton);
79+
80+
expect(hoisted.mockHandleClose).toHaveBeenCalledTimes(1);
81+
});
82+
});
83+
});

client/src/pages/automation/datatable/components/tests/DeleteDataTableDialog.test.tsx

Lines changed: 0 additions & 110 deletions
This file was deleted.

client/src/pages/automation/datatable/components/tests/RenameDataTableColumnDialog.test.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const hoisted = vi.hoisted(() => {
88
mockCanRename: true,
99
mockCurrentName: 'originalColumn',
1010
mockHandleOpenChange: vi.fn(),
11-
mockHandleRename: vi.fn(),
11+
mockHandleRenameSubmit: vi.fn(),
1212
mockHandleRenameValueChange: vi.fn(),
1313
mockOpen: true,
1414
mockRenameValue: 'originalColumn',
@@ -20,7 +20,7 @@ vi.mock('../../hooks/useRenameDataTableColumnDialog', () => ({
2020
canRename: hoisted.mockCanRename,
2121
currentName: hoisted.mockCurrentName,
2222
handleOpenChange: hoisted.mockHandleOpenChange,
23-
handleRename: hoisted.mockHandleRename,
23+
handleRenameSubmit: hoisted.mockHandleRenameSubmit,
2424
handleRenameValueChange: hoisted.mockHandleRenameValueChange,
2525
open: hoisted.mockOpen,
2626
renameValue: hoisted.mockRenameValue,
@@ -62,6 +62,12 @@ describe('RenameDataTableColumnDialog', () => {
6262
expect(screen.getByText('Rename Column')).toBeInTheDocument();
6363
});
6464

65+
it('should display the dialog description', () => {
66+
render(<RenameDataTableColumnDialog />);
67+
68+
expect(screen.getByText('Enter a new name for this column.')).toBeInTheDocument();
69+
});
70+
6571
it('should render the current column name in label', () => {
6672
hoisted.mockCurrentName = 'myColumn';
6773

@@ -154,7 +160,7 @@ describe('RenameDataTableColumnDialog', () => {
154160

155161
await user.click(renameButton);
156162

157-
expect(hoisted.mockHandleRename).toHaveBeenCalled();
163+
expect(hoisted.mockHandleRenameSubmit).toHaveBeenCalled();
158164
});
159165

160166
it('should not call handleRename when Rename button is disabled', async () => {
@@ -168,7 +174,7 @@ describe('RenameDataTableColumnDialog', () => {
168174

169175
await user.click(renameButton);
170176

171-
expect(hoisted.mockHandleRename).not.toHaveBeenCalled();
177+
expect(hoisted.mockHandleRenameSubmit).not.toHaveBeenCalled();
172178
});
173179
});
174180
});

client/src/pages/automation/datatable/components/tests/RenameDataTableDialog.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import RenameDataTableDialog from '../RenameDataTableDialog';
66
const hoisted = vi.hoisted(() => {
77
return {
88
mockHandleOpenChange: vi.fn(),
9-
mockHandleRename: vi.fn(),
9+
mockHandleRenameSubmit: vi.fn(),
1010
mockHandleRenameValueChange: vi.fn(),
1111
storeState: {
1212
canRename: true,
@@ -20,7 +20,7 @@ vi.mock('../../hooks/useRenameDataTableDialog', () => ({
2020
default: () => ({
2121
canRename: hoisted.storeState.canRename,
2222
handleOpenChange: hoisted.mockHandleOpenChange,
23-
handleRename: hoisted.mockHandleRename,
23+
handleRenameSubmit: hoisted.mockHandleRenameSubmit,
2424
handleRenameValueChange: hoisted.mockHandleRenameValueChange,
2525
open: hoisted.storeState.open,
2626
renameValue: hoisted.storeState.renameValue,
@@ -94,7 +94,7 @@ describe('RenameDataTableDialog', () => {
9494

9595
await user.click(renameButton);
9696

97-
expect(hoisted.mockHandleRename).toHaveBeenCalledTimes(1);
97+
expect(hoisted.mockHandleRenameSubmit).toHaveBeenCalledTimes(1);
9898
});
9999

100100
it('should call handleOpenChange when cancel is clicked', async () => {

client/src/pages/automation/datatable/hooks/tests/useDataTableActionsMenu.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ vi.mock('../../stores/useCurrentDataTableStore', () => ({
4646
}),
4747
}));
4848

49-
vi.mock('../useDeleteDataTableDialog', () => ({
49+
vi.mock('../useDeleteDataTableAlertDialog', () => ({
5050
default: () => ({
5151
handleDelete: vi.fn(),
5252
handleOpen: hoisted.mockOpenDeleteDialog,

0 commit comments

Comments
 (0)