functionsTable.spec.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import {ReactElement, useEffect, useMemo} from 'react';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {FunctionsTable} from 'sentry/components/profiling/functionsTable';
  5. import {LegacyFunctionsTable} from 'sentry/components/profiling/legacyFunctionsTable';
  6. import ProjectsStore from 'sentry/stores/projectsStore';
  7. import {OrganizationContext} from 'sentry/views/organizationContext';
  8. import {RouteContext} from 'sentry/views/routeContext';
  9. const organization = TestStubs.Organization();
  10. const project = TestStubs.Project();
  11. function TestContext({children}: {children: ReactElement}) {
  12. const {router} = useMemo(() => initializeOrg({organization, project} as any), []);
  13. useEffect(() => {
  14. ProjectsStore.loadInitialData([project]);
  15. return () => ProjectsStore.reset();
  16. }, []);
  17. return (
  18. <RouteContext.Provider
  19. value={{
  20. router,
  21. location: router.location,
  22. params: {},
  23. routes: [],
  24. }}
  25. >
  26. <OrganizationContext.Provider value={organization}>
  27. {children}
  28. </OrganizationContext.Provider>
  29. </RouteContext.Provider>
  30. );
  31. }
  32. describe('FunctionsTable', function () {
  33. it('renders loading', function () {
  34. render(
  35. <TestContext>
  36. <FunctionsTable
  37. isLoading
  38. error={null}
  39. functions={[]}
  40. project={project}
  41. sort="p99"
  42. />
  43. </TestContext>
  44. );
  45. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  46. });
  47. it('renders empty data', function () {
  48. render(
  49. <TestContext>
  50. <FunctionsTable
  51. isLoading={false}
  52. error={null}
  53. functions={[]}
  54. project={project}
  55. sort="-p99"
  56. />
  57. </TestContext>
  58. );
  59. expect(screen.getByText('No results found for your query')).toBeInTheDocument();
  60. });
  61. it('renders one function', function () {
  62. const func = {
  63. count: 10,
  64. examples: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
  65. fingerprint: 1234,
  66. name: 'foo',
  67. p75: 10000000,
  68. p95: 12000000,
  69. p99: 12500000,
  70. package: 'bar',
  71. path: 'baz',
  72. worst: 'cccccccccccccccccccccccccccccccc',
  73. };
  74. render(
  75. <TestContext>
  76. <FunctionsTable
  77. isLoading={false}
  78. error={null}
  79. functions={[func]}
  80. project={project}
  81. sort="-p99"
  82. />
  83. </TestContext>
  84. );
  85. expect(screen.getByText('Name')).toBeInTheDocument();
  86. expect(screen.getByText('foo')).toBeInTheDocument();
  87. expect(screen.getByText('Package')).toBeInTheDocument();
  88. expect(screen.getByText('bar')).toBeInTheDocument();
  89. expect(screen.getByText('Count')).toBeInTheDocument();
  90. expect(screen.getByText('10')).toBeInTheDocument();
  91. expect(screen.getByText('P75 Duration')).toBeInTheDocument();
  92. expect(screen.getByText('10.00ms')).toBeInTheDocument();
  93. expect(screen.getByText('P99 Duration')).toBeInTheDocument();
  94. expect(screen.getByText('12.50ms')).toBeInTheDocument();
  95. });
  96. it('renders empty name', function () {
  97. const func = {
  98. count: 10,
  99. examples: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
  100. fingerprint: 1234,
  101. name: '',
  102. p75: 10000000,
  103. p95: 12000000,
  104. p99: 12500000,
  105. package: 'bar',
  106. path: 'baz',
  107. worst: 'cccccccccccccccccccccccccccccccc',
  108. };
  109. render(
  110. <TestContext>
  111. <FunctionsTable
  112. isLoading={false}
  113. error={null}
  114. functions={[func]}
  115. project={project}
  116. sort="-p99"
  117. />
  118. </TestContext>
  119. );
  120. expect(screen.getByText('Name')).toBeInTheDocument();
  121. expect(screen.getByText('Unknown')).toBeInTheDocument();
  122. expect(screen.getByText('Package')).toBeInTheDocument();
  123. expect(screen.getByText('bar')).toBeInTheDocument();
  124. });
  125. it('renders empty package', function () {
  126. const func = {
  127. count: 10,
  128. examples: ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
  129. fingerprint: 1234,
  130. name: 'foo',
  131. p75: 10000000,
  132. p95: 12000000,
  133. p99: 12500000,
  134. package: '',
  135. path: 'baz',
  136. worst: 'cccccccccccccccccccccccccccccccc',
  137. };
  138. render(
  139. <TestContext>
  140. <FunctionsTable
  141. isLoading={false}
  142. error={null}
  143. functions={[func]}
  144. project={project}
  145. sort="-p99"
  146. />
  147. </TestContext>
  148. );
  149. expect(screen.getByText('Name')).toBeInTheDocument();
  150. expect(screen.getByText('foo')).toBeInTheDocument();
  151. expect(screen.getByText('Package')).toBeInTheDocument();
  152. expect(screen.getByText('Unknown')).toBeInTheDocument();
  153. });
  154. });
  155. describe('LegacyFunctionsTable', function () {
  156. it('renders loading', function () {
  157. render(
  158. <TestContext>
  159. <LegacyFunctionsTable
  160. isLoading
  161. error={null}
  162. functionCalls={[]}
  163. project={project}
  164. />
  165. </TestContext>
  166. );
  167. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  168. });
  169. it('renders empty data', function () {
  170. render(
  171. <TestContext>
  172. <LegacyFunctionsTable
  173. isLoading={false}
  174. error={null}
  175. functionCalls={[]}
  176. project={project}
  177. />
  178. </TestContext>
  179. );
  180. expect(screen.getByText('No results found for your query')).toBeInTheDocument();
  181. });
  182. it('renders one function', function () {
  183. const func = {
  184. image: 'libnetwork.dylib',
  185. symbol: 'nw_endpoint_flow_setup_socket',
  186. duration_ns: {
  187. p50: 458843541,
  188. p75: 468843541,
  189. p90: 478843541,
  190. p95: 488843541,
  191. p99: 498843541,
  192. },
  193. duration_ns_values: null,
  194. frequency: {
  195. p50: 0,
  196. p75: 0,
  197. p90: 0.6333333333333346,
  198. p95: 1,
  199. p99: 1,
  200. },
  201. frequency_values: null,
  202. thread_name_to_percent: {
  203. '': 1,
  204. },
  205. line: 0,
  206. path: '',
  207. main_thread_percent: 0.33,
  208. profile_ids: ['75a32ee2e6ed44458f4647b024b615bb'],
  209. profile_id_to_thread_id: {
  210. '75a32ee2e6ed44458f4647b024b615bb': 23555,
  211. },
  212. key: '0dd7251302785a3be078d2a5200016fc',
  213. transaction_names: ['iOS_Swift.ViewController'],
  214. };
  215. render(
  216. <TestContext>
  217. <LegacyFunctionsTable
  218. isLoading={false}
  219. error={null}
  220. functionCalls={[func]}
  221. project={project}
  222. />
  223. </TestContext>
  224. );
  225. expect(screen.getByText('Symbol')).toBeInTheDocument();
  226. expect(screen.getByText('nw_endpoint_flow_setup_socket')).toBeInTheDocument();
  227. expect(screen.getByText('Binary')).toBeInTheDocument();
  228. expect(screen.getByText('libnetwork.dylib')).toBeInTheDocument();
  229. expect(screen.getByText('P75 Duration')).toBeInTheDocument();
  230. expect(screen.getByText('468.84ms')).toBeInTheDocument();
  231. expect(screen.getByText('P99 Duration')).toBeInTheDocument();
  232. expect(screen.getByText('498.84ms')).toBeInTheDocument();
  233. expect(screen.getByText('Main Thread %')).toBeInTheDocument();
  234. expect(screen.getByText('33%')).toBeInTheDocument();
  235. expect(screen.getByText('P75 Frequency')).toBeInTheDocument();
  236. expect(screen.getByText('0')).toBeInTheDocument();
  237. expect(screen.getByText('P99 Frequency')).toBeInTheDocument();
  238. expect(screen.getByText('1')).toBeInTheDocument();
  239. });
  240. });