mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 16:45:43 -06:00
* Moving query stuff out of dashboard folder * Moved more stuff * Moving more stuff * Update * WIP test page * Minor change * Before big changes * Fixed test
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import { DataQueryRequest, dateTime, LoadingState, PanelData, toDataFrame } 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');
|
|
});
|
|
|
|
it('should include errors when missing data', () => {
|
|
const withError = ({
|
|
series: [],
|
|
error: {
|
|
message: 'Error!!',
|
|
},
|
|
} as unknown) as PanelData;
|
|
|
|
const panelData = filterPanelDataToQuery(withError, 'B');
|
|
expect(panelData).toBeDefined();
|
|
|
|
// @ts-ignore typescript doesn't understand that panelData can't be undefined here
|
|
expect(panelData.state).toBe(LoadingState.Error);
|
|
// @ts-ignore typescript doesn't understand that panelData can't be undefined here
|
|
expect(panelData.error).toBe(withError.error);
|
|
});
|
|
});
|