functionsTable.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 ProjectsStore from 'sentry/stores/projectsStore';
  6. import {OrganizationContext} from 'sentry/views/organizationContext';
  7. import {RouteContext} from 'sentry/views/routeContext';
  8. const organization = TestStubs.Organization();
  9. const project = TestStubs.Project();
  10. function TestContext({children}: {children: ReactElement}) {
  11. const {router} = useMemo(() => initializeOrg({organization, project} as any), []);
  12. useEffect(() => {
  13. ProjectsStore.loadInitialData([project]);
  14. return () => ProjectsStore.reset();
  15. }, []);
  16. return (
  17. <RouteContext.Provider
  18. value={{
  19. router,
  20. location: router.location,
  21. params: {},
  22. routes: [],
  23. }}
  24. >
  25. <OrganizationContext.Provider value={organization}>
  26. {children}
  27. </OrganizationContext.Provider>
  28. </RouteContext.Provider>
  29. );
  30. }
  31. describe('FunctionsTable', function () {
  32. it('renders loading', function () {
  33. render(
  34. <TestContext>
  35. <FunctionsTable isLoading error={null} functionCalls={[]} project={project} />
  36. </TestContext>
  37. );
  38. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  39. });
  40. it('renders empty data', function () {
  41. render(
  42. <TestContext>
  43. <FunctionsTable
  44. isLoading={false}
  45. error={null}
  46. functionCalls={[]}
  47. project={project}
  48. />
  49. </TestContext>
  50. );
  51. expect(screen.getByText('No results found for your query')).toBeInTheDocument();
  52. });
  53. it('renders one function', function () {
  54. const func = {
  55. image: 'libnetwork.dylib',
  56. symbol: 'nw_endpoint_flow_setup_socket',
  57. duration_ns: {
  58. p50: 458843541,
  59. p75: 468843541,
  60. p90: 478843541,
  61. p95: 488843541,
  62. p99: 498843541,
  63. },
  64. duration_ns_values: null,
  65. frequency: {
  66. p50: 0,
  67. p75: 0,
  68. p90: 0.6333333333333346,
  69. p95: 1,
  70. p99: 1,
  71. },
  72. frequency_values: null,
  73. thread_name_to_percent: {
  74. '': 1,
  75. },
  76. line: 0,
  77. path: '',
  78. main_thread_percent: 0.33,
  79. profile_ids: ['75a32ee2e6ed44458f4647b024b615bb'],
  80. profile_id_to_thread_id: {
  81. '75a32ee2e6ed44458f4647b024b615bb': 23555,
  82. },
  83. key: '0dd7251302785a3be078d2a5200016fc',
  84. transaction_names: ['iOS_Swift.ViewController'],
  85. };
  86. render(
  87. <TestContext>
  88. <FunctionsTable
  89. isLoading={false}
  90. error={null}
  91. functionCalls={[func]}
  92. project={project}
  93. />
  94. </TestContext>
  95. );
  96. expect(screen.getByText('Symbol')).toBeInTheDocument();
  97. expect(screen.getByText('nw_endpoint_flow_setup_socket')).toBeInTheDocument();
  98. expect(screen.getByText('Binary')).toBeInTheDocument();
  99. expect(screen.getByText('libnetwork.dylib')).toBeInTheDocument();
  100. expect(screen.getByText('P75 Duration')).toBeInTheDocument();
  101. expect(screen.getByText('468.84ms')).toBeInTheDocument();
  102. expect(screen.getByText('P99 Duration')).toBeInTheDocument();
  103. expect(screen.getByText('498.84ms')).toBeInTheDocument();
  104. expect(screen.getByText('Main Thread %')).toBeInTheDocument();
  105. expect(screen.getByText('33%')).toBeInTheDocument();
  106. expect(screen.getByText('P75 Frequency')).toBeInTheDocument();
  107. expect(screen.getByText('0')).toBeInTheDocument();
  108. expect(screen.getByText('P99 Frequency')).toBeInTheDocument();
  109. expect(screen.getByText('1')).toBeInTheDocument();
  110. });
  111. });