Skip to content

Commit 62fc97c

Browse files
committed
fix: update unit tests for WidgetPlugin changes
- Add moduleNameMapper in jest.config.cjs to resolve React 18 from the plugin's local node_modules, fixing dual-React-instance errors - Mock usePersistentState in @deephaven/plugin mock to avoid FiberProvider dependency in tests - Update DocumentHandler test to reflect new behavior where non-layout children are rendered directly without ReactPanel wrapping
1 parent aa7c200 commit 62fc97c

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// Mock @deephaven/plugin package
2+
const React = require('react');
23
const PluginActual = jest.requireActual('@deephaven/plugin');
34

45
module.exports = {
56
...PluginActual,
67
useDashboardPlugins: jest.fn(() => []),
8+
// Mock usePersistentState to behave like useState.
9+
// The real implementation requires FiberProvider which is internal to Dashboard.
10+
usePersistentState: (initialState, _config) => React.useState(initialState),
711
__esModule: true,
812
};

plugins/ui/src/js/jest.config.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
const path = require('path');
12
const baseConfig = require('../../../../jest.config.base.cjs');
23
const packageJson = require('./package');
34

45
module.exports = {
56
...baseConfig,
67
displayName: packageJson.name,
8+
moduleNameMapper: {
9+
...baseConfig.moduleNameMapper,
10+
// Force all react imports to the local React 18 to avoid dual-instance issues
11+
// with the root workspace's React 17.
12+
'^react$': path.resolve(__dirname, 'node_modules/react'),
13+
'^react/(.*)$': path.resolve(__dirname, 'node_modules/react/$1'),
14+
'^react-dom$': path.resolve(__dirname, 'node_modules/react-dom'),
15+
'^react-dom/(.*)$': path.resolve(__dirname, 'node_modules/react-dom/$1'),
16+
},
717
};

plugins/ui/src/js/src/widget/DocumentHandler.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ it('should throw an error if the document mixes panel and non-panel elements', (
7272
);
7373
});
7474

75-
it('should combine multiple single elements into one panel', () => {
75+
it('should render multiple single elements directly without wrapping in a panel', () => {
7676
const children = makeDocument([makeElement('foo'), makeElement('bar')]);
7777
render(makeDocumentHandler({ children }));
78-
expect(mockReactPanel).toHaveBeenCalledTimes(1);
78+
// When not nested (no PanelIdContext), non-layout children are rendered directly
79+
// without being wrapped in a ReactPanel (WidgetPlugin handles the panel)
80+
expect(mockReactPanel).toHaveBeenCalledTimes(0);
7981
});
8082

8183
it('should render multiple panels', () => {

0 commit comments

Comments
 (0)