Skip to content

Commit

Permalink
Issue #552 badge (#908)
Browse files Browse the repository at this point in the history
* Fixed Badge getStyle test.

* New structure for correct testing.

* Fixed Badge component test.
  • Loading branch information
IanCStewart authored and Sjaak Luthart committed Oct 12, 2017
1 parent 4ae94bb commit f83461e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
10 changes: 1 addition & 9 deletions src/badge/index.jsx → src/badge/component.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import Radium from 'radium';
import compose from 'recompose/compose';
import isNumber from 'lodash/isNumber';
import getStyles from './get-styles';
import themeable from '../themeable';

/** Used for displaying a (notification) counter */
const Badge = ({ value, maxValue, inverted, style, color, ...custom }) => {
Expand Down Expand Up @@ -43,9 +40,4 @@ Badge.defaultProps = {
maxValue: null
};

const enhance = compose(
themeable(),
Radium
);

export default enhance(Badge);
export default Badge;
11 changes: 11 additions & 0 deletions src/badge/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Radium from 'radium';
import compose from 'recompose/compose';
import themeable from '../themeable';
import Badge from './component';

const enhance = compose(
themeable(),
Radium
);

export default enhance(Badge);
1 change: 1 addition & 0 deletions test/badge/get-styles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Badge.getStyles', () => {
const style = getStyles.root('red', true);

expect(style).to.have.property('backgroundColor', '#FEFEFE');
expect(style).to.have.property('color', 'red');
});
});
});
29 changes: 16 additions & 13 deletions test/badge/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chai, { expect } from 'chai';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import Badge from '../../src/badge';
import Badge from '../../src/badge/component';
import getStyles from '../../src/badge/get-styles';

chai.use(sinonChai);
Expand All @@ -27,30 +27,33 @@ describe('Badge', () => {
global.navigator = undefined;
});

it('should always render a span element', () => {
const wrapper = shallow(<Badge {...props} />).dive();
it('should render a span element', () => {
const component = shallow(<Badge {...props} />);

expect(wrapper.find('span')).to.have.length(1);
expect(component.find('span')).to.have.length(1);
});

it('should pass the content prop to the span element if the value prop is not greater than the maxValue prop', () => {
const wrapper = shallow(<Badge {...props} />).dive();
it('should render content element', () => {
const component = shallow(<Badge {...props} />);

expect(wrapper.containsMatchingElement(<span>{1}</span>)).to.equal(true);
expect(component.find('span').containsMatchingElement(1)).to.equal(true);
});

it('should pass the content prop to the span element if the value prop is greater than the maxValue prop', () => {
props.value = 3;
const wrapper = shallow(<Badge {...props} />).dive();
it('should render maxValue+ element', () => {
const combinedProps = {
...props,
value: 3
};

expect(wrapper.containsMatchingElement(<span>2+</span>)).to.equal(true);
props.value = 1;
const component = shallow(<Badge {...combinedProps} />);

expect(component.find('span').containsMatchingElement('2+')).to.equal(true);
});

it('should get root styles', () => {
const spy = sinon.spy(getStyles, 'root');

shallow(<Badge {...props} />).dive();
shallow(<Badge {...props} />);
expect(spy).to.have.been.calledWith(
props.color, props.inverted, props.style
);
Expand Down

0 comments on commit f83461e

Please sign in to comment.