Skip to content

Commit

Permalink
wip: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinwcyu committed Mar 11, 2024
1 parent 788326f commit 76186ab
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/DatasourceWithAsyncBackend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PluginType,
getDefaultTimeRange,
} from '@grafana/data';
import { DataSourceWithBackend } from '@grafana/runtime';
import { DataSourceWithBackend, config } from '@grafana/runtime';
import { DatasourceWithAsyncBackend } from './DatasourceWithAsyncBackend';
import { RequestLoopOptions } from 'requestLooper';

Expand All @@ -18,6 +18,16 @@ jest.mock('./requestLooper.ts', () => ({
getRequestLooper: (req: DataQueryRequest, options: RequestLoopOptions) => getRequestLooperMock(req, options),
}));

jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
config: {
...jest.requireActual('@grafana/runtime').config,
buildInfo: {
version: '10.2.3',
},
},
}));

const defaultInstanceSettings: DataSourceInstanceSettings<{}> = {
id: 12,
uid: 'test',
Expand Down Expand Up @@ -71,9 +81,9 @@ const setupDatasourceWithAsyncBackend = ({
}) => new DatasourceWithAsyncBackend<DataQuery>(settings, asyncQueryDataSupport);

describe('DatasourceWithAsyncBackend', () => {
// beforeAll(() => {
// queryMock.mockClear();
// });
beforeAll(() => {
queryMock.mockClear();
});

it('can store running queries', () => {
const ds = setupDatasourceWithAsyncBackend({});
Expand Down Expand Up @@ -121,15 +131,15 @@ describe('DatasourceWithAsyncBackend', () => {
expect(queryMock).toHaveBeenCalledWith(defaultRequest);
});

it('uses the datasource id for the request id', () => {
it('uses the datasource uid for the request uid', () => {
const ds = setupDatasourceWithAsyncBackend({ asyncQueryDataSupport: true });
expect(getRequestLooperMock).not.toHaveBeenCalled();
ds.doSingle(defaultQuery, defaultRequest);
expect(getRequestLooperMock).toHaveBeenCalledTimes(1);
const expectedRequest = {
...defaultRequest,
targets: [defaultQuery],
requestId: '12_100',
requestId: 'test_100',
};
expect(getRequestLooperMock).toHaveBeenCalledWith(expectedRequest, expect.anything());
});
Expand Down

0 comments on commit 76186ab

Please sign in to comment.