header.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import EventView from 'sentry/utils/discover/eventView';
  4. import {OrganizationContext} from 'sentry/views/organizationContext';
  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 = TestStubs.Organization({
  15. projects: [project],
  16. 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. const WrappedComponent = ({
  46. hasWebVitals,
  47. platform,
  48. features,
  49. }: {
  50. hasWebVitals: 'yes' | 'no' | 'maybe';
  51. } & InitialOpts) => {
  52. const {project, organization, router, eventView} = initializeData({features, platform});
  53. return (
  54. <OrganizationContext.Provider value={organization}>
  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={hasWebVitals}
  64. />
  65. </OrganizationContext.Provider>
  66. );
  67. };
  68. describe('Performance > Transaction Summary Header', function () {
  69. let wrapper;
  70. afterEach(function () {
  71. MockApiClient.clearMockResponses();
  72. wrapper.unmount();
  73. });
  74. it('should render web vitals tab when yes', async function () {
  75. wrapper = mountWithTheme(<WrappedComponent hasWebVitals="yes" />);
  76. await tick();
  77. wrapper.update();
  78. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeTruthy();
  79. });
  80. it('should not render web vitals tab when no', async function () {
  81. wrapper = mountWithTheme(<WrappedComponent hasWebVitals="no" />);
  82. await tick();
  83. wrapper.update();
  84. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeFalsy();
  85. });
  86. it('should render web vitals tab when maybe and is frontend platform', async function () {
  87. wrapper = mountWithTheme(
  88. <WrappedComponent hasWebVitals="maybe" platform="javascript" />
  89. );
  90. await tick();
  91. wrapper.update();
  92. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeTruthy();
  93. });
  94. it('should render web vitals tab when maybe and has measurements', async function () {
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/events-has-measurements/',
  97. body: {measurements: true},
  98. });
  99. wrapper = mountWithTheme(<WrappedComponent hasWebVitals="maybe" />);
  100. await tick();
  101. wrapper.update();
  102. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeTruthy();
  103. });
  104. it('should not render web vitals tab when maybe and has no measurements', async function () {
  105. MockApiClient.addMockResponse({
  106. url: '/organizations/org-slug/events-has-measurements/',
  107. body: {measurements: false},
  108. });
  109. wrapper = mountWithTheme(<WrappedComponent hasWebVitals="maybe" />);
  110. await tick();
  111. wrapper.update();
  112. expect(wrapper.find('ListLink[data-test-id="web-vitals-tab"]').exists()).toBeFalsy();
  113. });
  114. it('should render spans tab with feature', async function () {
  115. wrapper = mountWithTheme(
  116. <WrappedComponent
  117. hasWebVitals="yes"
  118. features={['performance-suspect-spans-view']}
  119. />
  120. );
  121. await tick();
  122. wrapper.update();
  123. expect(wrapper.find('ListLink[data-test-id="spans-tab"]').exists()).toBeTruthy();
  124. });
  125. });