-
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
HT2 #39
base: master
Are you sure you want to change the base?
HT2 #39
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,24 @@ const Restaurant = ({ restaurant }) => { | |
); | ||
}; | ||
|
||
Restaurant.propTypes = { | ||
restaurant: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string, | ||
menu: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
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 |
||
id: PropTypes.string, | ||
name: PropTypes.string, | ||
price: PropTypes.number, | ||
ingredients: PropTypes.arrayOf(PropTypes.string), | ||
}) | ||
), | ||
reviews: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
rating: PropTypes.number.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. тут shape и arrayOf тоже должны быть isRequired |
||
).isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
export default Restaurant; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { useState, useMemo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import Restaurant from '../restaurant'; | ||
import Tabs from '../tabs'; | ||
|
@@ -23,3 +24,20 @@ export default function Restaurants({ restaurants }) { | |
</div> | ||
); | ||
} | ||
|
||
Restaurants.propTypes = { | ||
restaurants: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string, | ||
menu: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string, | ||
name: PropTypes.string, | ||
price: PropTypes.number, | ||
ingredients: PropTypes.arrayOf(PropTypes.string), | ||
}) | ||
), | ||
}) | ||
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. тут shape тоже должен быть isRequired |
||
).isRequired, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import Review from './review'; | ||
import styles from './reviews.module.css'; | ||
|
||
const Reviews = ({ reviews }) => { | ||
return ( | ||
<div className={styles.reviews}> | ||
<div className={styles.reviews} data-id="reviews"> | ||
{reviews.map((review) => ( | ||
<Review key={review.id} {...review} /> | ||
<Review key={review.id} {...review} data-id="review" /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
Review.propTypes = { | ||
reviews: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string, | ||
user: PropTypes.string, | ||
text: PropTypes.string, | ||
rating: PropTypes.number.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,38 @@ | ||
import Enzyme, { mount } from 'enzyme'; | ||
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; | ||
|
||
import Reviews from './reviews'; | ||
import { restaurants } from '../../fixtures'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
describe('Reviews', () => { | ||
const reviews = restaurants[0].reviews; | ||
const wrapper = mount(<Reviews reviews={reviews} />); | ||
|
||
it('should render', () => { | ||
expect(wrapper.find('[data-id="reviews"]').length).toBe(1); | ||
}); | ||
|
||
it('should have children', () => { | ||
expect(wrapper.find('[data-id="review"]').length).not.toBe(0); | ||
}); | ||
|
||
it('each child is not Anonymous', () => { | ||
wrapper.find('[data-id="review"]').forEach((el) => { | ||
expect(el.find('h4').text()).not.toBe('Anonymous'); | ||
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. тут лучше поиск делать по дата атрибутам, т.к. если мы поменяем в разметке на h5, то тест упадет 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. лучше проверить на на то, что это не Anonymous, а то, что отображается правильно имя |
||
}); | ||
}); | ||
|
||
it('each child name is not empty', () => { | ||
wrapper.find('[data-id="review"]').forEach((el) => { | ||
expect(el.find('h4').text().length).not.toBe(0); | ||
}); | ||
}); | ||
|
||
it('each child has description', () => { | ||
wrapper.find('[data-id="review"]').forEach((el) => { | ||
expect(el.find('p').text().length).not.toBe(0); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import cn from 'classnames'; | ||
|
||
import styles from './tabs.module.css'; | ||
|
@@ -17,3 +19,14 @@ export default function Tabs({ tabs, activeId, onChange }) { | |
</div> | ||
); | ||
} | ||
|
||
Tabs.propTypes = { | ||
tabs: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
label: PropTypes.string, | ||
}) | ||
), | ||
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. тут shape и arrayOf тоже должны быть isRequired |
||
activeId: PropTypes.string, | ||
onChange: PropTypes.func, | ||
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. onChange должен быть тоже isRequired |
||
}; |
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.
тут в пропах компонента нет такого ключа, как props, это просто все остальные пропы, которые мы неявно передаем дальше