header.spec.tsx 5.8 KB

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