metricsDataSwitcher.spec.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import {ProjectFixture} from 'sentry-fixture/project';
  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 {generatePerformanceEventView} from 'sentry/views/performance/data';
  8. import {PerformanceLanding} from 'sentry/views/performance/landing';
  9. function WrappedComponent({
  10. data,
  11. withStaticFilters = true,
  12. }: {
  13. data: any;
  14. withStaticFilters?: boolean;
  15. }) {
  16. const eventView = generatePerformanceEventView(
  17. data.router.location,
  18. data.projects,
  19. {
  20. withStaticFilters,
  21. },
  22. data.organization
  23. );
  24. return (
  25. <MetricsCardinalityProvider
  26. location={data.router.location}
  27. organization={data.organization}
  28. >
  29. <PerformanceLanding
  30. router={data.router}
  31. organization={data.organization}
  32. location={data.router.location}
  33. eventView={eventView}
  34. projects={data.projects}
  35. selection={eventView.getPageFilters()}
  36. onboardingProject={undefined}
  37. handleSearch={() => {}}
  38. handleTrendsClick={() => {}}
  39. setError={() => {}}
  40. withStaticFilters={withStaticFilters}
  41. />
  42. </MetricsCardinalityProvider>
  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: '/organizations/org-slug/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 = ProjectFixture();
  118. const data = initializeData({
  119. project: project.id,
  120. projects: [project],
  121. features,
  122. });
  123. wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
  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 = ProjectFixture();
  129. const data = initializeData({
  130. project: project.id,
  131. projects: [project],
  132. features,
  133. });
  134. wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
  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 = ProjectFixture();
  144. const data = initializeData({
  145. project: project.id,
  146. projects: [project],
  147. features,
  148. });
  149. wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
  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 = ProjectFixture();
  159. const data = initializeData({
  160. project: project.id,
  161. projects: [project],
  162. features,
  163. });
  164. wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
  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 = ProjectFixture({id: '1'});
  178. const project2 = ProjectFixture({id: '2'});
  179. const data = initializeData({
  180. project: '-1',
  181. projects: [project, project2],
  182. features,
  183. });
  184. wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
  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 = ProjectFixture({id: '1'});
  198. const project2 = ProjectFixture({id: '2'});
  199. const data = initializeData({
  200. project: '-1',
  201. projects: [project, project2],
  202. features,
  203. });
  204. wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
  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 = ProjectFixture();
  217. const data = initializeData({
  218. project: project.id,
  219. projects: [project],
  220. features,
  221. });
  222. wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
  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 project = ProjectFixture({platform: 'javascript-react'});
  235. const data = initializeData({
  236. project: project.id,
  237. projects: [project],
  238. features,
  239. });
  240. wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
  241. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  242. expect(
  243. await screen.findByTestId('landing-mep-alert-unnamed-discover-or-set')
  244. ).toBeInTheDocument();
  245. });
  246. it('renders with feature flag and partial other(unparam) transactions', async function () {
  247. addMetricsDataMock({
  248. metricsCount: 100,
  249. nullCount: 0,
  250. unparamCount: 1,
  251. });
  252. const project = ProjectFixture();
  253. const data = initializeData({
  254. project: project.id,
  255. projects: [project],
  256. features,
  257. });
  258. wrapper = render(<WrappedComponent data={data} />, {organization: data.organization});
  259. expect(await screen.findByTestId('transaction-search-bar')).toBeInTheDocument();
  260. expect(
  261. await screen.findByTestId('landing-mep-alert-unnamed-discover')
  262. ).toBeInTheDocument();
  263. });
  264. });