eventCause.spec.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. describe('EventCause', function () {
  6. const organization = TestStubs.Organization();
  7. const project = TestStubs.Project();
  8. const event = TestStubs.Event();
  9. const group = TestStubs.Group({firstRelease: {}});
  10. afterEach(function () {
  11. Client.clearMockResponses();
  12. act(() => CommitterStore.reset());
  13. });
  14. beforeEach(function () {
  15. CommitterStore.init();
  16. Client.addMockResponse({
  17. method: 'GET',
  18. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  19. body: {
  20. committers: [
  21. {
  22. author: {name: 'Max Bittker', id: '1'},
  23. commits: [
  24. {
  25. message:
  26. '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.',
  27. score: 4,
  28. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  29. repository: TestStubs.Repository(),
  30. dateCreated: '2018-03-02T18:30:26Z',
  31. },
  32. {
  33. message:
  34. '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.',
  35. score: 4,
  36. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  37. repository: TestStubs.Repository(),
  38. dateCreated: '2018-03-02T18:30:26Z',
  39. },
  40. ],
  41. },
  42. {
  43. author: {name: 'Somebody else', id: '2'},
  44. commits: [
  45. {
  46. message: 'fix: Make things less broken',
  47. score: 2,
  48. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  49. repository: TestStubs.Repository(),
  50. dateCreated: '2018-03-02T16:30:26Z',
  51. },
  52. ],
  53. },
  54. ],
  55. },
  56. });
  57. });
  58. it('renders', async function () {
  59. render(<EventCause project={project} event={event} group={group} />, {organization});
  60. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  61. expect(screen.queryByTestId('email-warning')).not.toBeInTheDocument();
  62. });
  63. it('expands', async function () {
  64. render(<EventCause project={project} event={event} group={group} />, {organization});
  65. userEvent.click(await screen.findByText('Show more'));
  66. expect(screen.getAllByTestId('commit-row')).toHaveLength(2);
  67. // and hides
  68. userEvent.click(screen.getByText('Show less'));
  69. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  70. });
  71. it('shows unassociated email warning', async function () {
  72. Client.addMockResponse({
  73. method: 'GET',
  74. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  75. body: {
  76. committers: [
  77. {
  78. author: {name: 'Somebody else', email: 'somebodyelse@email.com'},
  79. commits: [
  80. {
  81. message: 'fix: Make things less broken',
  82. score: 2,
  83. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  84. repository: TestStubs.Repository(),
  85. dateCreated: '2018-03-02T16:30:26Z',
  86. },
  87. ],
  88. },
  89. ],
  90. },
  91. });
  92. render(<EventCause project={project} event={event} group={group} />, {
  93. organization,
  94. });
  95. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  96. expect(screen.getByTestId('email-warning')).toBeInTheDocument();
  97. });
  98. });