mirror of
https://github.com/grafana/grafana.git
synced 2025-09-19 21:24:56 +08:00

* 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
65 lines
1.9 KiB
TypeScript
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);
|
|
});
|
|
});
|
|
});
|
|
});
|