Files
grafana/public/app/features/alerting/unified/api/annotations.test.ts
Josh Hunt 3c6e0e8ef8 Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

65 lines
1.9 KiB
TypeScript

import '@grafana/runtime';
import { StateHistoryItem } from 'app/types/unified-alerting';
import { fetchAnnotations, sortStateHistory } from './annotations';
const get = jest.fn(() => {
return new Promise((resolve) => {
resolve(undefined);
});
});
jest.mock('@grafana/runtime', () => ({
getBackendSrv: () => ({
get,
}),
}));
describe('annotations', () => {
beforeEach(() => get.mockClear());
it('should fetch annotation for an alertId', () => {
const ALERT_ID = 'abc123';
fetchAnnotations(ALERT_ID);
expect(get).toBeCalledWith('/api/annotations', { alertId: ALERT_ID });
});
});
describe(sortStateHistory, () => {
describe('should stably sort', () => {
describe('when timeEnd is different', () => {
it('should not sort by rule id', () => {
let data: StateHistoryItem[] = [
{ timeEnd: 23, time: 22, id: 1 } as StateHistoryItem,
{ timeEnd: 22, time: 21, id: 3 } as StateHistoryItem,
{ timeEnd: 22, time: 22, id: 2 } as StateHistoryItem,
{ timeEnd: 24, id: 3 } as StateHistoryItem,
];
data.sort(sortStateHistory);
expect(data[0].timeEnd).toBe(24);
expect(data[1].timeEnd).toBe(23);
expect(data[2].time).toBe(22);
expect(data[3].id).toBe(3);
});
});
describe('when only the rule id is different', () => {
it('should sort by rule id', () => {
let data: StateHistoryItem[] = [
{ timeEnd: 23, time: 22, id: 1 } as StateHistoryItem,
{ timeEnd: 23, time: 22, id: 3 } as StateHistoryItem,
{ timeEnd: 23, time: 22, id: 2 } as StateHistoryItem,
{ timeEnd: 23, time: 22, id: 6 } as StateHistoryItem,
];
data.sort(sortStateHistory);
expect(data[0].id).toBe(6);
expect(data[1].id).toBe(3);
expect(data[2].id).toBe(2);
expect(data[3].id).toBe(1);
});
});
});
});