LokiQueryEditorByApp.test.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { render, RenderResult } from '@testing-library/react';
  2. import { noop } from 'lodash';
  3. import React from 'react';
  4. import { CoreApp } from '@grafana/data';
  5. import { LokiDatasource } from '../datasource';
  6. import { testIds as exploreTestIds } from './LokiExploreQueryEditor';
  7. import { testIds as regularTestIds } from './LokiQueryEditor';
  8. import { LokiQueryEditorByApp } from './LokiQueryEditorByApp';
  9. import { testIds as alertingTestIds } from './LokiQueryEditorForAlerting';
  10. function setup(app: CoreApp): RenderResult {
  11. const dataSource = {
  12. languageProvider: {
  13. start: () => Promise.resolve([]),
  14. getSyntax: () => {},
  15. getLabelKeys: () => [],
  16. metrics: [],
  17. },
  18. } as unknown as LokiDatasource;
  19. return render(
  20. <LokiQueryEditorByApp
  21. app={app}
  22. onChange={noop}
  23. onRunQuery={noop}
  24. datasource={dataSource}
  25. query={{ refId: 'A', expr: '' }}
  26. />
  27. );
  28. }
  29. describe('LokiQueryEditorByApp', () => {
  30. it('should render simplified query editor for cloud alerting', () => {
  31. const { getByTestId, queryByTestId } = setup(CoreApp.CloudAlerting);
  32. expect(getByTestId(alertingTestIds.editor)).toBeInTheDocument();
  33. expect(queryByTestId(regularTestIds.editor)).toBeNull();
  34. });
  35. it('should render regular query editor for unkown apps', () => {
  36. const { getByTestId, queryByTestId } = setup(CoreApp.Unknown);
  37. expect(getByTestId(regularTestIds.editor)).toBeInTheDocument();
  38. expect(queryByTestId(alertingTestIds.editor)).toBeNull();
  39. });
  40. it('should render expore query editor for explore', () => {
  41. const { getByTestId, queryByTestId } = setup(CoreApp.Explore);
  42. expect(getByTestId(exploreTestIds.editor)).toBeInTheDocument();
  43. expect(queryByTestId(alertingTestIds.editor)).toBeNull();
  44. });
  45. it('should render regular query editor for dashboard', () => {
  46. const { getByTestId, queryByTestId } = setup(CoreApp.Dashboard);
  47. expect(getByTestId(regularTestIds.editor)).toBeInTheDocument();
  48. expect(queryByTestId(alertingTestIds.editor)).toBeNull();
  49. });
  50. });