From 4b90167a50b9f95293425726d2470674fff460c0 Mon Sep 17 00:00:00 2001 From: Catherine Liu Date: Mon, 3 Jun 2024 16:18:46 -0700 Subject: [PATCH] Fix action tests --- .../expand_panel_action.test.tsx | 21 ++++++++++++------- .../filters_notification_action.test.tsx | 6 +++--- .../presentation_panel_context_menu.tsx | 2 -- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/plugins/dashboard/public/dashboard_actions/expand_panel_action.test.tsx b/src/plugins/dashboard/public/dashboard_actions/expand_panel_action.test.tsx index 6ff1773ff610e29..e38a4137e6ef199 100644 --- a/src/plugins/dashboard/public/dashboard_actions/expand_panel_action.test.tsx +++ b/src/plugins/dashboard/public/dashboard_actions/expand_panel_action.test.tsx @@ -13,14 +13,18 @@ describe('Expand panel action', () => { let action: ExpandPanelAction; let context: { embeddable: ExpandPanelActionApi }; + let updateExpandPanelId: (id?: string) => void; + beforeEach(() => { + const expandPanelIdSubject = new BehaviorSubject(undefined); + updateExpandPanelId = (id) => expandPanelIdSubject.next(id); action = new ExpandPanelAction(); context = { embeddable: { uuid: 'superId', parentApi: { expandPanel: jest.fn(), - expandedPanelId: new BehaviorSubject(undefined), + expandedPanelId: expandPanelIdSubject, }, }, }; @@ -37,19 +41,22 @@ describe('Expand panel action', () => { expect(await action.isCompatible(emptyContext)).toBe(false); }); + it('calls onChange when expandedPanelId changes', async () => { + const onChange = jest.fn(); + updateExpandPanelId('superPanelId'); + action.subscribeToCompatibilityChanges(context, onChange); + expect(onChange).toHaveBeenCalledWith(true, action); + }); + it('returns the correct icon based on expanded panel id', async () => { expect(await action.getIconType(context)).toBe('expand'); - context.embeddable.parentApi.expandedPanelId = new BehaviorSubject( - 'superPanelId' - ); + updateExpandPanelId('superPanelId'); expect(await action.getIconType(context)).toBe('minimize'); }); it('returns the correct display name based on expanded panel id', async () => { expect(await action.getDisplayName(context)).toBe('Maximize'); - context.embeddable.parentApi.expandedPanelId = new BehaviorSubject( - 'superPanelId' - ); + updateExpandPanelId('superPanelId'); expect(await action.getDisplayName(context)).toBe('Minimize'); }); diff --git a/src/plugins/dashboard/public/dashboard_actions/filters_notification_action.test.tsx b/src/plugins/dashboard/public/dashboard_actions/filters_notification_action.test.tsx index 2565c3f00821c0a..485835055bb9243 100644 --- a/src/plugins/dashboard/public/dashboard_actions/filters_notification_action.test.tsx +++ b/src/plugins/dashboard/public/dashboard_actions/filters_notification_action.test.tsx @@ -86,11 +86,11 @@ describe('filters notification action', () => { expect(await action.isCompatible(context)).toBe(true); }); - it('is incompatible when api is in view mode', async () => { + it('is available when api is in view mode', async () => { updateFilters([getMockPhraseFilter('SuperField', 'SuperValue')]); updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery); updateViewMode('view'); - expect(await action.isCompatible(context)).toBe(false); + expect(await action.isCompatible(context)).toBe(true); }); it('calls onChange when view mode changes', () => { @@ -99,7 +99,7 @@ describe('filters notification action', () => { updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery); action.subscribeToCompatibilityChanges(context, onChange); updateViewMode('view'); - expect(onChange).toHaveBeenCalledWith(false, action); + expect(onChange).toHaveBeenCalledWith(true, action); }); it('calls onChange when filters change', async () => { diff --git a/src/plugins/presentation_panel/public/panel_component/panel_header/presentation_panel_context_menu.tsx b/src/plugins/presentation_panel/public/panel_component/panel_header/presentation_panel_context_menu.tsx index fc02d4bdbd4c04b..72a1ebd2185b8d2 100644 --- a/src/plugins/presentation_panel/public/panel_component/panel_header/presentation_panel_context_menu.tsx +++ b/src/plugins/presentation_panel/public/panel_component/panel_header/presentation_panel_context_menu.tsx @@ -263,8 +263,6 @@ export const PresentationPanelContextMenu = ({ [contextMenuActions] ); - console.log({ quickActions, hoverActionPanels }); - const notificationElements = useMemo(() => { if (!showNotifications || !api) return []; return notifications?.map((notification) => {