Skip to content

Commit

Permalink
feat(card): create reusable card component
Browse files Browse the repository at this point in the history
- write test for card component
- create card component to be reusable
- add styling to the card component
- fix jest configuration
- add setup files for enzyme and jest

[Delivers #168078593]
  • Loading branch information
Oluwajuwon Fagbohungbe authored and Oluwajuwon Fagbohungbe committed Sep 4, 2019
1 parent e11700b commit 83cfb5e
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ client/dist
andela_creds.json
artifacts/
htmlcov/

revampedClient/coverage
revampedClient/**/**/__snapshots__/*.test.js.snap
1 change: 1 addition & 0 deletions revampedClient/__mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
1 change: 1 addition & 0 deletions revampedClient/__mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
21 changes: 21 additions & 0 deletions revampedClient/__tests__/components/cards/Card.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import React from 'react';

import { shallow } from 'enzyme';

import Card from '../../../components/cards/Card';

describe('Card component', () => {
it('should render correctly', () => {
const props = {
style: {
height: '10px',
width: '120px',
},
children: '<div>code block</div>',
};
const wrapper = shallow(<Card { ...props }/>);

expect(wrapper).toMatchSnapshot();
});
});
4 changes: 4 additions & 0 deletions revampedClient/__tests__/setup/setupEnzyme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });
8 changes: 8 additions & 0 deletions revampedClient/assets/components/_card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.card {
border-radius: 10px;
box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.1);
min-height: 200px;
min-width: 250px;
padding: 10px;
}
34 changes: 34 additions & 0 deletions revampedClient/components/cards/Card.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import PropTypes from 'prop-types';
import '../../assets/components/_card.scss';

/**
* @description - This component displays a reusable card
*
* @param {object} props { children, style }
*
* @returns JSX
*/
const Card = (props) => {
const {
children, style,
} = props;

return (
<div
className="card"
style={style}
>
{children}
</div>
);
};

Card.propTypes = {
children: PropTypes.string.isRequired,
style: PropTypes.objectOf(PropTypes.string),
};

Card.defaultProps = { style: {} };

export default Card;
4 changes: 3 additions & 1 deletion revampedClient/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ReactDOM from 'react-dom';
import './assets/style.scss';

ReactDOM.render(
<div>Andela Socials Revamping on process</div>,
<div>
Andela Socials Revamping on process
</div>,
document.getElementById('app')
);
16 changes: 16 additions & 0 deletions revampedClient/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
clearMocks: true,
coverageDirectory: 'coverage',
testRegex: '(roots/.*|(\\.|/)(test))\\.(js|jsx)?$',
testEnvironment: 'node',
testPathIgnorePatterns: [
'/node_modules/',
'/cypress/',
'/__tests__/setup/',
],
setupTestFrameworkScriptFile: '<rootDir>/__tests__/setup/setupEnzyme.js',
moduleNameMapper: {
'\\.(css|less|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',
'\\.(gif|ttf|eot|svg)$': '<rootDir>/__mocks__/fileMock.js',
},
};

0 comments on commit 83cfb5e

Please sign in to comment.