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,
  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.TransactionSummary}
  63. hasWebVitals="yes"
  64. />
  65. );
  66. expect(screen.getByRole('tab', {name: 'Web Vitals'})).toBeInTheDocument();
  67. });
  68. it('should not render web vitals tab when 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. <TransactionHeader
  75. eventView={eventView}
  76. location={router.location}
  77. organization={organization}
  78. projects={[project]}
  79. projectId={project.id}
  80. transactionName="transaction_name"
  81. currentTab={Tab.TransactionSummary}
  82. hasWebVitals="no"
  83. />;
  84. expect(screen.queryByRole('tab', {name: 'Web Vitals'})).not.toBeInTheDocument();
  85. });
  86. it('should render web vitals tab when maybe and is frontend platform', function () {
  87. const {project, organization, router, eventView} = initializeData({
  88. platform: 'javascript',
  89. });
  90. MockApiClient.addMockResponse({
  91. url: '/organizations/org-slug/events-has-measurements/',
  92. body: {measurements: true},
  93. });
  94. render(
  95. <TransactionHeader
  96. eventView={eventView}
  97. location={router.location}
  98. organization={organization}
  99. projects={[project]}
  100. projectId={project.id}
  101. transactionName="transaction_name"
  102. currentTab={Tab.TransactionSummary}
  103. hasWebVitals="maybe"
  104. />
  105. );
  106. expect(screen.getByRole('tab', {name: 'Web Vitals'})).toBeInTheDocument();
  107. });
  108. it('should render web vitals tab when maybe and has measurements', async function () {
  109. const {project, organization, router, eventView} = initializeData();
  110. const eventHasMeasurementsMock = MockApiClient.addMockResponse({
  111. url: '/organizations/org-slug/events-has-measurements/',
  112. body: {measurements: true},
  113. });
  114. render(
  115. <TransactionHeader
  116. eventView={eventView}
  117. location={router.location}
  118. organization={organization}
  119. projects={[project]}
  120. projectId={project.id}
  121. transactionName="transaction_name"
  122. currentTab={Tab.TransactionSummary}
  123. hasWebVitals="maybe"
  124. />
  125. );
  126. await waitFor(() => expect(eventHasMeasurementsMock).toHaveBeenCalled());
  127. expect(screen.getByRole('tab', {name: 'Web Vitals'})).toBeInTheDocument();
  128. });
  129. it('should not render web vitals tab when maybe and has no measurements', async function () {
  130. const {project, organization, router, eventView} = initializeData();
  131. const eventHasMeasurementsMock = MockApiClient.addMockResponse({
  132. url: '/organizations/org-slug/events-has-measurements/',
  133. body: {measurements: false},
  134. });
  135. render(
  136. <TransactionHeader
  137. eventView={eventView}
  138. location={router.location}
  139. organization={organization}
  140. projects={[project]}
  141. projectId={project.id}
  142. transactionName="transaction_name"
  143. currentTab={Tab.TransactionSummary}
  144. hasWebVitals="maybe"
  145. />
  146. );
  147. await waitFor(() => expect(eventHasMeasurementsMock).toHaveBeenCalled());
  148. expect(screen.queryByRole('tab', {name: 'Web Vitals'})).not.toBeInTheDocument();
  149. });
  150. it('should render spans tab with feature', function () {
  151. const {project, organization, router, eventView} = initializeData({
  152. features: ['performance-suspect-spans-view'],
  153. });
  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.TransactionSummary}
  167. hasWebVitals="yes"
  168. />
  169. );
  170. expect(screen.getByRole('tab', {name: 'Spans'})).toBeInTheDocument();
  171. });
  172. });