metricsDataSwitcher.spec.tsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. import {addMetricsDataMock} from 'sentry-test/performance/addMetricsDataMock';
  2. import {initializeData} from 'sentry-test/performance/initializePerformanceData';
  3. import {act, render, screen} from 'sentry-test/reactTestingLibrary';
  4. import TeamStore from 'sentry/stores/teamStore';
  5. import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
  6. import {QueryClient, QueryClientProvider} from 'sentry/utils/queryClient';
  7. import {OrganizationContext} from 'sentry/views/organizationContext';
  8. import {generatePerformanceEventView} from 'sentry/views/performance/data';
  9. import {PerformanceLanding} from 'sentry/views/performance/landing';
  10. function WrappedComponent({data, withStaticFilters = true}) {
  11. const eventView = generatePerformanceEventView(
  12. data.router.location,
  13. data.projects,
  14. {
  15. withStaticFilters,
  16. },
  17. data.organization
  18. );
  19. const client = new QueryClient();
  20. return (
  21. <QueryClientProvider client={client}>
  22. <OrganizationContext.Provider value={data.organization}>
  23. <MetricsCardinalityProvider
  24. location={data.router.location}
  25. organization={data.organization}
  26. >
  27. <PerformanceLanding
  28. router={data.router}
  29. organization={data.organization}
  30. location={data.router.location}
  31. eventView={eventView}
  32. projects={data.projects}
  33. selection={eventView.getPageFilters()}
  34. onboardingProject={undefined}
  35. handleSearch={() => {}}
  36. handleTrendsClick={() => {}}
  37. setError={() => {}}
  38. withStaticFilters={withStaticFilters}
  39. />
  40. </MetricsCardinalityProvider>
  41. </OrganizationContext.Provider>
  42. </QueryClientProvider>
  43. );
  44. }
  45. const features = [
  46. 'performance-transaction-name-only-search',
  47. 'organizations:performance-transaction-name-only-search',
  48. ];
  49. describe('Performance > Landing > MetricsDataSwitcher', function () {
  50. let wrapper: any;
  51. act(() => void TeamStore.loadInitialData([], false, null));
  52. beforeEach(function () {
  53. // eslint-disable-next-line no-console
  54. jest.spyOn(console, 'error').mockImplementation(jest.fn());
  55. MockApiClient.addMockResponse({
  56. url: '/organizations/org-slug/sdk-updates/',
  57. body: [],
  58. });
  59. MockApiClient.addMockResponse({
  60. url: '/prompts-activity/',
  61. body: {},
  62. });
  63. MockApiClient.addMockResponse({
  64. url: '/organizations/org-slug/projects/',
  65. body: [],
  66. });
  67. MockApiClient.addMockResponse({
  68. method: 'GET',
  69. url: `/organizations/org-slug/key-transactions-list/`,
  70. body: [],
  71. });
  72. MockApiClient.addMockResponse({
  73. method: 'GET',
  74. url: `/organizations/org-slug/legacy-key-transactions-count/`,
  75. body: [],
  76. });
  77. MockApiClient.addMockResponse({
  78. method: 'GET',
  79. url: `/organizations/org-slug/events-stats/`,
  80. body: [],
  81. });
  82. MockApiClient.addMockResponse({
  83. method: 'GET',
  84. url: `/organizations/org-slug/events-trends-stats/`,
  85. body: [],
  86. });
  87. MockApiClient.addMockResponse({
  88. method: 'GET',
  89. url: `/organizations/org-slug/events-histogram/`,
  90. body: [],
  91. });
  92. MockApiClient.addMockResponse({
  93. method: 'GET',
  94. url: `/organizations/org-slug/eventsv2/`,
  95. body: {
  96. meta: {
  97. id: 'string',
  98. },
  99. data: [
  100. {
  101. id: '1234',
  102. },
  103. ],
  104. },
  105. });
  106. });
  107. afterEach(function () {
  108. MockApiClient.clearMockResponses();
  109. jest.restoreAllMocks();
  110. if (wrapper) {
  111. wrapper.unmount();
  112. wrapper = undefined;
  113. }
  114. });
  115. it('renders basic UI elements', function () {
  116. addMetricsDataMock();
  117. const project = TestStubs.Project();
  118. const data = initializeData({
  119. project: project.id,
  120. projects: [project],
  121. features,
  122. });
  123. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  124. expect(screen.getByTestId('performance-landing-v3')).toBeInTheDocument();
  125. });
  126. it('renders with feature flag and all metric data', async function () {
  127. addMetricsDataMock();
  128. const project = TestStubs.Project();
  129. const data = initializeData({
  130. project: project.id,
  131. projects: [project],
  132. features,
  133. });
  134. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  135. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  136. });
  137. it('renders with feature flag and checking dynamic sampled projects exist', async function () {
  138. addMetricsDataMock({
  139. metricsCount: 100,
  140. nullCount: 0,
  141. unparamCount: 0,
  142. });
  143. const project = TestStubs.Project();
  144. const data = initializeData({
  145. project: project.id,
  146. projects: [project],
  147. features,
  148. });
  149. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  150. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  151. });
  152. it('renders with feature flag and any incompatible data', async function () {
  153. addMetricsDataMock({
  154. metricsCount: 100,
  155. nullCount: 1,
  156. unparamCount: 0,
  157. });
  158. const project = TestStubs.Project();
  159. const data = initializeData({
  160. project: project.id,
  161. projects: [project],
  162. features,
  163. });
  164. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  165. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  166. expect(
  167. await screen.findByTestId('landing-mep-alert-single-project-incompatible')
  168. ).toBeInTheDocument();
  169. });
  170. it('renders with feature flag and any incompatible transactions on multiple projects with at least one compatible project', async function () {
  171. addMetricsDataMock({
  172. metricsCount: 100,
  173. nullCount: 1,
  174. unparamCount: 0,
  175. compatibleProjects: [1],
  176. });
  177. const project = TestStubs.Project({id: 1});
  178. const project2 = TestStubs.Project({id: 2});
  179. const data = initializeData({
  180. project: '-1',
  181. projects: [project, project2],
  182. features,
  183. });
  184. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  185. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  186. expect(
  187. await screen.findByTestId('landing-mep-alert-multi-project-incompatible')
  188. ).toBeInTheDocument();
  189. });
  190. it('renders with feature flag and any incompatible transactions on multiple projects with no compatible project', async function () {
  191. addMetricsDataMock({
  192. metricsCount: 100,
  193. nullCount: 1,
  194. unparamCount: 0,
  195. compatibleProjects: [],
  196. });
  197. const project = TestStubs.Project({id: 1});
  198. const project2 = TestStubs.Project({id: 2});
  199. const data = initializeData({
  200. project: '-1',
  201. projects: [project, project2],
  202. features,
  203. });
  204. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  205. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  206. expect(
  207. await screen.findByTestId('landing-mep-alert-multi-project-all-incompatible')
  208. ).toBeInTheDocument();
  209. });
  210. it('renders with feature flag and all other(unparam) transactions', async function () {
  211. addMetricsDataMock({
  212. metricsCount: 100,
  213. nullCount: 0,
  214. unparamCount: 100,
  215. });
  216. const project = TestStubs.Project();
  217. const data = initializeData({
  218. project: project.id,
  219. projects: [project],
  220. features,
  221. });
  222. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  223. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  224. expect(
  225. await screen.findByTestId('landing-mep-alert-unnamed-discover')
  226. ).toBeInTheDocument();
  227. });
  228. it('renders with feature flag and partial other(unparam) transactions and platform with docs', async function () {
  229. addMetricsDataMock({
  230. metricsCount: 100,
  231. nullCount: 0,
  232. unparamCount: 1,
  233. });
  234. const platformWithDocs = 'javascript.react';
  235. const project = TestStubs.Project({platform: platformWithDocs});
  236. const data = initializeData({
  237. project: project.id,
  238. projects: [project],
  239. features,
  240. });
  241. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  242. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  243. expect(
  244. await screen.findByTestId('landing-mep-alert-unnamed-discover-or-set')
  245. ).toBeInTheDocument();
  246. });
  247. it('renders with feature flag and partial other(unparam) transactions', async function () {
  248. addMetricsDataMock({
  249. metricsCount: 100,
  250. nullCount: 0,
  251. unparamCount: 1,
  252. });
  253. const project = TestStubs.Project();
  254. const data = initializeData({
  255. project: project.id,
  256. projects: [project],
  257. features,
  258. });
  259. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  260. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  261. expect(
  262. await screen.findByTestId('landing-mep-alert-unnamed-discover')
  263. ).toBeInTheDocument();
  264. });
  265. });