react-toolbox/components/button/__test__/index.spec.js

46 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-11-04 22:20:00 +03:00
import expect from 'expect';
2016-05-25 01:25:43 +03:00
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import theme from '../theme.scss';
import Button, { Button as RawButton } from '../Button';
2015-11-04 22:20:00 +03:00
2016-05-25 01:25:43 +03:00
const getRenderedClassName = (tree, Component) => {
const rendered = TestUtils.findRenderedComponentWithType(tree, Component);
return ReactDOM.findDOMNode(rendered).getAttribute('class');
};
2015-11-04 22:20:00 +03:00
2016-05-25 01:25:43 +03:00
describe('Button', function () {
2015-11-04 22:20:00 +03:00
describe('#render', function () {
it('uses flat and neutral styles by default', function () {
2016-05-25 01:25:43 +03:00
const tree = TestUtils.renderIntoDocument(<Button theme={theme} />);
const className = getRenderedClassName(tree, RawButton);
expect(className).toContain(theme.flat);
expect(className).toContain(theme.neutral);
2015-11-04 22:20:00 +03:00
});
it('renders accent button with accent style', function () {
2016-05-25 01:25:43 +03:00
const tree = TestUtils.renderIntoDocument(<Button accent theme={theme} />);
const className = getRenderedClassName(tree, RawButton);
expect(className).toContain(theme.flat);
expect(className).toContain(theme.accent);
2015-11-04 22:20:00 +03:00
});
it('renders mini button with mini style', function () {
2016-05-25 01:25:43 +03:00
const tree = TestUtils.renderIntoDocument(<Button floating mini theme={theme} />);
const className = getRenderedClassName(tree, RawButton);
expect(className).toContain(theme.floating);
expect(className).toContain(theme.neutral);
expect(className).toContain(theme.mini);
2015-11-04 22:20:00 +03:00
});
it('renders mini accented button with both styles', function () {
2016-05-25 01:25:43 +03:00
const tree = TestUtils.renderIntoDocument(<Button accent mini theme={theme} />);
const className = getRenderedClassName(tree, RawButton);
expect(className).toContain(theme.flat);
expect(className).toContain(theme.accent);
expect(className).toContain(theme.mini);
2015-11-04 22:20:00 +03:00
});
});
});