button.spec.tsx 1.3 KB

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