about summary refs log tree commit diff
path: root/app/javascript/themes/glitch/components/__tests__/button-test.js
diff options
context:
space:
mode:
authorkibigo! <marrus-sh@users.noreply.github.com>2017-11-17 19:11:18 -0800
committerkibigo! <marrus-sh@users.noreply.github.com>2017-11-17 19:29:16 -0800
commit45c44989c8fb6e24badd18bb83ac5f68de0aceaf (patch)
tree794d088986d8518506e3e1eec0c8ffb7da5604b8 /app/javascript/themes/glitch/components/__tests__/button-test.js
parent5a9982b425d3db65d813eb0314a27cea16f0f52d (diff)
Forking glitch theme
Diffstat (limited to 'app/javascript/themes/glitch/components/__tests__/button-test.js')
-rw-r--r--app/javascript/themes/glitch/components/__tests__/button-test.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/app/javascript/themes/glitch/components/__tests__/button-test.js b/app/javascript/themes/glitch/components/__tests__/button-test.js
new file mode 100644
index 000000000..924ba39dc
--- /dev/null
+++ b/app/javascript/themes/glitch/components/__tests__/button-test.js
@@ -0,0 +1,82 @@
+import { shallow } from 'enzyme';
+import React from 'react';
+import renderer from 'react-test-renderer';
+import Button from '../button';
+
+describe('<Button />', () => {
+  it('renders a button element', () => {
+    const component = renderer.create(<Button />);
+    const tree      = component.toJSON();
+
+    expect(tree).toMatchSnapshot();
+  });
+
+  it('renders the given text', () => {
+    const text      = 'foo';
+    const component = renderer.create(<Button text={text} />);
+    const tree      = component.toJSON();
+
+    expect(tree).toMatchSnapshot();
+  });
+
+  it('handles click events using the given handler', () => {
+    const handler = jest.fn();
+    const button  = shallow(<Button onClick={handler} />);
+    button.find('button').simulate('click');
+
+    expect(handler.mock.calls.length).toEqual(1);
+  });
+
+  it('does not handle click events if props.disabled given', () => {
+    const handler = jest.fn();
+    const button  = shallow(<Button onClick={handler} disabled />);
+    button.find('button').simulate('click');
+
+    expect(handler.mock.calls.length).toEqual(0);
+  });
+
+  it('renders a disabled attribute if props.disabled given', () => {
+    const component = renderer.create(<Button disabled />);
+    const tree      = component.toJSON();
+
+    expect(tree).toMatchSnapshot();
+  });
+
+  it('renders the children', () => {
+    const children  = <p>children</p>;
+    const component = renderer.create(<Button>{children}</Button>);
+    const tree      = component.toJSON();
+
+    expect(tree).toMatchSnapshot();
+  });
+
+  it('renders the props.text instead of children', () => {
+    const text      = 'foo';
+    const children  = <p>children</p>;
+    const component = renderer.create(<Button text={text}>{children}</Button>);
+    const tree      = component.toJSON();
+
+    expect(tree).toMatchSnapshot();
+  });
+
+  it('renders class="button--block" if props.block given', () => {
+    const component = renderer.create(<Button block />);
+    const tree      = component.toJSON();
+
+    expect(tree).toMatchSnapshot();
+  });
+
+  it('adds class "button-secondary" if props.secondary given', () => {
+    const component = renderer.create(<Button secondary />);
+    const tree      = component.toJSON();
+
+    expect(tree).toMatchSnapshot();
+  });
+
+  it('renders title if props.title is given', () => {
+    const component = renderer.create(<Button title='foo' />);
+    const tree      = component.toJSON();
+
+    expect(tree).toMatchSnapshot();
+  });
+});