render.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { render } from '@testing-library/react';
  2. import React, { ComponentProps, ReactNode } from 'react';
  3. import { getDefaultTimeRange } from '@grafana/data';
  4. import { ElasticsearchProvider } from '../components/QueryEditor/ElasticsearchQueryContext';
  5. import { ElasticDatasource } from '../datasource';
  6. const defaultProviderProps = {
  7. datasource: {} as ElasticDatasource,
  8. query: { refId: 'A' },
  9. onChange: () => void 0,
  10. onRunQuery: () => void 0,
  11. range: getDefaultTimeRange(),
  12. };
  13. export const renderWithESProvider = (
  14. ui: ReactNode,
  15. {
  16. providerProps: {
  17. datasource = defaultProviderProps.datasource,
  18. query = defaultProviderProps.query,
  19. onChange = defaultProviderProps.onChange,
  20. onRunQuery = defaultProviderProps.onRunQuery,
  21. range = defaultProviderProps.range,
  22. } = defaultProviderProps,
  23. ...renderOptions
  24. }: { providerProps?: Partial<Omit<ComponentProps<typeof ElasticsearchProvider>, 'children'>> } & Parameters<
  25. typeof render
  26. >[1] = { providerProps: defaultProviderProps }
  27. ) => {
  28. return render(
  29. <ElasticsearchProvider
  30. query={query}
  31. onChange={onChange}
  32. datasource={datasource}
  33. onRunQuery={onRunQuery}
  34. range={range}
  35. >
  36. {ui}
  37. </ElasticsearchProvider>,
  38. renderOptions
  39. );
  40. };