header.spec.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import type {PlatformKey} from 'sentry/types';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import TransactionHeader from 'sentry/views/performance/transactionSummary/header';
  8. import Tab from 'sentry/views/performance/transactionSummary/tabs';
  9. type InitialOpts = {
  10. features?: string[];
  11. platform?: PlatformKey;
  12. };
  13. function initializeData(opts?: InitialOpts) {
  14. const {features, platform} = opts ?? {};
  15. const project = ProjectFixture({platform});
  16. const organization = OrganizationFixture({
  17. projects: [project],
  18. features: features ?? [],
  19. });
  20. const initialData = initializeOrg({
  21. organization,
  22. router: {
  23. location: {
  24. query: {
  25. project: project.id,
  26. },
  27. },
  28. },
  29. project,
  30. projects: [],
  31. });
  32. const router = initialData.router;
  33. const eventView = EventView.fromSavedQuery({
  34. id: undefined,
  35. version: 2,
  36. name: '',
  37. fields: ['transaction.status'], // unused fields
  38. projects: [parseInt(project.id, 10)],
  39. });
  40. return {
  41. project,
  42. organization,
  43. router,
  44. eventView,
  45. };
  46. }
  47. describe('Performance > Transaction Summary Header', function () {
  48. beforeEach(function () {
  49. MockApiClient.clearMockResponses();
  50. });
  51. it('should render web vitals tab when yes', function () {
  52. const {project, organization, router, eventView} = initializeData();
  53. MockApiClient.addMockResponse({
  54. url: '/organizations/org-slug/events-has-measurements/',
  55. body: {measurements: true},
  56. });
  57. render(
  58. <TransactionHeader
  59. eventView={eventView}
  60. location={router.location}
  61. organization={organization}
  62. projects={[project]}
  63. projectId={project.id}
  64. transactionName="transaction_name"
  65. currentTab={Tab.TRANSACTION_SUMMARY}
  66. hasWebVitals="yes"
  67. />
  68. );
  69. expect(screen.getByRole('tab', {name: 'Web Vitals'})).toBeInTheDocument();
  70. });
  71. it('should not render web vitals tab when hasWebVitals=no', function () {
  72. const {project, organization, router, eventView} = initializeData();
  73. MockApiClient.addMockResponse({
  74. url: '/organizations/org-slug/events-has-measurements/',
  75. body: {measurements: true},
  76. });
  77. render(
  78. <TransactionHeader
  79. eventView={eventView}
  80. location={router.location}
  81. organization={organization}
  82. projects={[project]}
  83. projectId={project.id}
  84. transactionName="transaction_name"
  85. currentTab={Tab.TRANSACTION_SUMMARY}
  86. hasWebVitals="no"
  87. />
  88. );
  89. expect(screen.queryByRole('tab', {name: 'Web Vitals'})).not.toBeInTheDocument();
  90. });
  91. it('should render web vitals tab when maybe and is frontend platform', function () {
  92. const {project, organization, router, eventView} = initializeData({
  93. platform: 'javascript',
  94. });
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/events-has-measurements/',
  97. body: {measurements: true},
  98. });
  99. render(
  100. <TransactionHeader
  101. eventView={eventView}
  102. location={router.location}
  103. organization={organization}
  104. projects={[project]}
  105. projectId={project.id}
  106. transactionName="transaction_name"
  107. currentTab={Tab.TRANSACTION_SUMMARY}
  108. hasWebVitals="maybe"
  109. />
  110. );
  111. expect(screen.getByRole('tab', {name: 'Web Vitals'})).toBeInTheDocument();
  112. });
  113. it('should render web vitals tab when maybe and has measurements', async function () {
  114. const {project, organization, router, eventView} = initializeData();
  115. const eventHasMeasurementsMock = MockApiClient.addMockResponse({
  116. url: '/organizations/org-slug/events-has-measurements/',
  117. body: {measurements: true},
  118. });
  119. render(
  120. <TransactionHeader
  121. eventView={eventView}
  122. location={router.location}
  123. organization={organization}
  124. projects={[project]}
  125. projectId={project.id}
  126. transactionName="transaction_name"
  127. currentTab={Tab.TRANSACTION_SUMMARY}
  128. hasWebVitals="maybe"
  129. />
  130. );
  131. await waitFor(() => expect(eventHasMeasurementsMock).toHaveBeenCalled());
  132. expect(screen.getByRole('tab', {name: 'Web Vitals'})).toBeInTheDocument();
  133. });
  134. it('should not render web vitals tab when maybe and has no measurements', async function () {
  135. const {project, organization, router, eventView} = initializeData();
  136. const eventHasMeasurementsMock = MockApiClient.addMockResponse({
  137. url: '/organizations/org-slug/events-has-measurements/',
  138. body: {measurements: false},
  139. });
  140. MockApiClient.addMockResponse({
  141. url: '/organizations/org-slug/replay-count/',
  142. body: {},
  143. });
  144. render(
  145. <TransactionHeader
  146. eventView={eventView}
  147. location={router.location}
  148. organization={organization}
  149. projects={[project]}
  150. projectId={project.id}
  151. transactionName="transaction_name"
  152. currentTab={Tab.TRANSACTION_SUMMARY}
  153. hasWebVitals="maybe"
  154. />
  155. );
  156. await waitFor(() => expect(eventHasMeasurementsMock).toHaveBeenCalled());
  157. expect(screen.queryByRole('tab', {name: 'Web Vitals'})).not.toBeInTheDocument();
  158. });
  159. it('should render spans tab with feature', function () {
  160. const {project, organization, router, eventView} = initializeData({});
  161. MockApiClient.addMockResponse({
  162. url: '/organizations/org-slug/events-has-measurements/',
  163. body: {measurements: true},
  164. });
  165. render(
  166. <TransactionHeader
  167. eventView={eventView}
  168. location={router.location}
  169. organization={organization}
  170. projects={[project]}
  171. projectId={project.id}
  172. transactionName="transaction_name"
  173. currentTab={Tab.TRANSACTION_SUMMARY}
  174. hasWebVitals="yes"
  175. />
  176. );
  177. expect(screen.getByRole('tab', {name: 'Spans'})).toBeInTheDocument();
  178. });
  179. });