eventOrGroupTitle.spec.tsx 4.0 KB

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