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