index.spec.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import type {Location} from 'history';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import {browserHistory} from 'sentry/utils/browserHistory';
  6. import localStorage from 'sentry/utils/localStorage';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import usePageFilters from 'sentry/utils/usePageFilters';
  9. import useProjects from 'sentry/utils/useProjects';
  10. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  11. import PageloadModule from 'sentry/views/performance/mobile/screenload';
  12. import {PLATFORM_LOCAL_STORAGE_KEY} from 'sentry/views/performance/mobile/useCrossPlatformProject';
  13. jest.mock('sentry/views/performance/browser/webVitals/utils/useOnboardingProject');
  14. jest.mock('sentry/utils/useLocation');
  15. jest.mock('sentry/utils/usePageFilters');
  16. jest.mock('sentry/utils/useProjects');
  17. describe('PageloadModule', function () {
  18. const project = ProjectFixture({platform: 'react-native'});
  19. const organization = OrganizationFixture({
  20. features: ['spans-first-ui'],
  21. projects: [project],
  22. });
  23. jest.mocked(useOnboardingProject).mockReturnValue(undefined);
  24. jest.mocked(useProjects).mockReturnValue({
  25. fetchError: null,
  26. fetching: false,
  27. hasMore: false,
  28. initiallyLoaded: false,
  29. onSearch: jest.fn(),
  30. placeholders: [],
  31. projects: [project],
  32. });
  33. jest.mocked(useLocation).mockReturnValue({
  34. action: 'PUSH',
  35. hash: '',
  36. key: '',
  37. pathname: '/organizations/org-slug/performance/mobile/screens/',
  38. query: {},
  39. search: '',
  40. state: undefined,
  41. } as Location);
  42. jest.mocked(usePageFilters).mockReturnValue({
  43. isReady: true,
  44. desyncedFilters: new Set(),
  45. pinnedFilters: new Set(),
  46. shouldPersist: true,
  47. selection: {
  48. datetime: {
  49. period: '10d',
  50. start: null,
  51. end: null,
  52. utc: false,
  53. },
  54. environments: [],
  55. projects: [parseInt(project.id, 10)],
  56. },
  57. });
  58. let eventsMock;
  59. beforeEach(function () {
  60. localStorage.clear();
  61. browserHistory.push = jest.fn();
  62. MockApiClient.addMockResponse({
  63. url: `/organizations/${organization.slug}/releases/`,
  64. body: [
  65. {
  66. id: 970136705,
  67. version: 'com.example.vu.android@2.10.5',
  68. dateCreated: '2023-12-19T21:37:53.895495Z',
  69. },
  70. {
  71. id: 969902997,
  72. version: 'com.example.vu.android@2.10.3+42',
  73. dateCreated: '2023-12-19T18:04:06.953025Z',
  74. },
  75. ],
  76. });
  77. MockApiClient.addMockResponse({
  78. url: `/organizations/${organization.slug}/events/`,
  79. query: {
  80. dataset: 'metrics',
  81. environment: [],
  82. field: ['release', 'count()'],
  83. per_page: 50,
  84. project: ['2'],
  85. query:
  86. 'transaction.op:ui.load release:["com.example.vu.android@2.10.5","com.example.vu.android@2.10.3+42"]',
  87. referrer: 'api.starfish.mobile-release-selector',
  88. statsPeriod: '10d',
  89. },
  90. body: {
  91. meta: {},
  92. data: [
  93. {
  94. release: 'com.example.vu.android@2.10.5',
  95. 'count()': 9768,
  96. },
  97. {
  98. release: 'com.example.vu.android@2.10.3+42',
  99. 'count()': 826,
  100. },
  101. ],
  102. },
  103. });
  104. eventsMock = MockApiClient.addMockResponse({
  105. url: `/organizations/${organization.slug}/events/`,
  106. });
  107. });
  108. afterEach(function () {
  109. MockApiClient.clearMockResponses();
  110. jest.clearAllMocks();
  111. });
  112. it('defaults requests with android platform filter', async function () {
  113. render(<PageloadModule />, {organization});
  114. await waitFor(() => {
  115. expect(
  116. screen.getByRole('radiogroup', {name: 'Filter platform'})
  117. ).toBeInTheDocument();
  118. });
  119. await waitFor(() => {
  120. expect(eventsMock).toHaveBeenNthCalledWith(
  121. 4,
  122. expect.anything(),
  123. expect.objectContaining({
  124. query: expect.objectContaining({
  125. query: 'event.type:transaction transaction.op:ui.load os.name:Android',
  126. }),
  127. })
  128. );
  129. });
  130. await waitFor(() => {
  131. expect(eventsMock).toHaveBeenNthCalledWith(
  132. 4,
  133. expect.anything(),
  134. expect.objectContaining({
  135. query: expect.objectContaining({
  136. query: 'event.type:transaction transaction.op:ui.load os.name:Android',
  137. }),
  138. })
  139. );
  140. });
  141. });
  142. it('uses value from local storage if available', async function () {
  143. localStorage.setItem(PLATFORM_LOCAL_STORAGE_KEY, 'iOS');
  144. render(<PageloadModule />, {organization});
  145. await waitFor(() => {
  146. expect(
  147. screen.getByRole('radiogroup', {name: 'Filter platform'})
  148. ).toBeInTheDocument();
  149. });
  150. await waitFor(() => {
  151. expect(eventsMock).toHaveBeenNthCalledWith(
  152. 4,
  153. expect.anything(),
  154. expect.objectContaining({
  155. query: expect.objectContaining({
  156. query: 'event.type:transaction transaction.op:ui.load os.name:iOS',
  157. }),
  158. })
  159. );
  160. });
  161. });
  162. });