Skip to content

Commit 334827c

Browse files
review
1 parent 406f91d commit 334827c

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

ui/src/components/CustomMenu/test/CustomMenu.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { vi } from 'vitest';
12
import { render, screen, waitFor } from '@testing-library/react';
23
import React from 'react';
34
import userEvent from '@testing-library/user-event';
4-
import { vi } from 'vitest';
55

66
import { getBuildDirPath } from '../../../util/script';
77
import { setUnifiedConfig } from '../../../util/util';

ui/src/components/table/tests/CustomTableCell.test.tsx

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,15 @@ const props = {
2828
handleOpenPageStyleDialog: vi.fn(),
2929
} satisfies ITableWrapperProps;
3030

31-
const mockCustomCell = () => {
31+
const mockCustomCellModule = (variant: 'valid' | 'error' | 'noRender' | 'undefined') => {
32+
const mod = {
33+
valid: MockCustomCell,
34+
error: MockCustomCellError,
35+
noRender: MockCustomCellNoRender,
36+
undefined,
37+
}[variant];
3238
vi.doMock(`${getBuildDirPath()}/custom/${CUSTOM_CELL_FILE_NAME}.js`, () => ({
33-
default: MockCustomCell,
34-
}));
35-
};
36-
37-
const mockCustomCellError = () => {
38-
vi.doMock(`${getBuildDirPath()}/custom/${CUSTOM_CELL_FILE_NAME}.js`, () => ({
39-
default: MockCustomCellError,
40-
}));
41-
};
42-
43-
const mockCustomCellWithoutRender = () => {
44-
vi.doMock(`${getBuildDirPath()}/custom/${CUSTOM_CELL_FILE_NAME}.js`, () => ({
45-
default: MockCustomCellNoRender,
46-
}));
47-
};
48-
const mockCustomCellToUndefined = () => {
49-
vi.doMock(`${getBuildDirPath()}/custom/${CUSTOM_CELL_FILE_NAME}.js`, () => ({
50-
default: undefined,
39+
default: mod,
5140
}));
5241
};
5342

@@ -94,7 +83,7 @@ test.each([
9483
{ interval: 14, expected: '14' },
9584
{ interval: 15, expected: '15' },
9685
])('Render custom cell correctly for interval $interval', async ({ interval, expected }) => {
97-
mockCustomCell();
86+
mockCustomCellModule('valid');
9887
// render only one row as mock for custom cell work just for the first time
9988
// so we need to render only one row
10089
mocksAndRenderTable(interval);
@@ -109,7 +98,7 @@ test.each([
10998
});
11099

111100
test('Render custom cell with Error message', async () => {
112-
mockCustomCellError();
101+
mockCustomCellModule('error');
113102
const mockConsoleError = vi.fn();
114103
consoleError.mockImplementation(mockConsoleError);
115104
mocksAndRenderTable(10);
@@ -130,7 +119,7 @@ test('Render custom cell with Error message', async () => {
130119
});
131120

132121
test('Error as custom cell without render method', async () => {
133-
mockCustomCellWithoutRender();
122+
mockCustomCellModule('noRender');
134123
mocksAndRenderTable();
135124

136125
const row = await waitForRow();
@@ -144,7 +133,8 @@ test('Error as custom cell without render method', async () => {
144133

145134
test('Error as custom cell file is undefined', async () => {
146135
consoleError.mockImplementation(() => {});
147-
mockCustomCellToUndefined();
136+
// mockCustomCellToUndefined();
137+
mockCustomCellModule('undefined');
148138
mocksAndRenderTable();
149139

150140
const row = await waitForRow();
@@ -157,7 +147,7 @@ test('Error as custom cell file is undefined', async () => {
157147
});
158148

159149
test('should update custom Cell Row when Input has changed', async () => {
160-
mockCustomCell();
150+
mockCustomCellModule('valid');
161151
// render only one row as mock for custom cell work just for the first time
162152
mocksAndRenderTable(11);
163153

0 commit comments

Comments
 (0)