mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
Primarily- moving majority of the types and utils from @grafana/ui to @grafana/data * Move types from grafana-ui to grafana-data * Move valueFormats to grafana-data * Move utils from grafana-ui to grafana-data * Update imports in grafana-ui * revert data's tsconfig change * Update imports in grafana-runtime * Fix import paths in grafana-ui * Move rxjs to devDeps * Core import updates batch 1 * Import updates batch 2 * Imports fix batch 3 * Imports fixes batch i don't know * Fix imorts in grafana-toolkit * Fix imports after master merge
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { LoadingState, toDataFrame, dateTime, PanelData, DataQueryRequest } from '@grafana/data';
|
|
import { filterPanelDataToQuery } from './QueryEditorRow';
|
|
|
|
function makePretendRequest(requestId: string, subRequests?: DataQueryRequest[]): DataQueryRequest {
|
|
return {
|
|
requestId,
|
|
// subRequests,
|
|
} as DataQueryRequest;
|
|
}
|
|
|
|
describe('filterPanelDataToQuery', () => {
|
|
const data: PanelData = {
|
|
state: LoadingState.Done,
|
|
series: [
|
|
toDataFrame({ refId: 'A', fields: [{ name: 'AAA' }], meta: {} }),
|
|
toDataFrame({ refId: 'B', fields: [{ name: 'B111' }], meta: {} }),
|
|
toDataFrame({ refId: 'B', fields: [{ name: 'B222' }], meta: {} }),
|
|
toDataFrame({ refId: 'B', fields: [{ name: 'B333' }], meta: {} }),
|
|
toDataFrame({ refId: 'C', fields: [{ name: 'CCCC' }], meta: { requestId: 'sub3' } }),
|
|
],
|
|
error: {
|
|
refId: 'B',
|
|
message: 'Error!!',
|
|
},
|
|
request: makePretendRequest('111', [
|
|
makePretendRequest('sub1'),
|
|
makePretendRequest('sub2'),
|
|
makePretendRequest('sub3'),
|
|
]),
|
|
timeRange: { from: dateTime(), to: dateTime(), raw: { from: 'now-1d', to: 'now' } },
|
|
};
|
|
|
|
it('should not have an error unless the refId matches', () => {
|
|
const panelData = filterPanelDataToQuery(data, 'A');
|
|
expect(panelData.series.length).toBe(1);
|
|
expect(panelData.series[0].refId).toBe('A');
|
|
expect(panelData.error).toBeUndefined();
|
|
});
|
|
|
|
it('should match the error to the query', () => {
|
|
const panelData = filterPanelDataToQuery(data, 'B');
|
|
expect(panelData.series.length).toBe(3);
|
|
expect(panelData.series[0].refId).toBe('B');
|
|
expect(panelData.error!.refId).toBe('B');
|
|
});
|
|
});
|