2020-12-04 22:29:40 +08:00
|
|
|
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';
|
|
|
|
|
|
|
|
describe('useNextId', () => {
|
|
|
|
it('Should return the next available id', () => {
|
|
|
|
const query: ElasticsearchQuery = {
|
|
|
|
refId: 'A',
|
2021-02-24 05:58:07 +08:00
|
|
|
query: '',
|
2020-12-04 22:29:40 +08:00
|
|
|
metrics: [{ id: '1', type: 'avg' }],
|
|
|
|
bucketAggs: [{ id: '2', type: 'date_histogram' }],
|
|
|
|
};
|
|
|
|
const wrapper: FunctionComponent = ({ children }) => {
|
|
|
|
return (
|
2021-01-06 23:51:21 +08:00
|
|
|
<ElasticsearchProvider query={query} datasource={{} as any} onChange={() => {}} onRunQuery={() => {}}>
|
2020-12-04 22:29:40 +08:00
|
|
|
{children}
|
|
|
|
</ElasticsearchProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const { result } = renderHook(() => useNextId(), {
|
|
|
|
wrapper,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(result.current).toBe('3');
|
|
|
|
});
|
|
|
|
});
|