functionsTable.spec.tsx 4.0 KB

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