button.spec.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from 'react';
  2. import {mountWithTheme, shallow} 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 = shallow(
  8. <Button priority="primary" size="large">
  9. Button
  10. </Button>
  11. );
  12. expect(component).toMatchSnapshot();
  13. });
  14. it('renders react-router link', function() {
  15. const component = shallow(
  16. <Button to="/some/route">Router Link</Button>,
  17. routerContext
  18. );
  19. expect(component).toMatchSnapshot();
  20. });
  21. it('renders normal link', function() {
  22. const component = shallow(
  23. <Button href="/some/relative/url">Normal Link</Button>,
  24. routerContext
  25. );
  26. expect(component).toMatchSnapshot();
  27. });
  28. it('renders disabled normal link', function() {
  29. const component = shallow(
  30. <Button href="/some/relative/url">Normal Link</Button>,
  31. routerContext
  32. );
  33. expect(component).toMatchSnapshot();
  34. });
  35. it('calls `onClick` callback', function() {
  36. const spy = jest.fn();
  37. const component = mountWithTheme(<Button onClick={spy} />, routerContext);
  38. component.simulate('click');
  39. expect(spy).toHaveBeenCalled();
  40. });
  41. it('does not call `onClick` on disabled buttons', function() {
  42. const spy = jest.fn();
  43. const component = mountWithTheme(<Button onClick={spy} disabled />, routerContext);
  44. component.simulate('click');
  45. expect(spy).not.toHaveBeenCalled();
  46. });
  47. });