header.spec.tsx 5.7 KB

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