metricsDataSwitcher.spec.tsx 9.5 KB

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