quickContextCommitRow.spec.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import {Commit, Repository, RepositoryStatus, User} from 'sentry/types';
  3. import {QuickContextCommitRow} from './quickContextCommitRow';
  4. const defaultCommit: Commit = {
  5. dateCreated: '2020-11-30T18:46:31Z',
  6. id: 'f7f395d14b2fe29a4e253bf1d3094d61e6ad4434',
  7. message: 'feat(quick-context-commit-row): Added new component\n',
  8. author: {
  9. id: '0',
  10. username: 'abdKhan',
  11. ip_address: '192.168.1.1',
  12. email: 'abd@commit.com',
  13. name: 'Abdullah Khan ',
  14. } as User,
  15. repository: {
  16. id: '1',
  17. integrationId: '2',
  18. name: 'getsentry/sentry',
  19. dateCreated: '2019-11-30T18:46:31Z',
  20. } as Repository,
  21. releases: [],
  22. };
  23. describe('Quick Context Commit Row', () => {
  24. it('Renders author name specific avatar', () => {
  25. render(<QuickContextCommitRow commit={defaultCommit} />);
  26. expect(screen.getByText(/AK/i)).toBeInTheDocument();
  27. });
  28. it('Renders commit link text with no PR', () => {
  29. render(<QuickContextCommitRow commit={defaultCommit} />);
  30. expect(
  31. screen.getByTestId('quick-context-commit-row-commit-link')
  32. ).toBeInTheDocument();
  33. expect(
  34. screen.queryByTestId('quick-context-commit-row-pr-link')
  35. ).not.toBeInTheDocument();
  36. expect(screen.getByText(/View commit/i)).toBeInTheDocument();
  37. expect(screen.getByText(/f7f395d/i)).toBeInTheDocument();
  38. expect(screen.getByText(/by/i)).toBeInTheDocument();
  39. expect(screen.getByText(/Abdullah Khan/i)).toBeInTheDocument();
  40. });
  41. it('Renders pull request link', () => {
  42. const commit: Commit = {
  43. ...defaultCommit,
  44. pullRequest: {
  45. id: '9',
  46. title: 'cool pr',
  47. externalUrl: 'https://github.com/getsentry/sentry/pull/1',
  48. repository: {
  49. id: '14',
  50. name: 'example',
  51. url: '',
  52. provider: {
  53. id: 'unknown',
  54. name: 'Unknown Provider',
  55. },
  56. status: RepositoryStatus.ACTIVE,
  57. dateCreated: '2022-10-07T19:35:27.370422Z',
  58. integrationId: '14',
  59. externalSlug: 'org-slug',
  60. },
  61. },
  62. };
  63. render(<QuickContextCommitRow commit={commit} />);
  64. const pullRequestLink = screen.getByText(
  65. /feat\(quick-context-commit-row\): Added new component/
  66. );
  67. expect(screen.queryByTestId('quick-context-commit-row-pr-link')).toBeInTheDocument();
  68. expect(pullRequestLink).toBeInTheDocument();
  69. expect(pullRequestLink).toHaveAttribute(
  70. 'href',
  71. 'https://github.com/getsentry/sentry/pull/1'
  72. );
  73. expect(
  74. screen.getByTestId('quick-context-commit-row-commit-link')
  75. ).toBeInTheDocument();
  76. });
  77. });