add wrapper test, WIP main test but remove the errors
This commit is contained in:
@@ -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(
|
||||
<TestProvider store={configureStore({})} grafanaContext={grafanaContext}>
|
||||
<CorrelationsPage
|
||||
fetchCorrelations={get.execute}
|
||||
correlations={get.value}
|
||||
isLoading={get.loading}
|
||||
error={get.error}
|
||||
removeFn={remove.execute}
|
||||
fetchCorrelations={() => new Promise((c) => c)}
|
||||
correlations={{ correlations: enhCorrData, limit: 100, page: 0, totalCount: correlations.length }}
|
||||
isLoading={false}
|
||||
error={undefined}
|
||||
removeFn={undefined}
|
||||
/>
|
||||
</TestProvider>,
|
||||
{
|
||||
|
||||
@@ -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(<CorrelationsPageWrapper />);
|
||||
expect(mockUseCorrelationsK8s).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with the kubernetes feature toggle off', () => {
|
||||
it('uses the legacy correlations hook', () => {
|
||||
config.featureToggles = { ...originalFeatureToggles, kubernetesCorrelations: false };
|
||||
render(<CorrelationsPageWrapper />);
|
||||
expect(mockUseCorrelations).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user