|
|
@ -42,7 +42,8 @@ jest.mock('../services', () => ({ |
|
|
|
|
|
|
|
|
|
|
|
describe('DataSourceWithBackend', () => { |
|
|
|
describe('DataSourceWithBackend', () => { |
|
|
|
test('check the executed queries', () => { |
|
|
|
test('check the executed queries', () => { |
|
|
|
const mock = runQueryAndReturnFetchMock({ |
|
|
|
const { mock, ds } = createMockDatasource(); |
|
|
|
|
|
|
|
ds.query({ |
|
|
|
maxDataPoints: 10, |
|
|
|
maxDataPoints: 10, |
|
|
|
intervalMs: 5000, |
|
|
|
intervalMs: 5000, |
|
|
|
targets: [{ refId: 'A' }, { refId: 'B', datasource: { type: 'sample' } }], |
|
|
|
targets: [{ refId: 'A' }, { refId: 'B', datasource: { type: 'sample' } }], |
|
|
@ -93,8 +94,22 @@ describe('DataSourceWithBackend', () => { |
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should apply template variables only for the current data source', () => { |
|
|
|
|
|
|
|
const { mock, ds } = createMockDatasource(); |
|
|
|
|
|
|
|
ds.applyTemplateVariables = jest.fn(); |
|
|
|
|
|
|
|
ds.query({ |
|
|
|
|
|
|
|
maxDataPoints: 10, |
|
|
|
|
|
|
|
intervalMs: 5000, |
|
|
|
|
|
|
|
targets: [{ refId: 'A' }, { refId: 'B', datasource: { type: 'sample' } }], |
|
|
|
|
|
|
|
} as DataQueryRequest); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(mock.calls.length).toBe(1); |
|
|
|
|
|
|
|
expect(ds.applyTemplateVariables).toHaveBeenCalledTimes(1); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('check that the executed queries is hidden from inspector', () => { |
|
|
|
test('check that the executed queries is hidden from inspector', () => { |
|
|
|
const mock = runQueryAndReturnFetchMock({ |
|
|
|
const { mock, ds } = createMockDatasource(); |
|
|
|
|
|
|
|
ds.query({ |
|
|
|
maxDataPoints: 10, |
|
|
|
maxDataPoints: 10, |
|
|
|
intervalMs: 5000, |
|
|
|
intervalMs: 5000, |
|
|
|
targets: [{ refId: 'A' }, { refId: 'B', datasource: { type: 'sample' } }], |
|
|
|
targets: [{ refId: 'A' }, { refId: 'B', datasource: { type: 'sample' } }], |
|
|
@ -169,9 +184,7 @@ describe('DataSourceWithBackend', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
function runQueryAndReturnFetchMock( |
|
|
|
function createMockDatasource() { |
|
|
|
request: DataQueryRequest |
|
|
|
|
|
|
|
): jest.MockContext<Promise<FetchResponse>, BackendSrvRequest[]> { |
|
|
|
|
|
|
|
const settings = { |
|
|
|
const settings = { |
|
|
|
name: 'test', |
|
|
|
name: 'test', |
|
|
|
id: 1234, |
|
|
|
id: 1234, |
|
|
@ -184,7 +197,5 @@ function runQueryAndReturnFetchMock( |
|
|
|
mockDatasourceRequest.mockReturnValue(Promise.resolve({} as FetchResponse)); |
|
|
|
mockDatasourceRequest.mockReturnValue(Promise.resolve({} as FetchResponse)); |
|
|
|
|
|
|
|
|
|
|
|
const ds = new MyDataSource(settings); |
|
|
|
const ds = new MyDataSource(settings); |
|
|
|
ds.query(request); |
|
|
|
return { ds, mock: mockDatasourceRequest.mock }; |
|
|
|
|
|
|
|
|
|
|
|
return mockDatasourceRequest.mock; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|