Files
Kian Eliasi e3c50f0cd6 Chore: Remove any from public/app/plugins/datasource/elasticsearch/hooks/useNextId.test.tsx (#53427)
* Remove any from public/app/plugins/datasource/elasticsearch/hooks/useNextId.test.tsx

* Fix lint and update betterer results
2022-08-10 09:25:35 +02:00

41 lines
1.1 KiB
TypeScript

import { renderHook } from '@testing-library/react-hooks';
import React, { PropsWithChildren } from 'react';
import { getDefaultTimeRange } from '@grafana/data';
import { ElasticsearchProvider } from '../components/QueryEditor/ElasticsearchQueryContext';
import { ElasticDatasource } from '../datasource';
import { ElasticsearchQuery } from '../types';
import { useNextId } from './useNextId';
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 = ({ children }: PropsWithChildren<{}>) => {
return (
<ElasticsearchProvider
query={query}
datasource={{} as ElasticDatasource}
onChange={() => {}}
onRunQuery={() => {}}
range={getDefaultTimeRange()}
>
{children}
</ElasticsearchProvider>
);
};
const { result } = renderHook(() => useNextId(), {
wrapper,
});
expect(result.current).toBe('3');
});
});