|
7 | 7 | type WidgetMiddlewarePlugin, |
8 | 8 | type WidgetComponentProps, |
9 | 9 | type WidgetMiddlewareComponentProps, |
| 10 | + type WidgetMiddlewarePanelProps, |
10 | 11 | } from '@deephaven/plugin'; |
11 | 12 | import { Provider } from 'react-redux'; |
12 | 13 | import { Dashboard, PanelEvent } from '@deephaven/dashboard'; |
@@ -433,4 +434,100 @@ describe('middleware plugin chaining', () => { |
433 | 434 | const wrapper = screen.getByTestId('middleware-wrapper'); |
434 | 435 | expect(wrapper).toContainElement(screen.getByText('TestWidgetTwo')); |
435 | 436 | }); |
| 437 | + |
| 438 | + it('middleware for one type does not affect a different type', async () => { |
| 439 | + const otherPlugin: WidgetPlugin = { |
| 440 | + name: 'other-widget', |
| 441 | + type: PluginType.WIDGET_PLUGIN, |
| 442 | + component: TestWidgetTwo, |
| 443 | + supportedTypes: 'other-type', |
| 444 | + }; |
| 445 | + |
| 446 | + const layoutManager = createAndMountDashboard([ |
| 447 | + ['test-widget-plugin', testWidgetPlugin], |
| 448 | + ['other-widget', otherPlugin], |
| 449 | + ['test-middleware-plugin', testMiddlewarePlugin], // targets 'test-widget' only |
| 450 | + ]); |
| 451 | + |
| 452 | + // Open the other type — middleware should NOT apply |
| 453 | + act( |
| 454 | + () => |
| 455 | + layoutManager?.eventHub.emit(PanelEvent.OPEN, { |
| 456 | + widget: { type: 'other-type' }, |
| 457 | + }) |
| 458 | + ); |
| 459 | + |
| 460 | + expect(screen.queryAllByText('TestWidgetTwo').length).toBe(1); |
| 461 | + expect(screen.queryAllByText('MiddlewareWrapper').length).toBe(0); |
| 462 | + }); |
| 463 | + |
| 464 | + it('chains panel middleware around base panelComponent', async () => { |
| 465 | + function TestPanelMiddleware({ |
| 466 | + Component, |
| 467 | + ...props |
| 468 | + }: WidgetMiddlewarePanelProps) { |
| 469 | + return ( |
| 470 | + <div data-testid="panel-middleware"> |
| 471 | + <span>PanelMiddleware</span> |
| 472 | + {/* eslint-disable-next-line react/jsx-props-no-spreading */} |
| 473 | + <Component {...props} /> |
| 474 | + </div> |
| 475 | + ); |
| 476 | + } |
| 477 | + |
| 478 | + const panelMiddleware: WidgetMiddlewarePlugin = { |
| 479 | + name: 'panel-middleware', |
| 480 | + type: PluginType.WIDGET_PLUGIN, |
| 481 | + component: TestMiddlewareWrapper, |
| 482 | + panelComponent: TestPanelMiddleware, |
| 483 | + supportedTypes: 'test-widget-panel', |
| 484 | + isMiddleware: true, |
| 485 | + }; |
| 486 | + |
| 487 | + const layoutManager = createAndMountDashboard([ |
| 488 | + ['test-widget-plugin-with-panel', testWidgetPluginWithPanel], |
| 489 | + ['panel-middleware', panelMiddleware], |
| 490 | + ]); |
| 491 | + |
| 492 | + act( |
| 493 | + () => |
| 494 | + layoutManager?.eventHub.emit(PanelEvent.OPEN, { |
| 495 | + widget: { type: 'test-widget-panel' }, |
| 496 | + }) |
| 497 | + ); |
| 498 | + |
| 499 | + // Panel middleware should wrap the base panel |
| 500 | + expect(screen.queryAllByText('PanelMiddleware').length).toBe(1); |
| 501 | + expect(screen.queryAllByText('TestPanel').length).toBe(1); |
| 502 | + const wrapper = screen.getByTestId('panel-middleware'); |
| 503 | + expect(wrapper).toContainElement(screen.getByText('TestPanel')); |
| 504 | + }); |
| 505 | + |
| 506 | + it('skips component-only middleware when base has panelComponent', async () => { |
| 507 | + // Middleware that only defines component (no panelComponent) |
| 508 | + const componentOnlyMiddleware: WidgetMiddlewarePlugin = { |
| 509 | + name: 'component-only-middleware', |
| 510 | + type: PluginType.WIDGET_PLUGIN, |
| 511 | + component: TestMiddlewareWrapper, |
| 512 | + supportedTypes: 'test-widget-panel', |
| 513 | + isMiddleware: true, |
| 514 | + }; |
| 515 | + |
| 516 | + const layoutManager = createAndMountDashboard([ |
| 517 | + ['test-widget-plugin-with-panel', testWidgetPluginWithPanel], |
| 518 | + ['component-only-middleware', componentOnlyMiddleware], |
| 519 | + ]); |
| 520 | + |
| 521 | + act( |
| 522 | + () => |
| 523 | + layoutManager?.eventHub.emit(PanelEvent.OPEN, { |
| 524 | + widget: { type: 'test-widget-panel' }, |
| 525 | + }) |
| 526 | + ); |
| 527 | + |
| 528 | + // The base panel should render, but middleware wrapper should NOT appear |
| 529 | + // because the middleware lacks panelComponent and the base has panelComponent |
| 530 | + expect(screen.queryAllByText('TestPanel').length).toBe(1); |
| 531 | + expect(screen.queryAllByText('MiddlewareWrapper').length).toBe(0); |
| 532 | + }); |
436 | 533 | }); |
0 commit comments