eventSamples.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import usePageFilters from 'sentry/utils/usePageFilters';
  5. import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
  6. import {ScreenLoadEventSamples} from 'sentry/views/insights/mobile/screenload/components/eventSamples';
  7. import {
  8. MobileCursors,
  9. MobileSortKeys,
  10. } from 'sentry/views/insights/mobile/screenload/constants';
  11. jest.mock('sentry/utils/usePageFilters');
  12. jest.mock('sentry/views/insights/common/queries/useReleases');
  13. describe('ScreenLoadEventSamples', function () {
  14. const organization = OrganizationFixture();
  15. const project = ProjectFixture();
  16. let mockEventsRequest;
  17. beforeEach(function () {
  18. jest.mocked(usePageFilters).mockReturnValue({
  19. isReady: true,
  20. desyncedFilters: new Set(),
  21. pinnedFilters: new Set(),
  22. shouldPersist: true,
  23. selection: {
  24. datetime: {
  25. period: '10d',
  26. start: null,
  27. end: null,
  28. utc: false,
  29. },
  30. environments: [],
  31. projects: [parseInt(project.id, 10)],
  32. },
  33. });
  34. jest.mocked(useReleaseSelection).mockReturnValue({
  35. primaryRelease: 'com.example.vu.android@2.10.5',
  36. isLoading: false,
  37. secondaryRelease: 'com.example.vu.android@2.10.3+42',
  38. });
  39. MockApiClient.addMockResponse({
  40. url: `/organizations/${organization.slug}/releases/`,
  41. body: [
  42. {
  43. id: 970136705,
  44. version: 'com.example.vu.android@2.10.5',
  45. dateCreated: '2023-12-19T21:37:53.895495Z',
  46. },
  47. {
  48. id: 969902997,
  49. version: 'com.example.vu.android@2.10.3+42',
  50. dateCreated: '2023-12-19T18:04:06.953025Z',
  51. },
  52. ],
  53. });
  54. mockEventsRequest = MockApiClient.addMockResponse({
  55. url: `/organizations/${organization.slug}/events/`,
  56. body: {
  57. meta: {
  58. fields: {
  59. id: 'string',
  60. 'project.name': 'string',
  61. 'profile.id': 'string',
  62. 'measurements.time_to_initial_display': 'duration',
  63. 'measurements.time_to_full_display': 'duration',
  64. },
  65. },
  66. data: [
  67. {
  68. id: '4142de70494989c04f023ce1727ac856f31b7f92',
  69. 'project.name': 'project1',
  70. 'profile.id': 'profile1',
  71. 'measurements.time_to_initial_display': 100.0,
  72. 'measurements.time_to_full_display': 200.0,
  73. },
  74. ],
  75. },
  76. });
  77. });
  78. it('makes a request for the release and transaction passed as props', async function () {
  79. render(
  80. <ScreenLoadEventSamples
  81. release="com.example.vu.android@2.10.5"
  82. sortKey={MobileSortKeys.RELEASE_1_EVENT_SAMPLE_TABLE}
  83. cursorName={MobileCursors.RELEASE_1_EVENT_SAMPLE_TABLE}
  84. transaction="ErrorController"
  85. showDeviceClassSelector
  86. />
  87. );
  88. // Check that headers are set properly
  89. expect(screen.getByRole('columnheader', {name: 'Event ID (R1)'})).toBeInTheDocument();
  90. expect(screen.getByRole('columnheader', {name: 'Profile'})).toBeInTheDocument();
  91. expect(screen.getByRole('columnheader', {name: 'TTID'})).toBeInTheDocument();
  92. expect(screen.getByRole('columnheader', {name: 'TTFD'})).toBeInTheDocument();
  93. expect(mockEventsRequest).toHaveBeenCalledTimes(1);
  94. // Check data is rendered properly
  95. // Transaction is a link
  96. expect(await screen.findByRole('link', {name: '4142de70'})).toHaveAttribute(
  97. 'href',
  98. '/organizations/org-slug/performance/project1:4142de70494989c04f023ce1727ac856f31b7f92/'
  99. );
  100. // Profile is a button
  101. expect(screen.getByRole('button', {name: 'View Profile'})).toHaveAttribute(
  102. 'href',
  103. '/organizations/org-slug/profiling/profile/project1/profile1/flamegraph/'
  104. );
  105. // TTID is a duration
  106. expect(screen.getByText('100.00ms')).toBeInTheDocument();
  107. // TTFD is a duration
  108. expect(screen.getByText('200.00ms')).toBeInTheDocument();
  109. });
  110. });