-
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 #36
base: master
Are you sure you want to change the base?
ht2 #36
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import Reviews from '../reviews'; | |
import Banner from '../banner'; | ||
import Rate from '../rate'; | ||
import styles from './restaurant.module.css'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const Restaurant = ({ restaurant }) => { | ||
const { id, name, menu, reviews } = restaurant; | ||
|
@@ -26,4 +27,13 @@ const Restaurant = ({ restaurant }) => { | |
); | ||
}; | ||
|
||
Restaurant.propTypes = { | ||
restaurant: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string, | ||
menu: PropTypes.array.isRequired, | ||
reviews: PropTypes.array.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. тут reviews нужно глубже описать, т.к. нам нужен rating для расчета averageRating |
||
}), | ||
}; | ||
|
||
export default Restaurant; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ import { useState, useMemo } from 'react'; | |
import Restaurant from '../restaurant'; | ||
import Tabs from '../tabs'; | ||
|
||
import PropTypes from 'prop-types'; | ||
|
||
export default function Restaurants({ restaurants }) { | ||
const [activeId, setActiveId] = useState(restaurants[0].id); | ||
|
||
|
@@ -23,3 +25,12 @@ export default function Restaurants({ restaurants }) { | |
</div> | ||
); | ||
} | ||
|
||
Restaurants.propTypes = { | ||
restaurants: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
name: PropTypes.string.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 |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import Review from './review'; | ||
import styles from './reviews.module.css'; | ||
|
||
import PropTypes from 'prop-types'; | ||
|
||
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> | ||
); | ||
}; | ||
|
||
export default Reviews; | ||
|
||
Reviews.propTypes = { | ||
reviews: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.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 |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Enzyme, { mount } from 'enzyme'; | ||
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; | ||
import Reviews from './reviews'; | ||
import { restaurants } from '../../fixtures'; | ||
import review from './review'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
const reviews = restaurants[0].reviews; | ||
|
||
describe('Reviews', () => { | ||
it('should render', () => { | ||
const wrapper = mount(<Reviews reviews={reviews} />); | ||
expect(wrapper.find('[data-id="reviews"]').length).toBe(1); | ||
}); | ||
|
||
it('should render all reviews', () => { | ||
const wrapper = mount(<Reviews reviews={reviews} />); | ||
expect(wrapper.find('[data-id="review"]').length).toBe(reviews.length); | ||
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. тут лучше проверять не наличие элементов, а сами имя юзера и прочее. |
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ import cn from 'classnames'; | |
|
||
import styles from './tabs.module.css'; | ||
|
||
import PropTypes from 'prop-types'; | ||
|
||
export default function Tabs({ tabs, activeId, onChange }) { | ||
return ( | ||
<div className={styles.tabs}> | ||
|
@@ -17,3 +19,13 @@ export default function Tabs({ tabs, activeId, onChange }) { | |
</div> | ||
); | ||
} | ||
|
||
Tabs.propTypes = { | ||
tabs: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
}) | ||
), | ||
activeId: PropTypes.string.isRequired, | ||
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.
это тест не на decrement, а на то, что у нас кол-во не уходит в минус