add simple tests to more components

This commit is contained in:
Sérgio Ramos 2016-10-28 16:49:00 +01:00
parent 3243941056
commit d108a14ff4
2 changed files with 48 additions and 24 deletions

View File

@ -7,7 +7,7 @@ const styles = require('./style.css');
const Avatar = ({ const Avatar = ({
color, color,
src, src,
name, name = '',
className, className,
style style
}) => { }) => {
@ -22,32 +22,26 @@ const Avatar = ({
background: color background: color
}; };
const fill = () => { const letter = name.split('')[0];
if ( src ) { const av = src ? (
return ( <img
<img alt={name}
alt={name} className={styles.picture}
className={styles.picture} src={src}
src={src} style={style}
style={style} />
/> ) : (
); <p
} else { className={styles.letter}
const letter = name.split('')[0]; style={style}
return ( >
<p {letter}
className={styles.letter} </p>
style={style} );
>
{letter}
</p>
);
}
};
return ( return (
<div className={cn} style={style}> <div className={cn} style={style}>
{fill()} {av}
</div> </div>
); );
}; };

View File

@ -6,8 +6,38 @@ const {
shallow shallow
} = enzyme; } = enzyme;
test('renders <Avatar> without exploding', (t) => {
const Avatar = require('../src/components/avatar');
const wrapper = shallow(<Avatar />);
t.deepEqual(wrapper.length, 1);
});
test('renders <Base> without exploding', (t) => { test('renders <Base> without exploding', (t) => {
const Base = require('../src/components/base'); const Base = require('../src/components/base');
const wrapper = shallow(<Base />); const wrapper = shallow(<Base />);
t.deepEqual(wrapper.length, 1); t.deepEqual(wrapper.length, 1);
}); });
test('renders <Button> without exploding', (t) => {
const Button = require('../src/components/button');
const wrapper = shallow(<Button />);
t.deepEqual(wrapper.length, 1);
});
test('renders <Checkbox> without exploding', (t) => {
const Checkbox = require('../src/components/checkbox');
const wrapper = shallow(<Checkbox />);
t.deepEqual(wrapper.length, 1);
});
test('renders <Column> without exploding', (t) => {
const Column = require('../src/components/column');
const wrapper = shallow(<Column />);
t.deepEqual(wrapper.length, 1);
});
test('renders <Container> without exploding', (t) => {
const Container = require('../src/components/container');
const wrapper = shallow(<Container />);
t.deepEqual(wrapper.length, 1);
});