button.spec.jsx 1.5 KB

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