forked from BolajiOlajide/a_socials
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(card): create reusable card component
- 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 5, 2019
1 parent
87ce144
commit dcb0808
Showing
9 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'test-file-stub'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |