Skip to content

Commit

Permalink
#9 Add TabTemplate class
Browse files Browse the repository at this point in the history
  • Loading branch information
Takeharu Oshida committed Jun 12, 2015
1 parent 550d18d commit 455a5bd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
41 changes: 41 additions & 0 deletions components/TabTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

import React from 'react';

const styles = {
root: {
width: '100%',
position: 'relative',
textAlign: 'initial'
},
unselected: {
height: '0px',
overflow: 'hidden'
}
};

class TabTemplate extends React.Component {

render(){
let css = [styles.root];
if (!this.props.selected) {
css.push(styles.unselected);
}

return (
<div styles={css}>
{this.props.children}
</div>
);
}
}

TabTemplate.defaultProps = {
selected:false
};

TabTemplate.propTypes = {
selected: React.PropTypes.bool.isRequired
};

export default TabTemplate;
30 changes: 30 additions & 0 deletions test/components/TabTemplate_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
import React from 'react/addons';
import chai from 'chai';
let expect = chai.expect;
import TabTemplate from '../../components/TabTemplate';
const {TestUtils} = React.addons;

describe('Test of TabTemplate', () => {
let component;

beforeEach(() => {
});

it('should have default properties', function () {
component = TestUtils.renderIntoDocument(<TabTemplate><p>test tab</p></TabTemplate>);
expect(component.props.selected).to.be.equal(false);
});

it('It will be height 0 none when not selected', () => {
component = TestUtils.renderIntoDocument(<TabTemplate selected={false} ><p>not test tab</p></TabTemplate>);
const p = TestUtils.findRenderedDOMComponentWithTag(component, 'p');
expect(React.findDOMNode(p).parentNode.style.height).to.be.equal('0px');
});

it('It will have visible height when selected', () => {
component = TestUtils.renderIntoDocument(<TabTemplate selected={true}><p>not test tab</p></TabTemplate>);
const p = TestUtils.findRenderedDOMComponentWithTag(component, 'p');
expect(React.findDOMNode(p).parentNode.style.height).to.be.not.equal('0px');
});
});

0 comments on commit 455a5bd

Please sign in to comment.