mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Remove unneeded uses of setBackendSrv in alerting tests (#90380)
This commit is contained in:
parent
c77015b329
commit
0547a9ed88
@ -1,30 +1,24 @@
|
|||||||
import { SerializedError } from '@reduxjs/toolkit';
|
import { SerializedError } from '@reduxjs/toolkit';
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import { setupServer } from 'msw/node';
|
import { SetupServer } from 'msw/node';
|
||||||
import { TestProvider } from 'test/helpers/TestProvider';
|
import { TestProvider } from 'test/helpers/TestProvider';
|
||||||
import { prettyDOM, render, screen, waitFor, within } from 'test/test-utils';
|
import { prettyDOM, render, screen, waitFor, within } from 'test/test-utils';
|
||||||
import { byRole, byTestId, byText } from 'testing-library-selector';
|
import { byRole, byTestId, byText } from 'testing-library-selector';
|
||||||
|
|
||||||
import { PluginExtensionTypes, PluginMeta } from '@grafana/data';
|
import { PluginExtensionTypes } from '@grafana/data';
|
||||||
import { selectors } from '@grafana/e2e-selectors';
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
import {
|
import {
|
||||||
DataSourceSrv,
|
DataSourceSrv,
|
||||||
getPluginLinkExtensions,
|
getPluginLinkExtensions,
|
||||||
locationService,
|
locationService,
|
||||||
setBackendSrv,
|
setAppEvents,
|
||||||
setDataSourceSrv,
|
setDataSourceSrv,
|
||||||
usePluginLinkExtensions,
|
usePluginLinkExtensions,
|
||||||
} from '@grafana/runtime';
|
} from '@grafana/runtime';
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
import appEvents from 'app/core/app_events';
|
||||||
import * as ruleActionButtons from 'app/features/alerting/unified/components/rules/RuleActionsButtons';
|
import * as ruleActionButtons from 'app/features/alerting/unified/components/rules/RuleActionsButtons';
|
||||||
import {
|
import { mockSearchApi, mockUserApi, setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||||
mockAlertRuleApi,
|
import { setAlertmanagerChoices } from 'app/features/alerting/unified/mocks/server/configure';
|
||||||
mockApi,
|
|
||||||
mockFolderApi,
|
|
||||||
mockSearchApi,
|
|
||||||
mockUserApi,
|
|
||||||
} from 'app/features/alerting/unified/mockApi';
|
|
||||||
import { mockAlertmanagerChoiceResponse } from 'app/features/alerting/unified/mocks/alertmanagerApi';
|
|
||||||
import * as actions from 'app/features/alerting/unified/state/actions';
|
import * as actions from 'app/features/alerting/unified/state/actions';
|
||||||
import { getMockUser } from 'app/features/users/__mocks__/userMocks';
|
import { getMockUser } from 'app/features/users/__mocks__/userMocks';
|
||||||
import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
|
import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
|
||||||
@ -42,13 +36,11 @@ import {
|
|||||||
getPotentiallyPausedRulerRules,
|
getPotentiallyPausedRulerRules,
|
||||||
grantUserPermissions,
|
grantUserPermissions,
|
||||||
mockDataSource,
|
mockDataSource,
|
||||||
mockFolder,
|
|
||||||
mockPromAlert,
|
mockPromAlert,
|
||||||
mockPromAlertingRule,
|
mockPromAlertingRule,
|
||||||
mockPromRecordingRule,
|
mockPromRecordingRule,
|
||||||
mockPromRuleGroup,
|
mockPromRuleGroup,
|
||||||
mockPromRuleNamespace,
|
mockPromRuleNamespace,
|
||||||
mockRulerGrafanaRule,
|
|
||||||
pausedPromRules,
|
pausedPromRules,
|
||||||
somePromRules,
|
somePromRules,
|
||||||
someRulerRules,
|
someRulerRules,
|
||||||
@ -67,22 +59,14 @@ jest.mock('./api/buildInfo');
|
|||||||
jest.mock('./api/prometheus');
|
jest.mock('./api/prometheus');
|
||||||
jest.mock('./api/ruler');
|
jest.mock('./api/ruler');
|
||||||
jest.mock('../../../core/hooks/useMediaQueryChange');
|
jest.mock('../../../core/hooks/useMediaQueryChange');
|
||||||
jest.spyOn(ruleActionButtons, 'matchesWidth').mockReturnValue(false);
|
|
||||||
jest.mock('app/core/core', () => ({
|
|
||||||
...jest.requireActual('app/core/core'),
|
|
||||||
appEvents: {
|
|
||||||
subscribe: () => {
|
|
||||||
return { unsubscribe: () => {} };
|
|
||||||
},
|
|
||||||
emit: () => {},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
jest.spyOn(ruleActionButtons, 'matchesWidth').mockReturnValue(false);
|
||||||
jest.spyOn(analytics, 'logInfo');
|
jest.spyOn(analytics, 'logInfo');
|
||||||
jest.spyOn(config, 'getAllDataSources');
|
jest.spyOn(config, 'getAllDataSources');
|
||||||
jest.spyOn(actions, 'rulesInSameGroupHaveInvalidFor').mockReturnValue([]);
|
jest.spyOn(actions, 'rulesInSameGroupHaveInvalidFor').mockReturnValue([]);
|
||||||
jest.spyOn(apiRuler, 'rulerUrlBuilder');
|
jest.spyOn(apiRuler, 'rulerUrlBuilder');
|
||||||
|
|
||||||
|
setAppEvents(appEvents);
|
||||||
setupPluginsExtensionsHook();
|
setupPluginsExtensionsHook();
|
||||||
|
|
||||||
const mocks = {
|
const mocks = {
|
||||||
@ -169,45 +153,17 @@ const ui = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const server = setupServer();
|
const server = setupMswServer();
|
||||||
|
|
||||||
const configureMockServer = () => {
|
const configureMockServer = (server: SetupServer) => {
|
||||||
mockSearchApi(server).search([]);
|
mockSearchApi(server).search([]);
|
||||||
mockUserApi(server).user(getMockUser());
|
mockUserApi(server).user(getMockUser());
|
||||||
mockFolderApi(server).folder(
|
setAlertmanagerChoices(AlertmanagerChoice.All, 1);
|
||||||
'NAMESPACE_UID',
|
|
||||||
mockFolder({
|
|
||||||
accessControl: { [AccessControlAction.AlertingRuleUpdate]: true },
|
|
||||||
})
|
|
||||||
);
|
|
||||||
mockApi(server).plugins.getPluginSettings(
|
|
||||||
// We aren't particularly concerned with the plugin response in these tests
|
|
||||||
// at the time of writing, so we can go unknown -> PluginMeta to get the bare minimum
|
|
||||||
{ id: 'grafana-incident-app' } as unknown as PluginMeta
|
|
||||||
);
|
|
||||||
mockAlertmanagerChoiceResponse(server, {
|
|
||||||
alertmanagersChoice: AlertmanagerChoice.All,
|
|
||||||
numExternalAlertmanagers: 1,
|
|
||||||
});
|
|
||||||
mockAlertRuleApi(server).updateRule('grafana', {
|
|
||||||
message: 'rule group updated successfully',
|
|
||||||
updated: ['foo', 'bar', 'baz'],
|
|
||||||
});
|
|
||||||
mockAlertRuleApi(server).rulerRuleGroup(GRAFANA_RULES_SOURCE_NAME, 'NAMESPACE_UID', 'groupPaused', {
|
|
||||||
name: 'group-1',
|
|
||||||
interval: '1m',
|
|
||||||
rules: [mockRulerGrafanaRule()],
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('RuleList', () => {
|
describe('RuleList', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
server.listen({ onUnhandledRequest: 'error' });
|
configureMockServer(server);
|
||||||
configureMockServer();
|
|
||||||
grantUserPermissions([
|
grantUserPermissions([
|
||||||
AccessControlAction.AlertingRuleRead,
|
AccessControlAction.AlertingRuleRead,
|
||||||
AccessControlAction.AlertingRuleUpdate,
|
AccessControlAction.AlertingRuleUpdate,
|
||||||
@ -232,15 +188,10 @@ describe('RuleList', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
setDataSourceSrv(undefined as unknown as DataSourceSrv);
|
setDataSourceSrv(undefined as unknown as DataSourceSrv);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('load & show rule groups from multiple cloud data sources', async () => {
|
it('load & show rule groups from multiple cloud data sources', async () => {
|
||||||
mocks.getAllDataSourcesMock.mockReturnValue(Object.values(dataSources));
|
mocks.getAllDataSourcesMock.mockReturnValue(Object.values(dataSources));
|
||||||
|
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
import { http, HttpResponse } from 'msw';
|
|
||||||
import { setupServer } from 'msw/node';
|
|
||||||
|
|
||||||
import { SupportedPlugin } from '../types/pluginBridges';
|
|
||||||
|
|
||||||
export const NON_EXISTING_PLUGIN = '__does_not_exist__';
|
|
||||||
|
|
||||||
const server = setupServer(
|
|
||||||
http.get(`/api/plugins/${NON_EXISTING_PLUGIN}/settings`, async () =>
|
|
||||||
HttpResponse.json(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
status: 404,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
),
|
|
||||||
http.get(`/api/plugins/${SupportedPlugin.Incident}/settings`, async () => {
|
|
||||||
return HttpResponse.json({
|
|
||||||
enabled: true,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export { server };
|
|
@ -1,19 +1,12 @@
|
|||||||
import { screen, render } from '@testing-library/react';
|
import { screen, render } from 'test/test-utils';
|
||||||
|
|
||||||
import { setBackendSrv } from '@grafana/runtime';
|
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
|
||||||
|
|
||||||
import { SupportedPlugin } from '../types/pluginBridges';
|
import { SupportedPlugin } from '../types/pluginBridges';
|
||||||
|
|
||||||
import { createBridgeURL, PluginBridge } from './PluginBridge';
|
import { createBridgeURL, PluginBridge } from './PluginBridge';
|
||||||
import { server, NON_EXISTING_PLUGIN } from './PluginBridge.mock';
|
const NON_EXISTING_PLUGIN = '__does_not_exist__';
|
||||||
|
setupMswServer();
|
||||||
beforeAll(() => {
|
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
server.listen({ onUnhandledRequest: 'error' });
|
|
||||||
});
|
|
||||||
afterEach(() => server.resetHandlers());
|
|
||||||
afterAll(() => server.close());
|
|
||||||
|
|
||||||
describe('createBridgeURL', () => {
|
describe('createBridgeURL', () => {
|
||||||
it('should work with path', () => {
|
it('should work with path', () => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { http, HttpResponse } from 'msw';
|
import { http, HttpResponse } from 'msw';
|
||||||
import { SetupServer } from 'msw/lib/node';
|
import { SetupServer } from 'msw/node';
|
||||||
|
|
||||||
import { AlertManagerCortexConfig } from 'app/plugins/datasource/alertmanager/types';
|
import { AlertManagerCortexConfig } from 'app/plugins/datasource/alertmanager/types';
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { http, HttpResponse } from 'msw';
|
import { http, HttpResponse } from 'msw';
|
||||||
import { SetupServer } from 'msw/lib/node';
|
import { SetupServer } from 'msw/node';
|
||||||
|
|
||||||
import { AlertmanagerStatus } from 'app/plugins/datasource/alertmanager/types';
|
import { AlertmanagerStatus } from 'app/plugins/datasource/alertmanager/types';
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import { screen, render, waitFor } from '@testing-library/react';
|
|
||||||
import { setupServer } from 'msw/node';
|
|
||||||
import { default as React } from 'react';
|
import { default as React } from 'react';
|
||||||
import { FormProvider, useForm } from 'react-hook-form';
|
import { FormProvider, useForm } from 'react-hook-form';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
|
import { screen, render, waitFor } from 'test/test-utils';
|
||||||
import { byRole } from 'testing-library-selector';
|
import { byRole } from 'testing-library-selector';
|
||||||
|
|
||||||
import { Components } from '@grafana/e2e-selectors';
|
import { Components } from '@grafana/e2e-selectors';
|
||||||
import { setBackendSrv } from '@grafana/runtime';
|
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
|
||||||
import { configureStore } from 'app/store/configureStore';
|
import { configureStore } from 'app/store/configureStore';
|
||||||
|
|
||||||
import { TemplatePreviewResponse } from '../../api/templateApi';
|
import { TemplatePreviewResponse } from '../../api/templateApi';
|
||||||
@ -39,20 +37,7 @@ const getProviderWraper = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const server = setupServer();
|
const server = setupMswServer();
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
server.listen({ onUnhandledRequest: 'error' });
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
server.resetHandlers();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
const ui = {
|
const ui = {
|
||||||
errorAlert: byRole('alert', { name: /error/i }),
|
errorAlert: byRole('alert', { name: /error/i }),
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
import { findByRole, findByText, findByTitle, getByTestId, queryByText, render } from '@testing-library/react';
|
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import { setupServer } from 'msw/node';
|
|
||||||
import { FormProvider, useForm } from 'react-hook-form';
|
import { FormProvider, useForm } from 'react-hook-form';
|
||||||
import { TestProvider } from 'test/helpers/TestProvider';
|
import { findByRole, findByText, findByTitle, getByTestId, queryByText, render } from 'test/test-utils';
|
||||||
import { byRole, byTestId } from 'testing-library-selector';
|
import { byRole, byTestId } from 'testing-library-selector';
|
||||||
|
|
||||||
import 'core-js/stable/structured-clone';
|
import 'core-js/stable/structured-clone';
|
||||||
import { setBackendSrv } from '@grafana/runtime';
|
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
|
||||||
|
|
||||||
import { DashboardSearchItemType } from '../../../../search/types';
|
import { DashboardSearchItemType } from '../../../../search/types';
|
||||||
import { mockDashboardApi } from '../../mockApi';
|
import { mockDashboardApi, setupMswServer } from '../../mockApi';
|
||||||
import { mockDashboardDto, mockDashboardSearchItem, mockStore } from '../../mocks';
|
import { mockDashboardDto, mockDashboardSearchItem } from '../../mocks';
|
||||||
import { RuleFormValues } from '../../types/rule-form';
|
import { RuleFormValues } from '../../types/rule-form';
|
||||||
import { Annotation } from '../../utils/constants';
|
import { Annotation } from '../../utils/constants';
|
||||||
import { getDefaultFormValues } from '../../utils/rule-form';
|
import { getDefaultFormValues } from '../../utils/rule-form';
|
||||||
@ -40,31 +36,15 @@ const ui = {
|
|||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const server = setupServer();
|
const server = setupMswServer();
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
server.listen({ onUnhandledRequest: 'error' });
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
server.resetHandlers();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
function FormWrapper({ formValues }: { formValues?: Partial<RuleFormValues> }) {
|
function FormWrapper({ formValues }: { formValues?: Partial<RuleFormValues> }) {
|
||||||
const store = mockStore(() => null);
|
|
||||||
const formApi = useForm<RuleFormValues>({ defaultValues: { ...getDefaultFormValues(), ...formValues } });
|
const formApi = useForm<RuleFormValues>({ defaultValues: { ...getDefaultFormValues(), ...formValues } });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TestProvider store={store}>
|
<FormProvider {...formApi}>
|
||||||
<FormProvider {...formApi}>
|
<AnnotationsStep />
|
||||||
<AnnotationsStep />
|
</FormProvider>
|
||||||
</FormProvider>
|
|
||||||
</TestProvider>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@ import { within } from '@testing-library/react';
|
|||||||
import { render, waitFor, screen, userEvent } from 'test/test-utils';
|
import { render, waitFor, screen, userEvent } from 'test/test-utils';
|
||||||
import { byText, byRole } from 'testing-library-selector';
|
import { byText, byRole } from 'testing-library-selector';
|
||||||
|
|
||||||
import { setBackendSrv, setPluginExtensionsHook } from '@grafana/runtime';
|
import { setPluginExtensionsHook } from '@grafana/runtime';
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
|
||||||
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||||
import { setFolderAccessControl } from 'app/features/alerting/unified/mocks/server/configure';
|
import { setFolderAccessControl } from 'app/features/alerting/unified/mocks/server/configure';
|
||||||
import { AlertManagerDataSourceJsonData } from 'app/plugins/datasource/alertmanager/types';
|
import { AlertManagerDataSourceJsonData } from 'app/plugins/datasource/alertmanager/types';
|
||||||
@ -95,7 +94,6 @@ beforeAll(() => {
|
|||||||
AccessControlAction.AlertingRuleDelete,
|
AccessControlAction.AlertingRuleDelete,
|
||||||
AccessControlAction.AlertingInstanceCreate,
|
AccessControlAction.AlertingInstanceCreate,
|
||||||
]);
|
]);
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('RuleViewer', () => {
|
describe('RuleViewer', () => {
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
import { http, HttpResponse, RequestHandler } from 'msw';
|
|
||||||
import { setupServer } from 'msw/node';
|
|
||||||
|
|
||||||
import { GrafanaAlertingConfigurationStatusResponse } from 'app/features/alerting/unified/api/alertmanagerApi';
|
|
||||||
import { grafanaAlertingConfigurationStatusHandler } from 'app/features/alerting/unified/mocks/server/handlers/alertmanagers';
|
|
||||||
import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
|
|
||||||
import { AccessControlAction } from 'app/types';
|
|
||||||
|
|
||||||
const grafanaAlertingConfigurationMockedResponse: GrafanaAlertingConfigurationStatusResponse = {
|
|
||||||
alertmanagersChoice: AlertmanagerChoice.Internal,
|
|
||||||
numExternalAlertmanagers: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
const folderAccess = {
|
|
||||||
[AccessControlAction.AlertingRuleCreate]: true,
|
|
||||||
[AccessControlAction.AlertingRuleRead]: true,
|
|
||||||
[AccessControlAction.AlertingRuleUpdate]: true,
|
|
||||||
[AccessControlAction.AlertingRuleDelete]: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
export function createMockGrafanaServer(...handlers: RequestHandler[]) {
|
|
||||||
const folderHandler = mockFolderAccess(folderAccess);
|
|
||||||
const amChoiceHandler = grafanaAlertingConfigurationStatusHandler(grafanaAlertingConfigurationMockedResponse);
|
|
||||||
|
|
||||||
return setupServer(folderHandler, amChoiceHandler, ...handlers);
|
|
||||||
}
|
|
||||||
|
|
||||||
// this endpoint is used to determine of we have edit / delete permissions for the Grafana managed alert rule
|
|
||||||
// a user must alsso have permissions for the folder (namespace) in which the alert rule is stored
|
|
||||||
function mockFolderAccess(accessControl: Partial<Record<AccessControlAction, boolean>>) {
|
|
||||||
return http.get('/api/folders/:uid', ({ request }) => {
|
|
||||||
const url = new URL(request.url);
|
|
||||||
const uid = url.searchParams.get('uid');
|
|
||||||
|
|
||||||
return HttpResponse.json({
|
|
||||||
title: 'My Folder',
|
|
||||||
uid,
|
|
||||||
accessControl,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -2,8 +2,7 @@ import { render } from 'test/test-utils';
|
|||||||
import { byRole } from 'testing-library-selector';
|
import { byRole } from 'testing-library-selector';
|
||||||
|
|
||||||
import { PluginExtensionTypes } from '@grafana/data';
|
import { PluginExtensionTypes } from '@grafana/data';
|
||||||
import { usePluginLinkExtensions, setBackendSrv } from '@grafana/runtime';
|
import { usePluginLinkExtensions } from '@grafana/runtime';
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
|
||||||
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||||
|
|
||||||
import { useIsRuleEditable } from '../../hooks/useIsRuleEditable';
|
import { useIsRuleEditable } from '../../hooks/useIsRuleEditable';
|
||||||
@ -34,7 +33,6 @@ const ui = {
|
|||||||
setupMswServer();
|
setupMswServer();
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
import { render, waitFor } from '@testing-library/react';
|
|
||||||
import { http, HttpResponse } from 'msw';
|
import { http, HttpResponse } from 'msw';
|
||||||
import { setupServer } from 'msw/node';
|
|
||||||
import { Props } from 'react-virtualized-auto-sizer';
|
import { Props } from 'react-virtualized-auto-sizer';
|
||||||
|
import { render, waitFor } from 'test/test-utils';
|
||||||
import { byRole, byTestId, byText } from 'testing-library-selector';
|
import { byRole, byTestId, byText } from 'testing-library-selector';
|
||||||
|
|
||||||
import { DataFrameJSON } from '@grafana/data';
|
import { DataFrameJSON } from '@grafana/data';
|
||||||
import { setBackendSrv } from '@grafana/runtime';
|
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||||
|
|
||||||
import { TestProvider } from '../../../../../../../test/helpers/TestProvider';
|
|
||||||
import { backendSrv } from '../../../../../../core/services/backend_srv';
|
|
||||||
|
|
||||||
import LokiStateHistory from './LokiStateHistory';
|
import LokiStateHistory from './LokiStateHistory';
|
||||||
|
|
||||||
const server = setupServer();
|
const server = setupMswServer();
|
||||||
|
|
||||||
jest.mock('react-virtualized-auto-sizer', () => {
|
jest.mock('react-virtualized-auto-sizer', () => {
|
||||||
return ({ children }: Props) =>
|
return ({ children }: Props) =>
|
||||||
@ -25,9 +21,6 @@ jest.mock('react-virtualized-auto-sizer', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
server.listen({ onUnhandledRequest: 'error' });
|
|
||||||
|
|
||||||
server.use(
|
server.use(
|
||||||
http.get('/api/v1/rules/history', () =>
|
http.get('/api/v1/rules/history', () =>
|
||||||
HttpResponse.json<DataFrameJSON>({
|
HttpResponse.json<DataFrameJSON>({
|
||||||
@ -78,10 +71,6 @@ beforeAll(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
window.HTMLElement.prototype.scrollIntoView = jest.fn();
|
window.HTMLElement.prototype.scrollIntoView = jest.fn();
|
||||||
|
|
||||||
const ui = {
|
const ui = {
|
||||||
@ -94,7 +83,7 @@ const ui = {
|
|||||||
|
|
||||||
describe('LokiStateHistory', () => {
|
describe('LokiStateHistory', () => {
|
||||||
it('should render history records', async () => {
|
it('should render history records', async () => {
|
||||||
render(<LokiStateHistory ruleUID="ABC123" />, { wrapper: TestProvider });
|
render(<LokiStateHistory ruleUID="ABC123" />);
|
||||||
|
|
||||||
await waitFor(() => expect(ui.loadingIndicator.query()).not.toBeInTheDocument());
|
await waitFor(() => expect(ui.loadingIndicator.query()).not.toBeInTheDocument());
|
||||||
|
|
||||||
@ -107,7 +96,7 @@ describe('LokiStateHistory', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render timeline chart', async () => {
|
it('should render timeline chart', async () => {
|
||||||
render(<LokiStateHistory ruleUID="ABC123" />, { wrapper: TestProvider });
|
render(<LokiStateHistory ruleUID="ABC123" />);
|
||||||
|
|
||||||
await waitFor(() => expect(ui.loadingIndicator.query()).not.toBeInTheDocument());
|
await waitFor(() => expect(ui.loadingIndicator.query()).not.toBeInTheDocument());
|
||||||
|
|
||||||
@ -121,7 +110,7 @@ describe('LokiStateHistory', () => {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
render(<LokiStateHistory ruleUID="abcd" />, { wrapper: TestProvider });
|
render(<LokiStateHistory ruleUID="abcd" />);
|
||||||
|
|
||||||
await waitFor(() => expect(ui.loadingIndicator.query()).not.toBeInTheDocument());
|
await waitFor(() => expect(ui.loadingIndicator.query()).not.toBeInTheDocument());
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { delay, http, HttpResponse } from 'msw';
|
import { delay, http, HttpResponse } from 'msw';
|
||||||
import { SetupServerApi } from 'msw/lib/node';
|
import { SetupServerApi } from 'msw/node';
|
||||||
|
|
||||||
import { setDataSourceSrv } from '@grafana/runtime';
|
import { setDataSourceSrv } from '@grafana/runtime';
|
||||||
import {
|
import {
|
||||||
|
@ -3,8 +3,6 @@ import { HttpResponse } from 'msw';
|
|||||||
import { render } from 'test/test-utils';
|
import { render } from 'test/test-utils';
|
||||||
import { byRole, byText } from 'testing-library-selector';
|
import { byRole, byText } from 'testing-library-selector';
|
||||||
|
|
||||||
import { setBackendSrv } from '@grafana/runtime';
|
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
|
||||||
import { AccessControlAction } from 'app/types';
|
import { AccessControlAction } from 'app/types';
|
||||||
import { CombinedRule } from 'app/types/unified-alerting';
|
import { CombinedRule } from 'app/types/unified-alerting';
|
||||||
|
|
||||||
@ -29,7 +27,6 @@ import { useDeleteRuleFromGroup } from './useDeleteRuleFromGroup';
|
|||||||
setupMswServer();
|
setupMswServer();
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
grantUserPermissions([AccessControlAction.AlertingRuleExternalRead, AccessControlAction.AlertingRuleRead]);
|
grantUserPermissions([AccessControlAction.AlertingRuleExternalRead, AccessControlAction.AlertingRuleRead]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ import { HttpResponse } from 'msw';
|
|||||||
import { render } from 'test/test-utils';
|
import { render } from 'test/test-utils';
|
||||||
import { byText, byRole } from 'testing-library-selector';
|
import { byText, byRole } from 'testing-library-selector';
|
||||||
|
|
||||||
import { setBackendSrv } from '@grafana/runtime';
|
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
|
||||||
import { AccessControlAction } from 'app/types';
|
import { AccessControlAction } from 'app/types';
|
||||||
import { RulerGrafanaRuleDTO } from 'app/types/unified-alerting-dto';
|
import { RulerGrafanaRuleDTO } from 'app/types/unified-alerting-dto';
|
||||||
|
|
||||||
@ -21,7 +19,6 @@ import { usePauseRuleInGroup } from './usePauseAlertRule';
|
|||||||
setupMswServer();
|
setupMswServer();
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
grantUserPermissions([AccessControlAction.AlertingRuleExternalRead, AccessControlAction.AlertingRuleRead]);
|
grantUserPermissions([AccessControlAction.AlertingRuleExternalRead, AccessControlAction.AlertingRuleRead]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@ import userEvent from '@testing-library/user-event';
|
|||||||
import { render } from 'test/test-utils';
|
import { render } from 'test/test-utils';
|
||||||
import { byRole, byText } from 'testing-library-selector';
|
import { byRole, byText } from 'testing-library-selector';
|
||||||
|
|
||||||
import { setBackendSrv } from '@grafana/runtime';
|
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
|
||||||
import { AccessControlAction } from 'app/types';
|
import { AccessControlAction } from 'app/types';
|
||||||
import { RuleGroupIdentifier } from 'app/types/unified-alerting';
|
import { RuleGroupIdentifier } from 'app/types/unified-alerting';
|
||||||
|
|
||||||
@ -22,7 +20,6 @@ import { useMoveRuleGroup, useRenameRuleGroup, useUpdateRuleGroupConfiguration }
|
|||||||
setupMswServer();
|
setupMswServer();
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
grantUserPermissions([AccessControlAction.AlertingRuleExternalRead, AccessControlAction.AlertingRuleRead]);
|
grantUserPermissions([AccessControlAction.AlertingRuleExternalRead, AccessControlAction.AlertingRuleRead]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,31 +1,17 @@
|
|||||||
import { renderHook, waitFor } from '@testing-library/react';
|
import { renderHook, waitFor } from '@testing-library/react';
|
||||||
import { http, HttpResponse } from 'msw';
|
import { http, HttpResponse } from 'msw';
|
||||||
import { SetupServer, setupServer } from 'msw/node';
|
import { SetupServer } from 'msw/node';
|
||||||
import { TestProvider } from 'test/helpers/TestProvider';
|
import { TestProvider } from 'test/helpers/TestProvider';
|
||||||
|
|
||||||
import { DataSourceSettings } from '@grafana/data';
|
import { DataSourceSettings } from '@grafana/data';
|
||||||
import { setBackendSrv } from '@grafana/runtime';
|
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||||
import { backendSrv } from 'app/core/services/backend_srv';
|
|
||||||
import { AlertManagerDataSourceJsonData } from 'app/plugins/datasource/alertmanager/types';
|
import { AlertManagerDataSourceJsonData } from 'app/plugins/datasource/alertmanager/types';
|
||||||
|
|
||||||
import { mockAlertmanagersResponse } from '../mocks/alertmanagerApi';
|
import { mockAlertmanagersResponse } from '../mocks/alertmanagerApi';
|
||||||
|
|
||||||
import { normalizeDataSourceURL, useExternalDataSourceAlertmanagers } from './useExternalAmSelector';
|
import { normalizeDataSourceURL, useExternalDataSourceAlertmanagers } from './useExternalAmSelector';
|
||||||
|
|
||||||
const server = setupServer();
|
const server = setupMswServer();
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
setBackendSrv(backendSrv);
|
|
||||||
server.listen({ onUnhandledRequest: 'error' });
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
server.resetHandlers();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('useExternalDataSourceAlertmanagers', () => {
|
describe('useExternalDataSourceAlertmanagers', () => {
|
||||||
it('Should get the correct data source settings', async () => {
|
it('Should get the correct data source settings', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user