NodeGraphContainer.test.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { getDefaultTimeRange, MutableDataFrame } from '@grafana/data';
  4. import { ExploreId } from '../../types';
  5. import { UnconnectedNodeGraphContainer } from './NodeGraphContainer';
  6. describe('NodeGraphContainer', () => {
  7. it('is collapsed if shown with traces', () => {
  8. const { container } = render(
  9. <UnconnectedNodeGraphContainer
  10. dataFrames={[emptyFrame]}
  11. exploreId={ExploreId.left}
  12. range={getDefaultTimeRange()}
  13. splitOpen={(() => {}) as any}
  14. withTraceView={true}
  15. datasourceType={''}
  16. />
  17. );
  18. // Make sure we only show header in the collapsible
  19. expect(container.firstChild?.childNodes.length).toBe(1);
  20. });
  21. it('shows the graph if not with trace view', async () => {
  22. const { container } = render(
  23. <UnconnectedNodeGraphContainer
  24. dataFrames={[nodes]}
  25. exploreId={ExploreId.left}
  26. range={getDefaultTimeRange()}
  27. splitOpen={(() => {}) as any}
  28. datasourceType={''}
  29. />
  30. );
  31. expect(container.firstChild?.childNodes.length).toBe(2);
  32. expect(container.querySelector('svg')).toBeInTheDocument();
  33. await screen.findByLabelText(/Node: tempo-querier/);
  34. });
  35. });
  36. const emptyFrame = new MutableDataFrame();
  37. const nodes = new MutableDataFrame({
  38. fields: toFields([
  39. ['id', ['3fa414edcef6ad90']],
  40. ['title', ['tempo-querier']],
  41. ['subTitle', ['HTTP GET - api_traces_traceid']],
  42. ['mainStat', ['1049.14ms (100%)']],
  43. ['secondaryStat', ['1047.29ms (99.82%)']],
  44. ['color', [0.9982395121342127]],
  45. ]),
  46. });
  47. function toFields(fields: Array<[string, any[]]>) {
  48. return fields.map(([name, values]) => {
  49. return { name, values };
  50. });
  51. }