-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prop types, tests #37
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import cn from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { ReactComponent as Star } from '../../icons/star.svg'; | ||
|
||
import styles from './rate.module.css'; | ||
|
||
const Rate = ({ value }) => ( | ||
<div> | ||
<div > | ||
{[...Array(5)].map((_, i) => ( | ||
<Star | ||
data-id="review-rating" | ||
key={i} | ||
className={cn(styles.star, { [styles.checked]: i <= value - 1 })} | ||
/> | ||
))} | ||
</div> | ||
); | ||
|
||
Rate.propTypes = { | ||
value: PropTypes.number.isRequired | ||
}; | ||
|
||
export default Rate; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { useMemo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import Menu from '../menu'; | ||
import Reviews from '../reviews'; | ||
import Banner from '../banner'; | ||
|
@@ -26,4 +28,26 @@ const Restaurant = ({ restaurant }) => { | |
); | ||
}; | ||
|
||
Restaurant.propTypes = { | ||
restaurant: | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
menu: PropTypes.arrayOf( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. слишком глубоко описаны propTypes, нем тут не нужна детализация по menu и reviews |
||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
price: PropTypes.number.isRequired, | ||
ingredients: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
})).isRequired, | ||
reviews: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
user: PropTypes.string.isRequired, | ||
rating: PropTypes.number.isRequired, | ||
text: PropTypes.string.isRequired, | ||
})).isRequired, | ||
}).isRequired | ||
}; | ||
|
||
export default Restaurant; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
import Review from './review'; | ||
import styles from './reviews.module.css'; | ||
|
||
import PropTypes from 'prop-types'; | ||
|
||
const Reviews = ({ reviews }) => { | ||
return ( | ||
<div className={styles.reviews}> | ||
{reviews.map((review) => ( | ||
<div className={styles.reviews} data-id="reviews"> | ||
{reviews && reviews.map((review) => ( | ||
<Review key={review.id} {...review} /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
Reviews.propTypes = { | ||
reviews: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
})).isRequired | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут arrayOf тоже должен быть isRequired |
||
|
||
export default Reviews; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Enzyme, { mount } from 'enzyme'; | ||
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; | ||
import Reviews from './reviews'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
const reviews = [{ | ||
id: '5db6247b-ab1c-49db-be1f-8dd27fd38b81', | ||
text: 'Finally! This place is amazing place for breakfast, lunch, dinner and supper', | ||
rating: 5, | ||
}]; | ||
|
||
describe('Reviews', () => { | ||
it(' should render Reviews', () => { | ||
const wrapper = mount(<Reviews reviews={reviews}/>); | ||
expect(wrapper.find('[data-id="reviews"]').length).toBe(1); | ||
}); | ||
|
||
it('should render Rate', () => { | ||
const wrapper = mount(<Reviews reviews={reviews}/>); | ||
expect(wrapper.find('svg[data-id="review-rating"]').length).toBe(5); | ||
}); | ||
|
||
it('should render default name', () => { | ||
const wrapper = mount(<Reviews reviews={reviews}/>); | ||
expect(wrapper.find('h4[data-id="review-name"]').text()).toEqual('Anonymous') | ||
}); | ||
|
||
it('should render text', () => { | ||
const wrapper = mount(<Reviews reviews={reviews}/>); | ||
expect(wrapper.find('p[data-id="review-text"]').text()).toEqual('Finally! This place is amazing place for breakfast, lunch, dinner and supper') | ||
}); | ||
|
||
it('allows us to set props', () => { | ||
const wrapper = mount(<Reviews reviews={reviews} />); | ||
expect(wrapper.props().reviews[0].rating).toEqual(5); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не нужно проверять props, тем более те, которых не должно быть |
||
wrapper.setProps({ bar: 'foo' }); | ||
expect(wrapper.props().bar).toEqual('foo'); | ||
}); | ||
|
||
it('reviews is an array of objects', () => { | ||
const wrapper = mount(<Reviews reviews={reviews} />); | ||
expect(reviews).toHaveLength(1); | ||
}); | ||
|
||
it('review has properties', () => { | ||
const wrapper = mount(<Reviews reviews={reviews} />); | ||
expect(reviews[0]).toHaveProperty('id'); | ||
expect(reviews[0]).toHaveProperty('text'); | ||
expect(reviews[0]).toHaveProperty('rating'); | ||
}); | ||
|
||
it('reviews rating is a number', () => { | ||
const wrapper = mount(<Reviews reviews={reviews} />); | ||
expect(typeof reviews[0].rating).toEqual("number"); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это тест не на decrement, а на то, что у нас кол-во не уходит в минус