functionsTable.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import {ReactElement, useEffect} from 'react';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {FunctionsTable} from 'sentry/components/profiling/suspectFunctions/functionsTable';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. const project = TestStubs.Project();
  6. function TestContext({children}: {children: ReactElement}) {
  7. useEffect(() => {
  8. ProjectsStore.loadInitialData([project]);
  9. return () => ProjectsStore.reset();
  10. }, []);
  11. return children;
  12. }
  13. describe('FunctionsTable', function () {
  14. it('renders loading', function () {
  15. render(
  16. <TestContext>
  17. <FunctionsTable
  18. analyticsPageSource="profiling_transaction"
  19. isLoading
  20. error={null}
  21. functions={[]}
  22. project={project}
  23. sort="p99"
  24. />
  25. </TestContext>
  26. );
  27. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  28. });
  29. it('renders empty data', function () {
  30. render(
  31. <TestContext>
  32. <FunctionsTable
  33. analyticsPageSource="profiling_transaction"
  34. isLoading={false}
  35. error={null}
  36. functions={[]}
  37. project={project}
  38. sort="-p99"
  39. />
  40. </TestContext>
  41. );
  42. expect(screen.getByText('No results found for your query')).toBeInTheDocument();
  43. });
  44. it('renders one function', function () {
  45. const func = {
  46. count: 10,
  47. examples: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
  48. fingerprint: 1234,
  49. name: 'foo',
  50. p75: 10000000,
  51. p95: 12000000,
  52. p99: 12500000,
  53. package: 'bar',
  54. path: 'baz',
  55. worst: 'cccccccccccccccccccccccccccccccc',
  56. };
  57. render(
  58. <TestContext>
  59. <FunctionsTable
  60. analyticsPageSource="profiling_transaction"
  61. isLoading={false}
  62. error={null}
  63. functions={[func]}
  64. project={project}
  65. sort="-p99"
  66. />
  67. </TestContext>
  68. );
  69. expect(screen.getByText('Name')).toBeInTheDocument();
  70. expect(screen.getByText('foo')).toBeInTheDocument();
  71. expect(screen.getByText('Package')).toBeInTheDocument();
  72. expect(screen.getByText('bar')).toBeInTheDocument();
  73. expect(screen.getByText('Total Occurrences')).toBeInTheDocument();
  74. expect(screen.getByText('10')).toBeInTheDocument();
  75. expect(screen.getByText('P75 Total Duration')).toBeInTheDocument();
  76. expect(screen.getByText('10.00ms')).toBeInTheDocument();
  77. expect(screen.getByText('P99 Total Duration')).toBeInTheDocument();
  78. expect(screen.getByText('12.50ms')).toBeInTheDocument();
  79. });
  80. it('renders empty name', function () {
  81. const func = {
  82. count: 10,
  83. examples: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
  84. fingerprint: 1234,
  85. name: '',
  86. p75: 10000000,
  87. p95: 12000000,
  88. p99: 12500000,
  89. package: 'bar',
  90. path: 'baz',
  91. worst: 'cccccccccccccccccccccccccccccccc',
  92. };
  93. render(
  94. <TestContext>
  95. <FunctionsTable
  96. analyticsPageSource="profiling_transaction"
  97. isLoading={false}
  98. error={null}
  99. functions={[func]}
  100. project={project}
  101. sort="-p99"
  102. />
  103. </TestContext>
  104. );
  105. expect(screen.getByText('Name')).toBeInTheDocument();
  106. expect(screen.getByText('Unknown')).toBeInTheDocument();
  107. expect(screen.getByText('Package')).toBeInTheDocument();
  108. expect(screen.getByText('bar')).toBeInTheDocument();
  109. });
  110. it('renders empty package', function () {
  111. const func = {
  112. count: 10,
  113. examples: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
  114. fingerprint: 1234,
  115. name: 'foo',
  116. p75: 10000000,
  117. p95: 12000000,
  118. p99: 12500000,
  119. package: '',
  120. path: 'baz',
  121. worst: 'cccccccccccccccccccccccccccccccc',
  122. };
  123. render(
  124. <TestContext>
  125. <FunctionsTable
  126. analyticsPageSource="profiling_transaction"
  127. isLoading={false}
  128. error={null}
  129. functions={[func]}
  130. project={project}
  131. sort="-p99"
  132. />
  133. </TestContext>
  134. );
  135. expect(screen.getByText('Name')).toBeInTheDocument();
  136. expect(screen.getByText('foo')).toBeInTheDocument();
  137. expect(screen.getByText('Package')).toBeInTheDocument();
  138. expect(screen.getByText('Unknown')).toBeInTheDocument();
  139. });
  140. });