闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.5 KiB

  1. import { expect } from 'chai';
  2. import { shallow } from 'enzyme';
  3. import sinon from 'sinon';
  4. import Button from '../../../app/javascript/mastodon/components/button';
  5. describe('<Button />', () => {
  6. it('renders a button element', () => {
  7. const wrapper = shallow(<Button />);
  8. expect(wrapper).to.match('button');
  9. });
  10. it('renders the given text', () => {
  11. const text = 'foo';
  12. const wrapper = shallow(<Button text={text} />);
  13. expect(wrapper.find('button')).to.have.text(text);
  14. });
  15. it('handles click events using the given handler', () => {
  16. const handler = sinon.spy();
  17. const wrapper = shallow(<Button onClick={handler} />);
  18. wrapper.find('button').simulate('click');
  19. expect(handler.calledOnce).to.equal(true);
  20. });
  21. it('does not handle click events if props.disabled given', () => {
  22. const handler = sinon.spy();
  23. const wrapper = shallow(<Button onClick={handler} disabled />);
  24. wrapper.find('button').simulate('click');
  25. expect(handler.called).to.equal(false);
  26. });
  27. it('renders a disabled attribute if props.disabled given', () => {
  28. const wrapper = shallow(<Button disabled />);
  29. expect(wrapper.find('button')).to.be.disabled();
  30. });
  31. it('renders the children', () => {
  32. const children = <p>children</p>;
  33. const wrapper = shallow(<Button>{children}</Button>);
  34. expect(wrapper.find('button')).to.contain(children);
  35. });
  36. it('renders the props.text instead of children', () => {
  37. const text = 'foo';
  38. const children = <p>children</p>;
  39. const wrapper = shallow(<Button text={text}>{children}</Button>);
  40. expect(wrapper.find('button')).to.have.text(text);
  41. expect(wrapper.find('button')).to.not.contain(children);
  42. });
  43. it('renders style="display: block; width: 100%;" if props.block given', () => {
  44. const wrapper = shallow(<Button block />);
  45. expect(wrapper.find('button')).to.have.className('button--block');
  46. });
  47. it('renders style="display: inline-block; width: auto;" by default', () => {
  48. const wrapper = shallow(<Button />);
  49. expect(wrapper.find('button')).to.not.have.className('button--block');
  50. });
  51. it('adds class "button-secondary" if props.secondary given', () => {
  52. const wrapper = shallow(<Button secondary />);
  53. expect(wrapper.find('button')).to.have.className('button-secondary');
  54. });
  55. it('does not add class "button-secondary" by default', () => {
  56. const wrapper = shallow(<Button />);
  57. expect(wrapper.find('button')).to.not.have.className('button-secondary');
  58. });
  59. });