The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/query/state/updateQueries.test.ts

103 lines
2.3 KiB

import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend';
import { updateQueries } from './updateQueries';
describe('updateQueries', () => {
it('Should update all queries except expression query when changing data source with same type', () => {
const updated = updateQueries(
{
uid: 'new-uid',
type: 'same-type',
meta: {},
} as any,
[
{
refId: 'A',
datasource: {
uid: 'old-uid',
type: 'same-type',
},
},
{
refId: 'B',
datasource: ExpressionDatasourceRef,
},
],
{
uid: 'old-uid',
type: 'same-type',
} as any
);
expect(updated[0].datasource).toEqual({ type: 'same-type', uid: 'new-uid' });
expect(updated[1].datasource).toEqual(ExpressionDatasourceRef);
});
it('Should clear queries when changing type', () => {
const updated = updateQueries(
{
uid: 'new-uid',
type: 'new-type',
meta: {},
} as any,
[
{
refId: 'A',
datasource: {
uid: 'old-uid',
type: 'old-type',
},
},
{
refId: 'B',
datasource: {
uid: 'old-uid',
type: 'old-type',
},
},
],
{
uid: 'old-uid',
type: 'old-type',
} as any
);
expect(updated.length).toEqual(1);
expect(updated[0].datasource).toEqual({ type: 'new-type', uid: 'new-uid' });
});
it('Should preserve query data source when changing to mixed', () => {
const updated = updateQueries(
{
uid: 'mixed',
type: 'mixed',
meta: {
mixed: true,
},
} as any,
[
{
refId: 'A',
datasource: {
uid: 'old-uid',
type: 'old-type',
},
},
{
refId: 'B',
datasource: {
uid: 'other-uid',
type: 'other-type',
},
},
],
{
uid: 'old-uid',
type: 'old-type',
} as any
);
expect(updated[0].datasource).toEqual({ type: 'old-type', uid: 'old-uid' });
expect(updated[1].datasource).toEqual({ type: 'other-type', uid: 'other-uid' });
});
});