button.spec.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {mountWithTheme, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import Button from 'sentry/components/button';
  3. describe('Button', function () {
  4. it('renders', function () {
  5. const {container} = mountWithTheme(<Button priority="primary">Button</Button>);
  6. expect(container).toSnapshot();
  7. });
  8. it('renders react-router link', function () {
  9. const {container} = mountWithTheme(<Button to="/some/route">Router Link</Button>);
  10. expect(container).toSnapshot();
  11. });
  12. it('renders normal link', function () {
  13. const {container} = mountWithTheme(
  14. <Button href="/some/relative/url">Normal Link</Button>
  15. );
  16. expect(container).toSnapshot();
  17. });
  18. it('renders disabled normal link', function () {
  19. const {container} = mountWithTheme(
  20. <Button href="/some/relative/url">Normal Link</Button>
  21. );
  22. expect(container).toSnapshot();
  23. });
  24. it('calls `onClick` callback', function () {
  25. const spy = jest.fn();
  26. mountWithTheme(<Button onClick={spy}>Click me</Button>);
  27. userEvent.click(screen.getByText('Click me'));
  28. expect(spy).toHaveBeenCalled();
  29. });
  30. it('does not call `onClick` on disabled buttons', function () {
  31. const spy = jest.fn();
  32. mountWithTheme(
  33. <Button onClick={spy} disabled>
  34. Click me
  35. </Button>
  36. );
  37. userEvent.click(screen.getByText('Click me'));
  38. expect(spy).not.toHaveBeenCalled();
  39. });
  40. });