lastCommit.spec.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import {Commit} from 'sentry-fixture/commit';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import LastCommit from 'sentry/components/lastCommit';
  4. describe('LastCommit', function () {
  5. let mockedCommit;
  6. const mockedCommitTitle = '(improve) Add Links to Spike-Protection Email (#2408)';
  7. beforeEach(() => {
  8. mockedCommit = Commit();
  9. });
  10. it('renders', function () {
  11. render(<LastCommit commit={mockedCommit} />);
  12. });
  13. it('links to the commit in GitHub', function () {
  14. mockedCommit.repository.provider = {id: 'github'};
  15. const mockedCommitURL = `${mockedCommit.repository?.url}/commit/${mockedCommit.id}`;
  16. render(<LastCommit commit={mockedCommit} />);
  17. expect(screen.getByText(mockedCommitTitle)).toBeInTheDocument();
  18. expect(screen.getByText(mockedCommitTitle)).toHaveAttribute('href', mockedCommitURL);
  19. });
  20. it('displays the commit with its shortened ID if it has no message', function () {
  21. mockedCommit.message = null;
  22. render(<LastCommit commit={mockedCommit} />);
  23. expect(screen.queryByText(mockedCommitTitle)).not.toBeInTheDocument();
  24. expect(screen.getByText(mockedCommit.id.slice(0, 7))).toBeInTheDocument();
  25. });
  26. });