eventCause.spec.jsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {Client} from 'sentry/api';
  3. import EventCause from 'sentry/components/events/eventCause';
  4. import CommitterStore from 'sentry/stores/committerStore';
  5. import {CommitRow} from '../commitRow';
  6. import {QuickContextCommitRow} from '../discover/quickContextCommitRow';
  7. describe('EventCause', function () {
  8. const organization = TestStubs.Organization();
  9. const project = TestStubs.Project();
  10. const event = TestStubs.Event();
  11. const group = TestStubs.Group({firstRelease: {}});
  12. afterEach(function () {
  13. Client.clearMockResponses();
  14. act(() => CommitterStore.reset());
  15. });
  16. beforeEach(function () {
  17. CommitterStore.init();
  18. Client.addMockResponse({
  19. method: 'GET',
  20. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  21. body: {
  22. committers: [
  23. {
  24. author: {name: 'Max Bittker', id: '1'},
  25. commits: [
  26. {
  27. message:
  28. 'feat: Enhance suggested commits and add to alerts\n\n- Refactor components to use new shared CommitRow\n- Add Suspect Commits to alert emails\n- Refactor committers scanning code to handle various edge cases.',
  29. score: 4,
  30. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  31. repository: TestStubs.Repository(),
  32. dateCreated: '2018-03-02T18:30:26Z',
  33. },
  34. {
  35. message:
  36. 'feat: Enhance suggested commits and add to alerts\n\n- Refactor components to use new shared CommitRow\n- Add Suspect Commits to alert emails\n- Refactor committers scanning code to handle various edge cases.',
  37. score: 4,
  38. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  39. repository: TestStubs.Repository(),
  40. dateCreated: '2018-03-02T18:30:26Z',
  41. },
  42. ],
  43. },
  44. {
  45. author: {name: 'Somebody else', id: '2'},
  46. commits: [
  47. {
  48. message: 'fix: Make things less broken',
  49. score: 2,
  50. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  51. repository: TestStubs.Repository(),
  52. dateCreated: '2018-03-02T16:30:26Z',
  53. },
  54. ],
  55. },
  56. ],
  57. },
  58. });
  59. });
  60. it('Renders base commit row', async function () {
  61. render(
  62. <EventCause
  63. project={project}
  64. commitRow={CommitRow}
  65. eventId={event.id}
  66. group={group}
  67. />,
  68. {
  69. organization,
  70. }
  71. );
  72. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  73. expect(screen.queryByTestId('quick-context-commit-row')).not.toBeInTheDocument();
  74. expect(screen.queryByTestId('email-warning')).not.toBeInTheDocument();
  75. });
  76. it('Renders quick context commit row', async function () {
  77. render(
  78. <EventCause
  79. project={project}
  80. commitRow={QuickContextCommitRow}
  81. eventId={event.id}
  82. group={group}
  83. />,
  84. {
  85. organization,
  86. }
  87. );
  88. expect(await screen.findByTestId('quick-context-commit-row')).toBeInTheDocument();
  89. expect(screen.queryByTestId('commit-row')).not.toBeInTheDocument();
  90. });
  91. it('expands', async function () {
  92. render(
  93. <EventCause
  94. project={project}
  95. commitRow={CommitRow}
  96. eventId={event.id}
  97. group={group}
  98. />,
  99. {
  100. organization,
  101. }
  102. );
  103. userEvent.click(await screen.findByText('Show more'));
  104. expect(screen.getAllByTestId('commit-row')).toHaveLength(2);
  105. // and hides
  106. userEvent.click(screen.getByText('Show less'));
  107. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  108. });
  109. it('shows unassociated email warning', async function () {
  110. Client.addMockResponse({
  111. method: 'GET',
  112. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  113. body: {
  114. committers: [
  115. {
  116. author: {name: 'Somebody else', email: 'somebodyelse@email.com'},
  117. commits: [
  118. {
  119. message: 'fix: Make things less broken',
  120. score: 2,
  121. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  122. repository: TestStubs.Repository(),
  123. dateCreated: '2018-03-02T16:30:26Z',
  124. },
  125. ],
  126. },
  127. ],
  128. },
  129. });
  130. render(
  131. <EventCause
  132. project={project}
  133. commitRow={CommitRow}
  134. eventId={event.id}
  135. group={group}
  136. />,
  137. {
  138. organization,
  139. }
  140. );
  141. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  142. expect(screen.getByTestId('email-warning')).toBeInTheDocument();
  143. });
  144. });