lastCommit.spec.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import LastCommit from 'sentry/components/lastCommit';
  3. describe('LastCommit', function () {
  4. let mockedCommit;
  5. const mockedCommitTitle = '(improve) Add Links to Spike-Protection Email (#2408)';
  6. beforeEach(() => {
  7. mockedCommit = TestStubs.Commit();
  8. });
  9. it('renders', function () {
  10. const wrapper = render(<LastCommit commit={mockedCommit} />);
  11. expect(wrapper.container).toSnapshot();
  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. });