header.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import EventView from 'app/utils/discover/eventView';
  4. import TransactionHeader, {Tab} from 'app/views/performance/transactionSummary/header';
  5. function initializeData(opts?: {platform?: string}) {
  6. // @ts-expect-error
  7. const project = TestStubs.Project({platform: opts?.platform});
  8. // @ts-expect-error
  9. const organization = TestStubs.Organization({
  10. projects: [project],
  11. });
  12. const initialData = initializeOrg({
  13. organization,
  14. router: {
  15. location: {
  16. query: {
  17. project: project.id,
  18. },
  19. },
  20. },
  21. project: project.id,
  22. projects: [],
  23. });
  24. const router = initialData.router;
  25. const eventView = EventView.fromSavedQuery({
  26. id: undefined,
  27. version: 2,
  28. name: '',
  29. fields: ['transaction.status'], // unused fields
  30. projects: [parseInt(project.id, 10)],
  31. });
  32. return {
  33. project,
  34. organization,
  35. router,
  36. eventView,
  37. };
  38. }
  39. describe('Performance > Transaction Summary Header', function () {
  40. let wrapper;
  41. afterEach(function () {
  42. // @ts-expect-error
  43. MockApiClient.clearMockResponses();
  44. wrapper.unmount();
  45. });
  46. it('should render web vitals tab when yes', async function () {
  47. const {project, organization, router, eventView} = initializeData();
  48. wrapper = mountWithTheme(
  49. <TransactionHeader
  50. eventView={eventView}
  51. location={router.location}
  52. organization={organization}
  53. projects={[project]}
  54. transactionName="transaction_name"
  55. currentTab={Tab.TransactionSummary}
  56. hasWebVitals="yes"
  57. handleIncompatibleQuery={() => {}}
  58. />
  59. );
  60. // @ts-expect-error
  61. await tick();
  62. wrapper.update();
  63. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeTruthy();
  64. });
  65. it('should not render web vitals tab when no', async function () {
  66. const {project, organization, router, eventView} = initializeData();
  67. wrapper = mountWithTheme(
  68. <TransactionHeader
  69. eventView={eventView}
  70. location={router.location}
  71. organization={organization}
  72. projects={[project]}
  73. transactionName="transaction_name"
  74. currentTab={Tab.TransactionSummary}
  75. hasWebVitals="no"
  76. handleIncompatibleQuery={() => {}}
  77. />
  78. );
  79. // @ts-expect-error
  80. await tick();
  81. wrapper.update();
  82. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeFalsy();
  83. });
  84. it('should render web vitals tab when maybe and is frontend platform', async function () {
  85. const {project, organization, router, eventView} = initializeData({
  86. platform: 'javascript',
  87. });
  88. wrapper = mountWithTheme(
  89. <TransactionHeader
  90. eventView={eventView}
  91. location={router.location}
  92. organization={organization}
  93. projects={[project]}
  94. transactionName="transaction_name"
  95. currentTab={Tab.TransactionSummary}
  96. hasWebVitals="maybe"
  97. handleIncompatibleQuery={() => {}}
  98. />
  99. );
  100. // @ts-expect-error
  101. await tick();
  102. wrapper.update();
  103. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeTruthy();
  104. });
  105. it('should render web vitals tab when maybe and has measurements', async function () {
  106. // @ts-expect-error
  107. MockApiClient.addMockResponse({
  108. url: '/organizations/org-slug/events-has-measurements/',
  109. body: {measurements: true},
  110. });
  111. const {project, organization, router, eventView} = initializeData();
  112. wrapper = mountWithTheme(
  113. <TransactionHeader
  114. eventView={eventView}
  115. location={router.location}
  116. organization={organization}
  117. projects={[project]}
  118. transactionName="transaction_name"
  119. currentTab={Tab.TransactionSummary}
  120. hasWebVitals="maybe"
  121. handleIncompatibleQuery={() => {}}
  122. />
  123. );
  124. // @ts-expect-error
  125. await tick();
  126. wrapper.update();
  127. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeTruthy();
  128. });
  129. it('should not render web vitals tab when maybe and has no measurements', async function () {
  130. // @ts-expect-error
  131. MockApiClient.addMockResponse({
  132. url: '/organizations/org-slug/events-has-measurements/',
  133. body: {measurements: false},
  134. });
  135. const {project, organization, router, eventView} = initializeData();
  136. wrapper = mountWithTheme(
  137. <TransactionHeader
  138. eventView={eventView}
  139. location={router.location}
  140. organization={organization}
  141. projects={[project]}
  142. transactionName="transaction_name"
  143. currentTab={Tab.TransactionSummary}
  144. hasWebVitals="maybe"
  145. handleIncompatibleQuery={() => {}}
  146. />
  147. );
  148. // @ts-expect-error
  149. await tick();
  150. wrapper.update();
  151. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeFalsy();
  152. });
  153. });