InspectDataTab.test.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { render, screen } from '@testing-library/react';
  2. import userEvent from '@testing-library/user-event';
  3. import React, { ComponentProps } from 'react';
  4. import { DataFrame, FieldType } from '@grafana/data';
  5. import { InspectDataTab } from './InspectDataTab';
  6. // the mock below gets rid of this warning from recompose:
  7. // Warning: React.createFactory() is deprecated and will be removed in a future major release. Consider using JSX or use React.createElement() directly instead.
  8. jest.mock('@jaegertracing/jaeger-ui-components', () => ({}));
  9. const createProps = (propsOverride?: Partial<ComponentProps<typeof InspectDataTab>>) => {
  10. const defaultProps = {
  11. isLoading: false,
  12. options: {
  13. withTransforms: false,
  14. withFieldConfig: false,
  15. },
  16. data: [
  17. {
  18. name: 'First data frame',
  19. fields: [
  20. { name: 'time', type: FieldType.time, values: [100, 200, 300] },
  21. { name: 'name', type: FieldType.string, values: ['uniqueA', 'b', 'c'] },
  22. { name: 'value', type: FieldType.number, values: [1, 2, 3] },
  23. ],
  24. length: 3,
  25. },
  26. {
  27. name: 'Second data frame',
  28. fields: [
  29. { name: 'time', type: FieldType.time, values: [400, 500, 600] },
  30. { name: 'name', type: FieldType.string, values: ['d', 'e', 'g'] },
  31. { name: 'value', type: FieldType.number, values: [4, 5, 6] },
  32. ],
  33. length: 3,
  34. },
  35. ],
  36. };
  37. return Object.assign(defaultProps, propsOverride) as ComponentProps<typeof InspectDataTab>;
  38. };
  39. describe('InspectDataTab', () => {
  40. describe('when panel is not passed as prop (Explore)', () => {
  41. it('should render InspectDataTab', () => {
  42. render(<InspectDataTab {...createProps()} />);
  43. expect(screen.getByLabelText(/Panel inspector Data content/i)).toBeInTheDocument();
  44. });
  45. it('should render Data Option row', () => {
  46. render(<InspectDataTab {...createProps()} />);
  47. expect(screen.getByText(/Data options/i)).toBeInTheDocument();
  48. });
  49. it('should show available options', async () => {
  50. render(<InspectDataTab {...createProps()} />);
  51. const dataOptions = screen.getByText(/Data options/i);
  52. await userEvent.click(dataOptions);
  53. expect(screen.getByText(/Show data frame/i)).toBeInTheDocument();
  54. expect(screen.getByText(/Download for Excel/i)).toBeInTheDocument();
  55. });
  56. it('should show available dataFrame options', async () => {
  57. render(<InspectDataTab {...createProps()} />);
  58. const dataOptions = screen.getByText(/Data options/i);
  59. await userEvent.click(dataOptions);
  60. const dataFrameInput = screen.getByRole('combobox', { name: /Select dataframe/i });
  61. await userEvent.click(dataFrameInput);
  62. expect(screen.getByText(/Second data frame/i)).toBeInTheDocument();
  63. });
  64. it('should show download logs button if logs data', () => {
  65. const dataWithLogs = [
  66. {
  67. name: 'Data frame with logs',
  68. fields: [
  69. { name: 'time', type: FieldType.time, values: [100, 200, 300] },
  70. { name: 'name', type: FieldType.string, values: ['uniqueA', 'b', 'c'] },
  71. { name: 'value', type: FieldType.number, values: [1, 2, 3] },
  72. ],
  73. length: 3,
  74. meta: {
  75. preferredVisualisationType: 'logs',
  76. },
  77. },
  78. ] as unknown as DataFrame[];
  79. render(<InspectDataTab {...createProps({ data: dataWithLogs })} />);
  80. expect(screen.getByText(/Download logs/i)).toBeInTheDocument();
  81. });
  82. it('should not show download logs button if no logs data', () => {
  83. render(<InspectDataTab {...createProps()} />);
  84. expect(screen.queryByText(/Download logs/i)).not.toBeInTheDocument();
  85. });
  86. it('should show download traces button if traces data', () => {
  87. const dataWithtraces = [
  88. {
  89. name: 'Data frame with traces',
  90. fields: [
  91. { name: 'traceID', values: ['3fa414edcef6ad90', '3fa414edcef6ad90'] },
  92. { name: 'spanID', values: ['3fa414edcef6ad90', '0f5c1808567e4403'] },
  93. { name: 'parentSpanID', values: [undefined, '3fa414edcef6ad90'] },
  94. { name: 'operationName', values: ['HTTP GET - api_traces_traceid', '/tempopb.Querier/FindTraceByID'] },
  95. { name: 'serviceName', values: ['tempo-querier', 'tempo-querier'] },
  96. {
  97. name: 'serviceTags',
  98. values: [
  99. [
  100. { key: 'cluster', type: 'string', value: 'ops-tools1' },
  101. { key: 'container', type: 'string', value: 'tempo-query' },
  102. ],
  103. [
  104. { key: 'cluster', type: 'string', value: 'ops-tools1' },
  105. { key: 'container', type: 'string', value: 'tempo-query' },
  106. ],
  107. ],
  108. },
  109. { name: 'startTime', values: [1605873894680.409, 1605873894680.587] },
  110. { name: 'duration', values: [1049.141, 1.847] },
  111. { name: 'logs', values: [[], []] },
  112. {
  113. name: 'tags',
  114. values: [
  115. [
  116. { key: 'sampler.type', type: 'string', value: 'probabilistic' },
  117. { key: 'sampler.param', type: 'float64', value: 1 },
  118. ],
  119. [
  120. { key: 'component', type: 'string', value: 'gRPC' },
  121. { key: 'span.kind', type: 'string', value: 'client' },
  122. ],
  123. ],
  124. },
  125. { name: 'warnings', values: [undefined, undefined] },
  126. { name: 'stackTraces', values: [undefined, undefined] },
  127. ],
  128. length: 2,
  129. meta: {
  130. preferredVisualisationType: 'trace',
  131. custom: {
  132. traceFormat: 'jaeger',
  133. },
  134. },
  135. },
  136. ] as unknown as DataFrame[];
  137. render(<InspectDataTab {...createProps({ data: dataWithtraces })} />);
  138. expect(screen.getByText(/Download traces/i)).toBeInTheDocument();
  139. });
  140. it('should not show download traces button if no traces data', () => {
  141. render(<InspectDataTab {...createProps()} />);
  142. expect(screen.queryByText(/Download traces/i)).not.toBeInTheDocument();
  143. });
  144. });
  145. });