import React from 'react';
import PropTypes from 'prop-types';
import styles from './menu-link.style.css';
export default class MenuLink extends React.PureComponent {
render() {
return (
<div className={styles.menuLink} onClick={this.props.next}>
<span className={styles.label}>
{this.props.label}
</span>
</div>
);
}
}
MenuLink.defaultProps = {
label: '-',
next: () => {},
};
MenuLink.propTypes = {
alertStatus: PropTypes.numb.isRequired,
next: PropTypes.func.isRequired,
label: PropTypes.string.isRequired,
};
import { connect } from 'react-redux';
import MenuLink from './menu-link.component';
import { next } from '../actions/navigate';
function mapStateToProps(state) {
return {
alertStatus: state.alertStatus
};
}
function mapDispatchToProps() {
return {
next: () => dispatch(next()),
};
}
export default connect(
mapStateToProps,
mapDispatchToProps,
)(MenuLink);
import React from 'react';
import { shallow } from 'enzyme';
import renderer from 'react-test-renderer';
import MenuLink from './menu-link.component';
describe('[Unit] MenuLink', () => {
it('Should call the "next" function', () => {
const nextMock = jest.fn();
container.setProps({ alertStatus: 1, label: 'Link !', next: nextMock });
container.simulate('click');
expect(nextMock.mock.calls.length).toEqual(1);
});
});
describe('[Snapshot] MenuLink', () => {
const data = [
{
props: { alertStatus: 1, label: 'A sweet button', next: () => {} },
label: 'default',
},
];
data.forEach(({ props, label }) => {
const container = renderer.create(<MenuLink {...props} />);
it(`should match snapshot : ${label}`, () => {
expect(container.toJSON()).toMatchSnapshot();
});
});
});
"jest": {
"rootDir": ".",
"roots": [
"<rootDir>/client/source",
],
"moduleNameMapper": {
"^.+\\.(css|less)$": "<rootDir>/client/source/CSSStub.js",
"^.+\\.(jpg|png)$": "<rootDir>/client/source/imgStub.js",
"^.+\\.(svg)$": "<rootDir>/client/source/svgStub.js"
},
"collectCoverage": true,
"coverageDirectory": "<rootDir>/coverage",
"collectCoverageFrom": [
"**/*.{js,jsx}",
"!**/*.container.{js,jsx}"
],
"coveragePathIgnorePatterns": [
"<rootDir>/client/source/actions/",
"<rootDir>/node_modules/"
]
},