platformCompatibilityChecker.spec.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {PageAlert, PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import useProjects from 'sentry/utils/useProjects';
  7. import {PlatformCompatibilityChecker} from 'sentry/views/performance/platformCompatibilityChecker';
  8. jest.mock('sentry/utils/useProjects');
  9. jest.mock('sentry/utils/usePageFilters');
  10. describe('PlatformCompatibilityChecker', () => {
  11. let organization;
  12. beforeEach(() => {
  13. MockApiClient.clearMockResponses();
  14. jest.mocked(useProjects).mockReturnValue({
  15. projects: [
  16. ProjectFixture({id: '1'}),
  17. ProjectFixture({id: '2', slug: 'incompatible'}),
  18. ],
  19. onSearch: jest.fn(),
  20. placeholders: [],
  21. fetching: false,
  22. hasMore: null,
  23. fetchError: null,
  24. initiallyLoaded: false,
  25. });
  26. jest.mocked(usePageFilters).mockReturnValue({
  27. isReady: true,
  28. desyncedFilters: new Set(),
  29. pinnedFilters: new Set(),
  30. shouldPersist: true,
  31. selection: {
  32. datetime: {
  33. period: '10d',
  34. start: null,
  35. end: null,
  36. utc: false,
  37. },
  38. environments: [],
  39. projects: [1],
  40. },
  41. });
  42. organization = OrganizationFixture();
  43. });
  44. it('renders the children if all projects are compatible', async () => {
  45. // Incompatible projects response
  46. MockApiClient.addMockResponse({
  47. url: `/organizations/${organization.slug}/events/`,
  48. body: {
  49. data: [],
  50. },
  51. });
  52. render(
  53. <PlatformCompatibilityChecker
  54. compatibleSDKNames={['foobar']}
  55. docsUrl="www.example.com"
  56. >
  57. <div>Child</div>
  58. </PlatformCompatibilityChecker>
  59. );
  60. expect(await screen.findByText('Child')).toBeInTheDocument();
  61. });
  62. it('does not render the children if all selected projects are incompatible', async () => {
  63. jest.mocked(usePageFilters).mockReturnValue({
  64. isReady: true,
  65. desyncedFilters: new Set(),
  66. pinnedFilters: new Set(),
  67. shouldPersist: true,
  68. selection: {
  69. datetime: {
  70. period: '10d',
  71. start: null,
  72. end: null,
  73. utc: false,
  74. },
  75. environments: [],
  76. projects: [2],
  77. },
  78. });
  79. // Incompatible projects response
  80. MockApiClient.addMockResponse({
  81. url: `/organizations/${organization.slug}/events/`,
  82. body: {
  83. data: [{project_id: 2, 'sdk.name': 'incompatible', count: 1}],
  84. },
  85. });
  86. render(
  87. <PageAlertProvider>
  88. <PageAlert />
  89. <PlatformCompatibilityChecker
  90. compatibleSDKNames={['foobar']}
  91. docsUrl="www.example.com"
  92. >
  93. <div>Child</div>
  94. </PlatformCompatibilityChecker>
  95. </PageAlertProvider>
  96. );
  97. expect(
  98. await screen.findByText(
  99. /The following selected projects contain data from SDKs that are not supported by this view: incompatible/
  100. )
  101. ).toBeInTheDocument();
  102. expect(
  103. screen.getByText(/The currently supported SDK platforms are: foobar/)
  104. ).toBeInTheDocument();
  105. expect(screen.queryByText('Child')).not.toBeInTheDocument();
  106. });
  107. it('renders the children and a warning message if some projects are incompatible', async () => {
  108. jest.mocked(usePageFilters).mockReturnValue({
  109. isReady: true,
  110. desyncedFilters: new Set(),
  111. pinnedFilters: new Set(),
  112. shouldPersist: true,
  113. selection: {
  114. datetime: {
  115. period: '10d',
  116. start: null,
  117. end: null,
  118. utc: false,
  119. },
  120. environments: [],
  121. projects: [1, 2],
  122. },
  123. });
  124. // Incompatible projects response
  125. MockApiClient.addMockResponse({
  126. url: `/organizations/${organization.slug}/events/`,
  127. body: {
  128. data: [{project_id: 2, 'sdk.name': 'incompatible', count: 1}],
  129. },
  130. });
  131. render(
  132. <PageAlertProvider>
  133. <PageAlert />
  134. <PlatformCompatibilityChecker
  135. compatibleSDKNames={['foobar']}
  136. docsUrl="www.example.com"
  137. >
  138. <div>Child</div>
  139. </PlatformCompatibilityChecker>
  140. </PageAlertProvider>
  141. );
  142. expect(
  143. await screen.findByText(
  144. /The following selected projects contain data from SDKs that are not supported by this view: incompatible/
  145. )
  146. ).toBeInTheDocument();
  147. expect(await screen.findByText('Child')).toBeInTheDocument();
  148. });
  149. it('handles all project selection', async () => {
  150. jest.mocked(usePageFilters).mockReturnValue({
  151. isReady: true,
  152. desyncedFilters: new Set(),
  153. pinnedFilters: new Set(),
  154. shouldPersist: true,
  155. selection: {
  156. datetime: {
  157. period: '10d',
  158. start: null,
  159. end: null,
  160. utc: false,
  161. },
  162. environments: [],
  163. projects: [],
  164. },
  165. });
  166. // Incompatible projects response
  167. MockApiClient.addMockResponse({
  168. url: `/organizations/${organization.slug}/events/`,
  169. body: {
  170. data: [{project_id: 2, 'sdk.name': 'incompatible', count: 1}],
  171. },
  172. });
  173. render(
  174. <PageAlertProvider>
  175. <PageAlert />
  176. <PlatformCompatibilityChecker
  177. compatibleSDKNames={['foobar']}
  178. docsUrl="www.example.com"
  179. >
  180. <div>Child</div>
  181. </PlatformCompatibilityChecker>
  182. </PageAlertProvider>
  183. );
  184. expect(
  185. await screen.findByText(
  186. /The following selected projects contain data from SDKs that are not supported by this view: incompatible/
  187. )
  188. ).toBeInTheDocument();
  189. expect(await screen.findByText('Child')).toBeInTheDocument();
  190. });
  191. });