From cc24e280ebae65d10c33c50386201b52b8dc9128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Tue, 18 Mar 2025 12:01:47 +0100 Subject: [PATCH] Chore: fix PanelMenuBehavior test --- .../pages/DashboardScenePage.test.tsx | 11 ++---- .../scene/PanelMenuBehavior.test.tsx | 35 ++++++++----------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/public/app/features/dashboard-scene/pages/DashboardScenePage.test.tsx b/public/app/features/dashboard-scene/pages/DashboardScenePage.test.tsx index 04dbc830a20..5866e7092c0 100644 --- a/public/app/features/dashboard-scene/pages/DashboardScenePage.test.tsx +++ b/public/app/features/dashboard-scene/pages/DashboardScenePage.test.tsx @@ -8,12 +8,7 @@ import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock'; import { PanelProps } from '@grafana/data'; import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; import { selectors } from '@grafana/e2e-selectors'; -import { - LocationServiceProvider, - config, - locationService, - setPluginImportUtils, -} from '@grafana/runtime'; +import { LocationServiceProvider, config, locationService, setPluginImportUtils } from '@grafana/runtime'; import { VizPanel } from '@grafana/scenes'; import { Dashboard } from '@grafana/schema'; import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps'; @@ -56,7 +51,7 @@ jest.mock('react-router-dom-v5-compat', () => ({ const getPluginExtensionsMock = jest.fn().mockReturnValue({ extensions: [] }); jest.mock('app/features/plugins/extensions/getPluginExtensions', () => ({ ...jest.requireActual('app/features/plugins/extensions/getPluginExtensions'), - createPluginExtensionsGetter: jest.fn().mockReturnValue(getPluginExtensionsMock), + createPluginExtensionsGetter: () => getPluginExtensionsMock, })); function setup({ routeProps }: { routeProps?: Partial } = {}) { @@ -162,7 +157,7 @@ describe('DashboardScenePage', () => { getPluginExtensionsMock.mockReturnValue({ extensions: [] }); store.delete(DASHBOARD_FROM_LS_KEY); }); - + it('Can render dashboard', async () => { setup(); diff --git a/public/app/features/dashboard-scene/scene/PanelMenuBehavior.test.tsx b/public/app/features/dashboard-scene/scene/PanelMenuBehavior.test.tsx index d0aa2f56b9f..3b512fd98e1 100644 --- a/public/app/features/dashboard-scene/scene/PanelMenuBehavior.test.tsx +++ b/public/app/features/dashboard-scene/scene/PanelMenuBehavior.test.tsx @@ -9,7 +9,7 @@ import { urlUtil, } from '@grafana/data'; import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; -import { config, getPluginLinkExtensions, locationService } from '@grafana/runtime'; +import { config, locationService } from '@grafana/runtime'; import { LocalValueVariable, SceneQueryRunner, @@ -47,24 +47,17 @@ jest.mock('app/core/utils/explore', () => ({ jest.mock('app/core/services/context_srv'); -jest.mock('@grafana/runtime', () => ({ - ...jest.requireActual('@grafana/runtime'), - setPluginExtensionGetter: jest.fn(), - getPluginLinkExtensions: jest.fn(), -})); - jest.mock('app/store/store', () => ({ dispatch: jest.fn(), })); -const getPluginLinkExtensionsMock = jest.mocked(getPluginLinkExtensions); +const getPluginExtensionsMock = jest.fn().mockReturnValue({ extensions: [] }); +jest.mock('app/features/plugins/extensions/getPluginExtensions', () => ({ + ...jest.requireActual('app/features/plugins/extensions/getPluginExtensions'), + createPluginExtensionsGetter: () => getPluginExtensionsMock, +})); describe('panelMenuBehavior', () => { - beforeEach(() => { - getPluginLinkExtensionsMock.mockRestore(); - getPluginLinkExtensionsMock.mockReturnValue({ extensions: [] }); - }); - beforeAll(() => { locationService.push('/d/dash-1?from=now-5m&to=now'); }); @@ -133,7 +126,7 @@ describe('panelMenuBehavior', () => { describe('when extending panel menu from plugins', () => { it('should contain menu item from link extension', async () => { - getPluginLinkExtensionsMock.mockReturnValue({ + getPluginExtensionsMock.mockReturnValue({ extensions: [ { id: '1', @@ -172,7 +165,7 @@ describe('panelMenuBehavior', () => { }); it('should truncate menu item title to 25 chars', async () => { - getPluginLinkExtensionsMock.mockReturnValue({ + getPluginExtensionsMock.mockReturnValue({ extensions: [ { id: '1', @@ -213,7 +206,7 @@ describe('panelMenuBehavior', () => { it('should pass onClick from plugin extension link to menu item', async () => { const expectedOnClick = jest.fn(); - getPluginLinkExtensionsMock.mockReturnValue({ + getPluginExtensionsMock.mockReturnValue({ extensions: [ { id: '1', @@ -299,7 +292,7 @@ describe('panelMenuBehavior', () => { data, }; - expect(getPluginLinkExtensionsMock).toBeCalledWith(expect.objectContaining({ context })); + expect(getPluginExtensionsMock).toBeCalledWith(expect.objectContaining({ context })); }); it('should pass context with default time zone values when configuring extension', async () => { @@ -356,11 +349,11 @@ describe('panelMenuBehavior', () => { data, }; - expect(getPluginLinkExtensionsMock).toBeCalledWith(expect.objectContaining({ context })); + expect(getPluginExtensionsMock).toBeCalledWith(expect.objectContaining({ context })); }); it('should contain menu item with category', async () => { - getPluginLinkExtensionsMock.mockReturnValue({ + getPluginExtensionsMock.mockReturnValue({ extensions: [ { id: '1', @@ -405,7 +398,7 @@ describe('panelMenuBehavior', () => { }); it('should truncate category to 25 chars', async () => { - getPluginLinkExtensionsMock.mockReturnValue({ + getPluginExtensionsMock.mockReturnValue({ extensions: [ { id: '1', @@ -450,7 +443,7 @@ describe('panelMenuBehavior', () => { }); it('should contain menu item with category and append items without category after divider', async () => { - getPluginLinkExtensionsMock.mockReturnValue({ + getPluginExtensionsMock.mockReturnValue({ extensions: [ { id: '1',