button.spec.jsx 1.4 KB

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