commitRow.spec.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {fireEvent, render, screen} from 'sentry-test/reactTestingLibrary';
  2. import {textWithMarkupMatcher} from 'sentry-test/utils';
  3. import {openInviteMembersModal} from 'sentry/actionCreators/modal';
  4. import {CommitRow} from 'sentry/components/commitRow';
  5. import {Commit, Repository, User} from 'sentry/types';
  6. jest.mock('sentry/components/hovercard', () => {
  7. return {
  8. Header: ({children}: {children: React.ReactNode}) => children,
  9. Body: ({children}: {children: React.ReactNode}) => children,
  10. Hovercard: ({body}) => {
  11. return body;
  12. },
  13. };
  14. });
  15. jest.mock('sentry/actionCreators/modal', () => {
  16. return {
  17. ...jest.requireActual('sentry/actionCreators/modal'),
  18. openInviteMembersModal: jest.fn(),
  19. };
  20. });
  21. const baseCommit: Commit = {
  22. dateCreated: '2020-11-30T18:46:31Z',
  23. id: 'f7f395d14b2fe29a4e253bf1d3094d61e6ad4434',
  24. message: 'ref(commitRow): refactor to fc\n',
  25. author: {
  26. id: '0',
  27. username: 'author',
  28. ip_address: '192.168.1.1',
  29. email: 'author@commit.com',
  30. name: 'Author',
  31. } as User,
  32. repository: {
  33. id: '1',
  34. integrationId: '2',
  35. name: 'getsentry/sentry',
  36. dateCreated: '2019-11-30T18:46:31Z',
  37. } as Repository,
  38. releases: [],
  39. };
  40. // static/app/components/hovercard.tsx
  41. describe('commitRow', () => {
  42. it('renders custom avatar', () => {
  43. render(<CommitRow commit={baseCommit} customAvatar="Custom Avatar" />);
  44. expect(screen.getByText(/Custom Avatar/)).toBeInTheDocument();
  45. });
  46. it('renders invite flow for non associated users', () => {
  47. const commit: Commit = {
  48. ...baseCommit,
  49. author: {
  50. ...baseCommit.author,
  51. id: undefined as unknown as string,
  52. },
  53. } as Commit;
  54. render(<CommitRow commit={commit} />);
  55. expect(
  56. screen.getByText(
  57. textWithMarkupMatcher(
  58. /The email author@commit.com is not a member of your organization./
  59. )
  60. )
  61. ).toBeInTheDocument();
  62. fireEvent.click(screen.getByText(/Invite/));
  63. // @ts-ignore we are mocking this import
  64. expect(openInviteMembersModal.mock.calls[0][0].initialData[0].emails).toEqual(
  65. new Set(['author@commit.com'])
  66. );
  67. });
  68. it('renders commit info', () => {
  69. const commit: Commit = {
  70. ...baseCommit,
  71. author: {
  72. ...baseCommit.author,
  73. id: '0' as unknown as string,
  74. },
  75. } as Commit;
  76. render(<CommitRow commit={commit} />);
  77. expect(screen.getByText(/ref\(commitRow\): refactor to fc/)).toBeInTheDocument();
  78. });
  79. });