metricsDataSwitcher.spec.tsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 checking dynamic sampled projects exist', async function () {
  136. addMetricsDataMock({
  137. metricsCount: 100,
  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('transaction-search-bar')).toBeInTheDocument();
  149. });
  150. it('renders with feature flag and any incompatible data', async function () {
  151. addMetricsDataMock({
  152. metricsCount: 100,
  153. nullCount: 1,
  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. expect(
  165. await screen.findByTestId('landing-mep-alert-single-project-incompatible')
  166. ).toBeInTheDocument();
  167. });
  168. it('renders with feature flag and any incompatible transactions on multiple projects with at least one compatible project', async function () {
  169. addMetricsDataMock({
  170. metricsCount: 100,
  171. nullCount: 1,
  172. unparamCount: 0,
  173. compatibleProjects: [1],
  174. });
  175. const project = TestStubs.Project({id: 1});
  176. const project2 = TestStubs.Project({id: 2});
  177. const data = initializeData({
  178. project: '-1',
  179. projects: [project, project2],
  180. features,
  181. });
  182. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  183. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  184. expect(
  185. await screen.findByTestId('landing-mep-alert-multi-project-incompatible')
  186. ).toBeInTheDocument();
  187. });
  188. it('renders with feature flag and any incompatible transactions on multiple projects with no compatible project', async function () {
  189. addMetricsDataMock({
  190. metricsCount: 100,
  191. nullCount: 1,
  192. unparamCount: 0,
  193. compatibleProjects: [],
  194. });
  195. const project = TestStubs.Project({id: 1});
  196. const project2 = TestStubs.Project({id: 2});
  197. const data = initializeData({
  198. project: '-1',
  199. projects: [project, project2],
  200. features,
  201. });
  202. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  203. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  204. expect(
  205. await screen.findByTestId('landing-mep-alert-multi-project-all-incompatible')
  206. ).toBeInTheDocument();
  207. });
  208. it('renders with feature flag and all other(unparam) transactions', async function () {
  209. addMetricsDataMock({
  210. metricsCount: 100,
  211. nullCount: 0,
  212. unparamCount: 100,
  213. });
  214. const project = TestStubs.Project();
  215. const data = initializeData({
  216. project: project.id,
  217. projects: [project],
  218. features,
  219. });
  220. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  221. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  222. expect(
  223. await screen.findByTestId('landing-mep-alert-unnamed-discover')
  224. ).toBeInTheDocument();
  225. });
  226. it('renders with feature flag and partial other(unparam) transactions and platform with docs', async function () {
  227. addMetricsDataMock({
  228. metricsCount: 100,
  229. nullCount: 0,
  230. unparamCount: 1,
  231. });
  232. const platformWithDocs = 'javascript.react';
  233. const project = TestStubs.Project({platform: platformWithDocs});
  234. const data = initializeData({
  235. project: project.id,
  236. projects: [project],
  237. features,
  238. });
  239. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  240. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  241. expect(
  242. await screen.findByTestId('landing-mep-alert-unnamed-discover-or-set')
  243. ).toBeInTheDocument();
  244. });
  245. it('renders with feature flag and partial other(unparam) transactions', async function () {
  246. addMetricsDataMock({
  247. metricsCount: 100,
  248. nullCount: 0,
  249. unparamCount: 1,
  250. });
  251. const project = TestStubs.Project();
  252. const data = initializeData({
  253. project: project.id,
  254. projects: [project],
  255. features,
  256. });
  257. wrapper = render(<WrappedComponent data={data} />, data.routerContext);
  258. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  259. expect(
  260. await screen.findByTestId('landing-mep-alert-unnamed-discover')
  261. ).toBeInTheDocument();
  262. });
  263. });