AnalyticsStatsTab.test.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { render, screen } from '@testing-library/react';
  2. import $ from 'jquery';
  3. import React from 'react';
  4. import { GrafanaTheme2 } from '@grafana/data';
  5. import { DashboardModel } from 'app/features/dashboard/state';
  6. import { getMockDailySummaries } from '../__mocks__/dailySummariesMocks';
  7. import AnalyticsStatsTab, { Props } from './AnalyticsStatsTab';
  8. jest.mock(
  9. 'react-virtualized-auto-sizer',
  10. () =>
  11. ({ children }: any) =>
  12. children({ height: 600, width: 600 })
  13. );
  14. // Mock plot to prevent graph rendering from crashing
  15. //@ts-ignore
  16. $.plot = jest.fn();
  17. beforeEach(() => {
  18. jest.clearAllMocks();
  19. });
  20. const setup = (props: Props) => {
  21. render(<AnalyticsStatsTab {...props} />);
  22. };
  23. describe('Render', () => {
  24. it('should render empty component - no data', async () => {
  25. const props: Props = {
  26. dashboard: new DashboardModel({ id: 1 }),
  27. dailySummaries: [],
  28. theme: {} as GrafanaTheme2,
  29. };
  30. setup(props);
  31. expect(screen.queryByRole('main')).not.toBeInTheDocument();
  32. expect(screen.getByText('No data.')).toBeInTheDocument();
  33. });
  34. it('should render query and error counts from daily summaries', async () => {
  35. const props: Props = {
  36. dashboard: new DashboardModel({ id: 1 }),
  37. dailySummaries: getMockDailySummaries(),
  38. theme: {} as GrafanaTheme2,
  39. };
  40. setup(props);
  41. expect(await screen.findByRole('main')).toBeInTheDocument();
  42. expect(screen.getAllByLabelText('Graph container')).toHaveLength(2);
  43. });
  44. });