Skip to content

Commit 0568216

Browse files
committed
refactor(CodeEditor): update Panel tests to use default context functions
- Removed the use of mockPanelFunctions in Panel tests, replacing them with defaultPanelContextFunctions for improved clarity and consistency. - Updated test cases to directly utilize context configuration for undo and redo actions, enhancing maintainability and readability of the tests.
1 parent 2e0a15f commit 0568216

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

packages/code-editor/src/Panel/Panel.spec.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22

33
import '@testing-library/jest-dom';
44

5-
import { mockPanelFunctions, renderPanel } from '../testing/panelTestUtils';
5+
import { renderPanel } from '../testing/panelTestUtils';
66

77
import { PanelProps } from './Panel.types';
88

@@ -30,7 +30,6 @@ Object.assign(document, {
3030
describe('Panel', () => {
3131
beforeEach(() => {
3232
jest.clearAllMocks();
33-
mockPanelFunctions.clearAll();
3433
});
3534

3635
describe('Basic Rendering', () => {
@@ -203,21 +202,23 @@ describe('Panel', () => {
203202
test('calls context undo function when undo menu item is clicked', async () => {
204203
const { panel } = renderPanel({
205204
panelProps: { ...defaultProps, showSecondaryMenuButton: true },
205+
contextConfig: { undo: mockUndo },
206206
});
207207

208208
await panel.interactions.clickUndoMenuItem();
209209

210-
expect(mockPanelFunctions.undo).toHaveBeenCalledTimes(1);
210+
expect(mockUndo).toHaveBeenCalledTimes(1);
211211
});
212212

213213
test('calls context redo function when redo menu item is clicked', async () => {
214214
const { panel } = renderPanel({
215215
panelProps: { ...defaultProps, showSecondaryMenuButton: true },
216+
contextConfig: { redo: mockRedo },
216217
});
217218

218219
await panel.interactions.clickRedoMenuItem();
219220

220-
expect(mockPanelFunctions.redo).toHaveBeenCalledTimes(1);
221+
expect(mockRedo).toHaveBeenCalledTimes(1);
221222
});
222223

223224
test('handles when undo function is not available', async () => {

packages/code-editor/src/testing/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { codeSnippets } from './codeSnippets';
22
import {
3-
mockPanelFunctions,
3+
defaultPanelContextFunctions,
44
PanelSelectors,
55
renderPanel,
66
} from './panelTestUtils';
77
import { renderCodeEditor } from './testUtils';
88

99
export {
1010
codeSnippets,
11-
mockPanelFunctions,
11+
defaultPanelContextFunctions,
1212
PanelSelectors,
1313
renderCodeEditor,
1414
renderPanel,

0 commit comments

Comments
 (0)