LokiQueryBuilderContainer.test.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { addOperation } from 'app/plugins/datasource/prometheus/querybuilder/shared/OperationList.testUtils';
  4. import { LokiDatasource } from '../../datasource';
  5. import { LokiQueryBuilderContainer } from './LokiQueryBuilderContainer';
  6. describe('LokiQueryBuilderContainer', () => {
  7. it('translates query between string and model', async () => {
  8. const props = {
  9. query: {
  10. expr: '{job="testjob"}',
  11. refId: 'A',
  12. },
  13. datasource: new LokiDatasource(
  14. {
  15. id: 1,
  16. uid: '',
  17. type: 'loki',
  18. name: 'loki-test',
  19. access: 'proxy',
  20. url: '',
  21. jsonData: {},
  22. meta: {} as any,
  23. },
  24. undefined,
  25. undefined
  26. ),
  27. onChange: jest.fn(),
  28. onRunQuery: () => {},
  29. showRawQuery: true,
  30. };
  31. render(<LokiQueryBuilderContainer {...props} />);
  32. expect(screen.getByText('testjob')).toBeInTheDocument();
  33. await addOperation('Range functions', 'Rate');
  34. expect(props.onChange).toBeCalledWith({
  35. expr: 'rate({job="testjob"} [$__interval])',
  36. refId: 'A',
  37. });
  38. });
  39. });