LogsVolumePanel.test.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { DataQueryResponse, LoadingState } from '@grafana/data';
  4. import { LogsVolumePanel } from './LogsVolumePanel';
  5. jest.mock('./ExploreGraph', () => {
  6. const ExploreGraph = () => <span>ExploreGraph</span>;
  7. return {
  8. ExploreGraph,
  9. };
  10. });
  11. function renderPanel(logsVolumeData?: DataQueryResponse) {
  12. render(
  13. <LogsVolumePanel
  14. absoluteRange={{ from: 0, to: 1 }}
  15. timeZone="timeZone"
  16. splitOpen={() => {}}
  17. width={100}
  18. onUpdateTimeRange={() => {}}
  19. logsVolumeData={logsVolumeData}
  20. onLoadLogsVolume={() => {}}
  21. />
  22. );
  23. }
  24. describe('LogsVolumePanel', () => {
  25. it('shows loading message', () => {
  26. renderPanel({ state: LoadingState.Loading, error: undefined, data: [] });
  27. expect(screen.getByText('Log volume is loading...')).toBeInTheDocument();
  28. });
  29. it('shows no volume data', () => {
  30. renderPanel({ state: LoadingState.Done, error: undefined, data: [] });
  31. expect(screen.getByText('No volume data.')).toBeInTheDocument();
  32. });
  33. it('renders logs volume histogram graph', () => {
  34. renderPanel({ state: LoadingState.Done, error: undefined, data: [{}] });
  35. expect(screen.getByText('ExploreGraph')).toBeInTheDocument();
  36. });
  37. it('shows short warning message', () => {
  38. renderPanel({ state: LoadingState.Error, error: { data: { message: 'Test error message' } }, data: [] });
  39. expect(screen.getByText('Failed to load log volume for this query')).toBeInTheDocument();
  40. expect(screen.getByText('Test error message')).toBeInTheDocument();
  41. });
  42. it('shows long warning message', () => {
  43. // we make a long message
  44. const messagePart = 'One two three four five six seven eight nine ten.';
  45. const message = messagePart + ' ' + messagePart + ' ' + messagePart;
  46. renderPanel({ state: LoadingState.Error, error: { data: { message } }, data: [] });
  47. expect(screen.getByText('Failed to load log volume for this query')).toBeInTheDocument();
  48. expect(screen.queryByText(message)).not.toBeInTheDocument();
  49. const button = screen.getByText('Show details');
  50. button.click();
  51. expect(screen.getByText(message)).toBeInTheDocument();
  52. });
  53. it('does not show the panel when there is no volume data', () => {
  54. renderPanel(undefined);
  55. expect(screen.queryByText('Log volume')).not.toBeInTheDocument();
  56. });
  57. });