TraceViewContainer.test.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { render, screen } from '@testing-library/react';
  2. import userEvent from '@testing-library/user-event';
  3. import React, { createRef } from 'react';
  4. import { Provider } from 'react-redux';
  5. import { getDefaultTimeRange, LoadingState } from '@grafana/data';
  6. import { ExploreId } from 'app/types';
  7. import { configureStore } from '../../../store/configureStore';
  8. import { frameOld } from './TraceView.test';
  9. import { TraceViewContainer } from './TraceViewContainer';
  10. jest.mock('@grafana/runtime', () => {
  11. return {
  12. ...jest.requireActual('@grafana/runtime'),
  13. reportInteraction: jest.fn(),
  14. };
  15. });
  16. function renderTraceViewContainer(frames = [frameOld]) {
  17. const store = configureStore();
  18. const mockPanelData = {
  19. state: LoadingState.Done,
  20. series: [],
  21. timeRange: getDefaultTimeRange(),
  22. };
  23. const topOfViewRef = createRef<HTMLDivElement>();
  24. const { container, baseElement } = render(
  25. <Provider store={store}>
  26. <TraceViewContainer
  27. exploreId={ExploreId.left}
  28. dataFrames={frames}
  29. splitOpenFn={() => {}}
  30. queryResponse={mockPanelData}
  31. topOfViewRef={topOfViewRef}
  32. />
  33. </Provider>
  34. );
  35. return {
  36. header: container.children[0],
  37. timeline: container.children[1],
  38. container,
  39. baseElement,
  40. };
  41. }
  42. describe('TraceViewContainer', () => {
  43. it('toggles children visibility', async () => {
  44. renderTraceViewContainer();
  45. expect(screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' }).length).toBe(3);
  46. await userEvent.click(screen.getAllByText('', { selector: 'span[data-testid="SpanTreeOffset--indentGuide"]' })[0]);
  47. expect(screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' }).length).toBe(1);
  48. await userEvent.click(screen.getAllByText('', { selector: 'span[data-testid="SpanTreeOffset--indentGuide"]' })[0]);
  49. expect(screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' }).length).toBe(3);
  50. });
  51. it('toggles collapses and expands one level of spans', async () => {
  52. renderTraceViewContainer();
  53. expect(screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' }).length).toBe(3);
  54. await userEvent.click(screen.getByLabelText('Collapse +1'));
  55. expect(screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' }).length).toBe(2);
  56. await userEvent.click(screen.getByLabelText('Expand +1'));
  57. expect(screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' }).length).toBe(3);
  58. });
  59. it('toggles collapses and expands all levels', async () => {
  60. renderTraceViewContainer();
  61. expect(screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' }).length).toBe(3);
  62. await userEvent.click(screen.getByLabelText('Collapse All'));
  63. expect(screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' }).length).toBe(1);
  64. await userEvent.click(screen.getByLabelText('Expand All'));
  65. expect(screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' }).length).toBe(3);
  66. });
  67. it('searches for spans', async () => {
  68. renderTraceViewContainer();
  69. await userEvent.type(screen.getByPlaceholderText('Find...'), '1ed38015486087ca');
  70. expect(
  71. (screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' })[0].parentNode! as HTMLElement).className
  72. ).toContain('rowMatchingFilter');
  73. });
  74. it('can select next/prev results', async () => {
  75. renderTraceViewContainer();
  76. await userEvent.type(screen.getByPlaceholderText('Find...'), 'logproto');
  77. const nextResultButton = screen.getByTestId('trace-page-search-bar-next-result-button');
  78. const prevResultButton = screen.getByTestId('trace-page-search-bar-prev-result-button');
  79. const suffix = screen.getByTestId('trace-page-search-bar-suffix');
  80. await userEvent.click(nextResultButton);
  81. expect(suffix.textContent).toBe('1 of 2');
  82. expect(
  83. (screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' })[1].parentNode! as HTMLElement).className
  84. ).toContain('rowFocused');
  85. await userEvent.click(nextResultButton);
  86. expect(suffix.textContent).toBe('2 of 2');
  87. expect(
  88. (screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' })[2].parentNode! as HTMLElement).className
  89. ).toContain('rowFocused');
  90. await userEvent.click(nextResultButton);
  91. expect(suffix.textContent).toBe('1 of 2');
  92. expect(
  93. (screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' })[1].parentNode! as HTMLElement).className
  94. ).toContain('rowFocused');
  95. await userEvent.click(prevResultButton);
  96. expect(suffix.textContent).toBe('2 of 2');
  97. expect(
  98. (screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' })[2].parentNode! as HTMLElement).className
  99. ).toContain('rowFocused');
  100. await userEvent.click(prevResultButton);
  101. expect(suffix.textContent).toBe('1 of 2');
  102. expect(
  103. (screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' })[1].parentNode! as HTMLElement).className
  104. ).toContain('rowFocused');
  105. await userEvent.click(prevResultButton);
  106. expect(suffix.textContent).toBe('2 of 2');
  107. expect(
  108. (screen.queryAllByText('', { selector: 'div[data-testid="span-view"]' })[2].parentNode! as HTMLElement).className
  109. ).toContain('rowFocused');
  110. });
  111. });