mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
* fix any's in tests * fix more any's in tests * more test type fixes * fixing any's in tests part 3 * more test type fixes * fixing test any's p5 * some tidy up * fix template_srv
85 lines
2.9 KiB
TypeScript
85 lines
2.9 KiB
TypeScript
import { DashboardSrv } from '../dashboard/services/DashboardSrv';
|
|
import { DatasourceSrv } from '../plugins/datasource_srv';
|
|
|
|
import { AlertTabCtrl } from './AlertTabCtrl';
|
|
|
|
interface Args {
|
|
notifications?: Array<{ uid?: string; id?: number; isDefault: boolean }>;
|
|
}
|
|
|
|
function setupTestContext({ notifications = [] }: Args = {}) {
|
|
const panel = {
|
|
alert: { notifications },
|
|
options: [],
|
|
title: 'Testing Alerts',
|
|
};
|
|
const $scope = {
|
|
ctrl: {
|
|
panel,
|
|
render: jest.fn(),
|
|
},
|
|
};
|
|
const dashboardSrv = {} as DashboardSrv;
|
|
const uiSegmentSrv = {};
|
|
const datasourceSrv = {} as DatasourceSrv;
|
|
|
|
const controller = new AlertTabCtrl($scope, dashboardSrv, uiSegmentSrv, datasourceSrv);
|
|
controller.notifications = notifications;
|
|
controller.alertNotifications = [];
|
|
controller.initModel();
|
|
|
|
return { controller };
|
|
}
|
|
|
|
describe('AlertTabCtrl', () => {
|
|
describe('when removeNotification is called with an uid', () => {
|
|
it('then the correct notifier should be removed', () => {
|
|
const { controller } = setupTestContext({
|
|
notifications: [
|
|
{ id: 1, uid: 'one', isDefault: true },
|
|
{ id: 2, uid: 'two', isDefault: false },
|
|
],
|
|
});
|
|
|
|
expect(controller.alert.notifications).toEqual([
|
|
{ id: 1, uid: 'one', isDefault: true, iconClass: 'bell' },
|
|
{ id: 2, uid: 'two', isDefault: false, iconClass: 'bell' },
|
|
]);
|
|
expect(controller.alertNotifications).toEqual([
|
|
{ id: 2, uid: 'two', isDefault: false, iconClass: 'bell' },
|
|
{ id: 1, uid: 'one', isDefault: true, iconClass: 'bell' },
|
|
]);
|
|
|
|
controller.removeNotification({ uid: 'one' });
|
|
|
|
expect(controller.alert.notifications).toEqual([{ id: 2, uid: 'two', isDefault: false, iconClass: 'bell' }]);
|
|
expect(controller.alertNotifications).toEqual([{ id: 2, uid: 'two', isDefault: false, iconClass: 'bell' }]);
|
|
});
|
|
});
|
|
|
|
describe('when removeNotification is called with an id', () => {
|
|
it('then the correct notifier should be removed', () => {
|
|
const { controller } = setupTestContext({
|
|
notifications: [
|
|
{ id: 1, uid: 'one', isDefault: true },
|
|
{ id: 2, uid: 'two', isDefault: false },
|
|
],
|
|
});
|
|
|
|
expect(controller.alert.notifications).toEqual([
|
|
{ id: 1, uid: 'one', isDefault: true, iconClass: 'bell' },
|
|
{ id: 2, uid: 'two', isDefault: false, iconClass: 'bell' },
|
|
]);
|
|
expect(controller.alertNotifications).toEqual([
|
|
{ id: 2, uid: 'two', isDefault: false, iconClass: 'bell' },
|
|
{ id: 1, uid: 'one', isDefault: true, iconClass: 'bell' },
|
|
]);
|
|
|
|
controller.removeNotification({ id: 2 });
|
|
|
|
expect(controller.alert.notifications).toEqual([{ id: 1, uid: 'one', isDefault: true, iconClass: 'bell' }]);
|
|
expect(controller.alertNotifications).toEqual([{ id: 1, uid: 'one', isDefault: true, iconClass: 'bell' }]);
|
|
});
|
|
});
|
|
});
|