eventOrGroupTitle.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {FC} from 'react';
  2. import {Organization} from 'fixtures/js-stubs/organization';
  3. import {routerContext} from 'fixtures/js-stubs/routerContext';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, screen} from 'sentry-test/reactTestingLibrary';
  6. import EventOrGroupTitle from 'sentry/components/eventOrGroupTitle';
  7. import {BaseGroup, EventOrGroupType, IssueCategory} from 'sentry/types';
  8. import {OrganizationContext} from 'sentry/views/organizationContext';
  9. describe('EventOrGroupTitle', function () {
  10. const data = {
  11. metadata: {
  12. type: 'metadata type',
  13. directive: 'metadata directive',
  14. uri: 'metadata uri',
  15. },
  16. culprit: 'culprit',
  17. };
  18. const {organization} = initializeOrg();
  19. const TestComponent: FC = ({children}) => (
  20. <OrganizationContext.Provider value={organization}>
  21. {children}
  22. </OrganizationContext.Provider>
  23. );
  24. it('renders with subtitle when `type = error`', function () {
  25. const wrapper = render(
  26. <TestComponent>
  27. <EventOrGroupTitle
  28. data={
  29. {
  30. ...data,
  31. ...{
  32. type: EventOrGroupType.ERROR,
  33. },
  34. } as BaseGroup
  35. }
  36. />
  37. </TestComponent>
  38. );
  39. expect(wrapper.container).toSnapshot();
  40. });
  41. it('renders with subtitle when `type = csp`', function () {
  42. const wrapper = render(
  43. <TestComponent>
  44. <EventOrGroupTitle
  45. data={
  46. {
  47. ...data,
  48. ...{
  49. type: EventOrGroupType.CSP,
  50. },
  51. } as BaseGroup
  52. }
  53. />
  54. </TestComponent>
  55. );
  56. expect(wrapper.container).toSnapshot();
  57. });
  58. it('renders with no subtitle when `type = default`', function () {
  59. const wrapper = render(
  60. <TestComponent>
  61. <EventOrGroupTitle
  62. data={
  63. {
  64. ...data,
  65. type: EventOrGroupType.DEFAULT,
  66. metadata: {
  67. ...data.metadata,
  68. title: 'metadata title',
  69. },
  70. } as BaseGroup
  71. }
  72. />
  73. </TestComponent>
  74. );
  75. expect(wrapper.container).toSnapshot();
  76. });
  77. it('renders with title override', function () {
  78. const routerContext = routerContext([
  79. {organization: Organization({features: ['custom-event-title']})},
  80. ]);
  81. render(
  82. <TestComponent>
  83. <EventOrGroupTitle
  84. data={
  85. {
  86. ...data,
  87. type: EventOrGroupType.ERROR,
  88. metadata: {
  89. ...data.metadata,
  90. title: 'metadata title',
  91. },
  92. } as BaseGroup
  93. }
  94. />
  95. </TestComponent>,
  96. {context: routerContext}
  97. );
  98. expect(screen.getByText('metadata title')).toBeInTheDocument();
  99. });
  100. it('does not render stack trace when issueCategory is performance', () => {
  101. render(
  102. <TestComponent>
  103. <EventOrGroupTitle
  104. data={
  105. {
  106. ...data,
  107. issueCategory: IssueCategory.PERFORMANCE,
  108. } as BaseGroup
  109. }
  110. withStackTracePreview
  111. />
  112. </TestComponent>
  113. );
  114. expect(screen.queryByTestId('stacktrace-preview')).not.toBeInTheDocument();
  115. });
  116. describe('performance issue list', () => {
  117. const perfData = {
  118. title: 'Hello',
  119. type: EventOrGroupType.TRANSACTION,
  120. issueCategory: IssueCategory.PERFORMANCE,
  121. metadata: {
  122. title: 'N+1 Query',
  123. },
  124. culprit: 'transaction name',
  125. } as BaseGroup;
  126. it('should correctly render title', () => {
  127. const routerContext = routerContext([
  128. {organization: Organization({features: ['custom-event-title']})},
  129. ]);
  130. render(
  131. <TestComponent>
  132. <EventOrGroupTitle data={perfData} />
  133. </TestComponent>,
  134. {context: routerContext}
  135. );
  136. expect(screen.getByText('N+1 Query')).toBeInTheDocument();
  137. expect(screen.getByText('transaction name')).toBeInTheDocument();
  138. });
  139. });
  140. });