mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Split handlers out into separate files
This commit is contained in:
parent
f419c9b53a
commit
0dc003aadc
@ -1,9 +1,12 @@
|
|||||||
import { http, HttpResponse } from 'msw';
|
import { http, HttpResponse } from 'msw';
|
||||||
import { SetupServer } from 'msw/node';
|
import { SetupServer } from 'msw/node';
|
||||||
|
|
||||||
|
import { mockAlertmanagerAlert } from 'app/features/alerting/unified/mocks';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AlertmanagerChoice,
|
AlertmanagerChoice,
|
||||||
AlertManagerCortexConfig,
|
AlertManagerCortexConfig,
|
||||||
|
AlertState,
|
||||||
ExternalAlertmanagersResponse,
|
ExternalAlertmanagersResponse,
|
||||||
} from '../../../../plugins/datasource/alertmanager/types';
|
} from '../../../../plugins/datasource/alertmanager/types';
|
||||||
import { AlertmanagersChoiceResponse } from '../api/alertmanagerApi';
|
import { AlertmanagersChoiceResponse } from '../api/alertmanagerApi';
|
||||||
@ -13,8 +16,12 @@ export const defaultAlertmanagerChoiceResponse: AlertmanagersChoiceResponse = {
|
|||||||
alertmanagersChoice: AlertmanagerChoice.Internal,
|
alertmanagersChoice: AlertmanagerChoice.Internal,
|
||||||
numExternalAlertmanagers: 0,
|
numExternalAlertmanagers: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const alertmanagerChoiceHandler = (response = defaultAlertmanagerChoiceResponse) =>
|
||||||
|
http.get('/api/v1/ngalert', () => HttpResponse.json(response));
|
||||||
|
|
||||||
export function mockAlertmanagerChoiceResponse(server: SetupServer, response: AlertmanagersChoiceResponse) {
|
export function mockAlertmanagerChoiceResponse(server: SetupServer, response: AlertmanagersChoiceResponse) {
|
||||||
server.use(http.get('/api/v1/ngalert', () => HttpResponse.json(response)));
|
server.use(alertmanagerChoiceHandler(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
export const emptyExternalAlertmanagersResponse: ExternalAlertmanagersResponse = {
|
export const emptyExternalAlertmanagersResponse: ExternalAlertmanagersResponse = {
|
||||||
@ -38,3 +45,17 @@ export function mockAlertmanagerConfigResponse(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const alertmanagerAlertsListHandler = () =>
|
||||||
|
http.get('/api/alertmanager/:datasourceUid/api/v2/alerts', () =>
|
||||||
|
HttpResponse.json([
|
||||||
|
mockAlertmanagerAlert({
|
||||||
|
labels: { foo: 'bar', buzz: 'bazz' },
|
||||||
|
status: { state: AlertState.Suppressed, silencedBy: ['12345'], inhibitedBy: [] },
|
||||||
|
}),
|
||||||
|
mockAlertmanagerAlert({
|
||||||
|
labels: { foo: 'bar', buzz: 'bazz' },
|
||||||
|
status: { state: AlertState.Suppressed, silencedBy: ['12345'], inhibitedBy: [] },
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
import { HttpResponse, http } from 'msw';
|
||||||
|
|
||||||
|
// TODO: Add more accurate endpoint responses as tests require
|
||||||
|
export const datasourceBuildInfoHandler = () =>
|
||||||
|
http.get('/api/datasources/proxy/uid/:datasourceUid/api/v1/status/buildinfo', () => HttpResponse.json({}));
|
@ -1,5 +1,5 @@
|
|||||||
import server from 'app/features/alerting/unified/mockApi';
|
import server from 'app/features/alerting/unified/mockApi';
|
||||||
import { alertmanagerChoiceHandler } from 'app/features/alerting/unified/mocks/server/handlers';
|
import { alertmanagerChoiceHandler } from 'app/features/alerting/unified/mocks/alertmanagerApi';
|
||||||
import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
|
import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,53 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* Contains definitions for all handlers that are required for test rendering of components within Alerting
|
* Contains all handlers that are required for test rendering of components within Alerting
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { HttpResponse, http } from 'msw';
|
import {
|
||||||
|
alertmanagerAlertsListHandler,
|
||||||
import { mockAlertmanagerAlert, mockSilences } from 'app/features/alerting/unified/mocks';
|
alertmanagerChoiceHandler,
|
||||||
import { defaultAlertmanagerChoiceResponse } from 'app/features/alerting/unified/mocks/alertmanagerApi';
|
} from 'app/features/alerting/unified/mocks/alertmanagerApi';
|
||||||
import { AlertState } from 'app/plugins/datasource/alertmanager/types';
|
import { datasourceBuildInfoHandler } from 'app/features/alerting/unified/mocks/datasources';
|
||||||
|
import { silenceCreateHandler, silencesListHandler } from 'app/features/alerting/unified/mocks/silences';
|
||||||
///////////////////
|
|
||||||
// Alertmanagers //
|
|
||||||
///////////////////
|
|
||||||
|
|
||||||
export const alertmanagerChoiceHandler = (response = defaultAlertmanagerChoiceResponse) =>
|
|
||||||
http.get('/api/v1/ngalert', () => HttpResponse.json(response));
|
|
||||||
|
|
||||||
const alertmanagerAlertsListHandler = () =>
|
|
||||||
http.get('/api/alertmanager/:datasourceUid/api/v2/alerts', () =>
|
|
||||||
HttpResponse.json([
|
|
||||||
mockAlertmanagerAlert({
|
|
||||||
labels: { foo: 'bar', buzz: 'bazz' },
|
|
||||||
status: { state: AlertState.Suppressed, silencedBy: ['12345'], inhibitedBy: [] },
|
|
||||||
}),
|
|
||||||
mockAlertmanagerAlert({
|
|
||||||
labels: { foo: 'bar', buzz: 'bazz' },
|
|
||||||
status: { state: AlertState.Suppressed, silencedBy: ['12345'], inhibitedBy: [] },
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
);
|
|
||||||
|
|
||||||
/////////////////
|
|
||||||
// Datasources //
|
|
||||||
/////////////////
|
|
||||||
|
|
||||||
// TODO: Add more accurate endpoint responses as tests require
|
|
||||||
const datasourceBuildInfoHandler = () =>
|
|
||||||
http.get('/api/datasources/proxy/uid/:datasourceUid/api/v1/status/buildinfo', () => HttpResponse.json({}));
|
|
||||||
|
|
||||||
//////////////
|
|
||||||
// Silences //
|
|
||||||
//////////////
|
|
||||||
|
|
||||||
const silencesListHandler = (silences = mockSilences) =>
|
|
||||||
http.get('/api/alertmanager/:datasourceUid/api/v2/silences', () => HttpResponse.json(silences));
|
|
||||||
|
|
||||||
const createSilenceHandler = () =>
|
|
||||||
http.post('/api/alertmanager/:datasourceUid/api/v2/silences', () =>
|
|
||||||
HttpResponse.json({ silenceId: '4bda5b38-7939-4887-9ec2-16323b8e3b4e' })
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All mock handlers that are required across Alerting tests
|
* All mock handlers that are required across Alerting tests
|
||||||
@ -55,7 +15,7 @@ const createSilenceHandler = () =>
|
|||||||
const allHandlers = [
|
const allHandlers = [
|
||||||
alertmanagerChoiceHandler(),
|
alertmanagerChoiceHandler(),
|
||||||
silencesListHandler(),
|
silencesListHandler(),
|
||||||
createSilenceHandler(),
|
silenceCreateHandler(),
|
||||||
alertmanagerAlertsListHandler(),
|
alertmanagerAlertsListHandler(),
|
||||||
datasourceBuildInfoHandler(),
|
datasourceBuildInfoHandler(),
|
||||||
];
|
];
|
||||||
|
15
public/app/features/alerting/unified/mocks/silences.ts
Normal file
15
public/app/features/alerting/unified/mocks/silences.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { HttpResponse, http } from 'msw';
|
||||||
|
|
||||||
|
import { mockSilences } from 'app/features/alerting/unified/mocks';
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// Silences //
|
||||||
|
//////////////
|
||||||
|
|
||||||
|
export const silencesListHandler = (silences = mockSilences) =>
|
||||||
|
http.get('/api/alertmanager/:datasourceUid/api/v2/silences', () => HttpResponse.json(silences));
|
||||||
|
|
||||||
|
export const silenceCreateHandler = () =>
|
||||||
|
http.post('/api/alertmanager/:datasourceUid/api/v2/silences', () =>
|
||||||
|
HttpResponse.json({ silenceId: '4bda5b38-7939-4887-9ec2-16323b8e3b4e' })
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user