mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Elasticsearch: Allow omitting field when metric supports inline script * Add tests for MetricEditor to show a None option * Add tests for useFields hook * Alerting: allow elasticsearch metrics without field
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import React, { FunctionComponent } from 'react';
|
|
import { renderHook } from '@testing-library/react-hooks';
|
|
import { ElasticsearchProvider } from '../components/QueryEditor/ElasticsearchQueryContext';
|
|
import { useNextId } from './useNextId';
|
|
import { ElasticsearchQuery } from '../types';
|
|
import { getDefaultTimeRange } from '@grafana/data';
|
|
|
|
describe('useNextId', () => {
|
|
it('Should return the next available id', () => {
|
|
const query: ElasticsearchQuery = {
|
|
refId: 'A',
|
|
query: '',
|
|
metrics: [{ id: '1', type: 'avg' }],
|
|
bucketAggs: [{ id: '2', type: 'date_histogram' }],
|
|
};
|
|
const wrapper: FunctionComponent = ({ children }) => {
|
|
return (
|
|
<ElasticsearchProvider
|
|
query={query}
|
|
datasource={{} as any}
|
|
onChange={() => {}}
|
|
onRunQuery={() => {}}
|
|
range={getDefaultTimeRange()}
|
|
>
|
|
{children}
|
|
</ElasticsearchProvider>
|
|
);
|
|
};
|
|
|
|
const { result } = renderHook(() => useNextId(), {
|
|
wrapper,
|
|
});
|
|
|
|
expect(result.current).toBe('3');
|
|
});
|
|
});
|