profilesTable.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {ReactElement, useEffect, useMemo} from 'react';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {ProfilesTable} from 'sentry/components/profiling/profilesTable';
  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('ProfilesTable', function () {
  32. it('renders loading', function () {
  33. render(
  34. <TestContext>
  35. <ProfilesTable isLoading error={null} traces={[]} />
  36. </TestContext>
  37. );
  38. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  39. });
  40. it('renders empty data', function () {
  41. render(
  42. <TestContext>
  43. <ProfilesTable isLoading={false} error={null} traces={[]} />
  44. </TestContext>
  45. );
  46. expect(screen.getByText('No results found for your query')).toBeInTheDocument();
  47. });
  48. it('renders one trace', function () {
  49. const trace = {
  50. android_api_level: 0,
  51. device_classification: 'low',
  52. device_locale: 'en_US',
  53. device_manufacturer: 'Apple',
  54. device_model: 'iPhone7,2',
  55. device_os_build_number: '14F89',
  56. device_os_name: 'iOS',
  57. device_os_version: '10.3.2',
  58. failed: false,
  59. id: '75a32ee2e6ed44458f4647b024b615bb',
  60. project_id: '2',
  61. timestamp: 1653426810,
  62. trace_duration_ms: 931.404667,
  63. transaction_id: '6051e1bfb94349a88ead9ffec6910eb9',
  64. transaction_name: 'iOS_Swift.ViewController',
  65. version_code: '1',
  66. version_name: '7.16.0',
  67. };
  68. render(
  69. <TestContext>
  70. <ProfilesTable isLoading={false} error={null} traces={[trace]} />
  71. </TestContext>
  72. );
  73. expect(screen.getByText('Status')).toBeInTheDocument();
  74. expect(screen.getByText('Profile ID')).toBeInTheDocument();
  75. expect(screen.getByText('75a32ee2')).toBeInTheDocument();
  76. expect(screen.getByText('Project')).toBeInTheDocument();
  77. expect(screen.getByText('project-slug')).toBeInTheDocument();
  78. expect(screen.getByText('Transaction Name')).toBeInTheDocument();
  79. expect(screen.getByText('iOS_Swift.ViewController')).toBeInTheDocument();
  80. expect(screen.getByText('Version')).toBeInTheDocument();
  81. expect(screen.getByText('7.16.0 (build 1)')).toBeInTheDocument();
  82. expect(screen.getByText('Timestamp')).toBeInTheDocument();
  83. expect(screen.getByText('May 24, 2022 9:13:30 PM UTC')).toBeInTheDocument();
  84. expect(screen.getByText('Duration')).toBeInTheDocument();
  85. expect(screen.getByText('931.40ms')).toBeInTheDocument();
  86. expect(screen.getByText('Device Model')).toBeInTheDocument();
  87. expect(screen.getByText('iPhone7,2')).toBeInTheDocument();
  88. expect(screen.getByText('Device Classification')).toBeInTheDocument();
  89. expect(screen.getByText('low')).toBeInTheDocument();
  90. });
  91. });