functionsTable.spec.tsx 4.7 KB

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