mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06: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
105 lines
3.2 KiB
TypeScript
105 lines
3.2 KiB
TypeScript
import { TestScheduler } from 'rxjs/testing';
|
|
|
|
import { AlertState, getDefaultTimeRange, LoadingState, PanelData, toDataFrame } from '@grafana/data';
|
|
|
|
import { mergePanelAndDashData } from './mergePanelAndDashData';
|
|
|
|
function getTestContext() {
|
|
const timeRange = getDefaultTimeRange();
|
|
const panelData: PanelData = {
|
|
state: LoadingState.Done,
|
|
series: [],
|
|
annotations: [toDataFrame([{ id: 'panelData' }])],
|
|
timeRange,
|
|
};
|
|
const scheduler: TestScheduler = new TestScheduler((actual, expected) => {
|
|
expect(actual).toEqual(expected);
|
|
});
|
|
|
|
return { timeRange, scheduler, panelData };
|
|
}
|
|
|
|
describe('mergePanelAndDashboardData', () => {
|
|
describe('when called and dashboard data contains annotations', () => {
|
|
it('then the annotations should be combined', () => {
|
|
const { panelData, timeRange, scheduler } = getTestContext();
|
|
|
|
scheduler.run(({ cold, expectObservable }) => {
|
|
const panelObservable = cold('a', { a: panelData });
|
|
const dashObservable = cold('a', { a: { annotations: [{ id: 'dashData' }] } });
|
|
|
|
const result = mergePanelAndDashData(panelObservable, dashObservable);
|
|
|
|
expectObservable(result).toBe('a', {
|
|
a: {
|
|
state: LoadingState.Done,
|
|
series: [],
|
|
annotations: [toDataFrame([{ id: 'panelData' }]), toDataFrame([{ id: 'dashData' }])],
|
|
timeRange,
|
|
},
|
|
});
|
|
});
|
|
|
|
scheduler.flush();
|
|
});
|
|
});
|
|
|
|
describe('when called and dashboard data contains alert states', () => {
|
|
it('then the alert states should be added', () => {
|
|
const { panelData, timeRange, scheduler } = getTestContext();
|
|
|
|
scheduler.run(({ cold, expectObservable }) => {
|
|
const panelObservable = cold('a', { a: panelData });
|
|
const dashObservable = cold('a', {
|
|
a: {
|
|
annotations: [],
|
|
alertState: { id: 1, state: AlertState.OK, dashboardId: 1, panelId: 1, newStateDate: '' },
|
|
},
|
|
});
|
|
|
|
const result = mergePanelAndDashData(panelObservable, dashObservable);
|
|
|
|
expectObservable(result).toBe('a', {
|
|
a: {
|
|
state: LoadingState.Done,
|
|
series: [],
|
|
annotations: [toDataFrame([{ id: 'panelData' }]), toDataFrame([])],
|
|
alertState: { id: 1, state: AlertState.OK, dashboardId: 1, panelId: 1, newStateDate: '' },
|
|
timeRange,
|
|
},
|
|
});
|
|
});
|
|
|
|
scheduler.flush();
|
|
});
|
|
});
|
|
|
|
describe('when called and dashboard data does not contain annotations or alertState', () => {
|
|
it('then the panelData is unchanged', () => {
|
|
const { panelData, timeRange, scheduler } = getTestContext();
|
|
|
|
scheduler.run(({ cold, expectObservable }) => {
|
|
const panelObservable = cold('a', { a: panelData });
|
|
const dashObservable = cold('a', {
|
|
a: {
|
|
annotations: [],
|
|
},
|
|
});
|
|
|
|
const result = mergePanelAndDashData(panelObservable, dashObservable);
|
|
|
|
expectObservable(result).toBe('a', {
|
|
a: {
|
|
state: LoadingState.Done,
|
|
series: [],
|
|
annotations: [toDataFrame([{ id: 'panelData' }])],
|
|
timeRange,
|
|
},
|
|
});
|
|
});
|
|
|
|
scheduler.flush();
|
|
});
|
|
});
|
|
});
|