From d3e3d4252bffd124c61bf2fa0e897c6da8ea2522 Mon Sep 17 00:00:00 2001 From: Kristina Durivage Date: Mon, 15 Dec 2025 10:46:03 -0600 Subject: [PATCH] add wrapper test, WIP main test but remove the errors --- .../correlations/CorrelationsPage.test.tsx | 16 +++--- .../CorrelationsPageWrapper.test.tsx | 54 +++++++++++++++++++ 2 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 public/app/features/correlations/CorrelationsPageWrapper.test.tsx diff --git a/public/app/features/correlations/CorrelationsPage.test.tsx b/public/app/features/correlations/CorrelationsPage.test.tsx index b9632a3d96f..a115a551798 100644 --- a/public/app/features/correlations/CorrelationsPage.test.tsx +++ b/public/app/features/correlations/CorrelationsPage.test.tsx @@ -33,7 +33,7 @@ import { MockDataSourceSrv, } from './mocks/useCorrelations.mocks'; import { Correlation, CreateCorrelationParams, OmitUnion } from './types'; -import { useCorrelations } from './useCorrelations'; +import { toEnrichedCorrelationData, useCorrelations } from './useCorrelations'; // Set app events up, otherwise plugin modules will fail to load setAppEvents(appEvents); @@ -111,16 +111,18 @@ const renderWithContext = async ( setDataSourceSrv(dsServer); - const { remove, get } = useCorrelations(); + // const { remove, get } = useCorrelations(); + + const enhCorrData = correlations.map(toEnrichedCorrelationData).filter((i) => i !== undefined); const renderResult = render( new Promise((c) => c)} + correlations={{ correlations: enhCorrData, limit: 100, page: 0, totalCount: correlations.length }} + isLoading={false} + error={undefined} + removeFn={undefined} /> , { diff --git a/public/app/features/correlations/CorrelationsPageWrapper.test.tsx b/public/app/features/correlations/CorrelationsPageWrapper.test.tsx new file mode 100644 index 00000000000..f1ddab82de3 --- /dev/null +++ b/public/app/features/correlations/CorrelationsPageWrapper.test.tsx @@ -0,0 +1,54 @@ +import { render } from 'test/test-utils'; + +import { config } from '@grafana/runtime'; + +import CorrelationsPageWrapper from './CorrelationsPageWrapper'; + +jest.mock('app/core/services/context_srv'); + +const mockUseCorrelations = jest.fn().mockReturnValue({ + remove: { execute: jest.fn() }, + get: { execute: jest.fn(), value: [], loading: false, error: undefined }, +}); +const mockUseCorrelationsK8s = jest.fn().mockReturnValue({ + currentData: [], + isLoading: false, + error: undefined, + remainingItems: 0, +}); + +jest.mock('./useCorrelations', () => ({ + useCorrelations: () => mockUseCorrelations(), +})); + +jest.mock('./useCorrelationsK8s', () => ({ + useCorrelationsK8s: () => mockUseCorrelationsK8s(), +})); + +describe('CorrelationsPageWrapper', () => { + const originalFeatureToggles = config.featureToggles; + + beforeEach(() => { + jest.clearAllMocks(); + }); + + afterEach(() => { + config.featureToggles = originalFeatureToggles; + }); + + describe('with the kubernetes feature toggle on', () => { + it('uses the K8s correlations hook', () => { + config.featureToggles = { ...originalFeatureToggles, kubernetesCorrelations: true }; + render(); + expect(mockUseCorrelationsK8s).toHaveBeenCalled(); + }); + }); + + describe('with the kubernetes feature toggle off', () => { + it('uses the legacy correlations hook', () => { + config.featureToggles = { ...originalFeatureToggles, kubernetesCorrelations: false }; + render(); + expect(mockUseCorrelations).toHaveBeenCalled(); + }); + }); +});