Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

ht2 #36

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16,316 changes: 16,316 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.5",
"enzyme": "^3.11.0",
"husky": "^7.0.4",
"prettier": "^2.5.0",
"prettier": "^2.5.1",
"pretty-quick": "^3.1.2"
}
}
5 changes: 5 additions & 0 deletions src/components/app/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { PureComponent } from 'react';
import Restaurants from '../restaurants';
import Header from '../header';
import PropTypes from 'prop-types';

export default class App extends PureComponent {
static propTypes = {
restaurants: PropTypes.array.isRequired,
};

render() {
return (
<div>
Expand Down
6 changes: 6 additions & 0 deletions src/components/banner/banner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styles from './banner.module.css';

import banner from './banner.jpg';
import PropTypes from 'prop-types';

const Banner = ({ heading, children }) => (
<div className={styles.banner}>
Expand All @@ -12,4 +13,9 @@ const Banner = ({ heading, children }) => (
</div>
);

Banner.propTypes = {
heading: PropTypes.string,
children: PropTypes.object,
};

export default Banner;
5 changes: 5 additions & 0 deletions src/components/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import styles from './button.module.css';

import { ReactComponent as PlusIcon } from '../../icons/plus.svg';
import { ReactComponent as MinusIcon } from '../../icons/minus.svg';
import PropTypes from 'prop-types';

const icons = {
plus: PlusIcon,
Expand All @@ -17,4 +18,8 @@ const Button = ({ icon, ...props }) => {
);
};

Button.propTypes = {
icon: PropTypes.string,
};

export default Button;
8 changes: 6 additions & 2 deletions src/components/product/product.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect } from 'react';
import PropTypes from 'prop-types';

import counter from '../../hocs/counter';
import styles from './product.module.css';
import Button from '../button';
import PropTypes from 'prop-types';

function Product({ product, amount, decrement, increment, fetchData }) {
useEffect(() => {
Expand All @@ -24,7 +24,11 @@ function Product({ product, amount, decrement, increment, fetchData }) {
{amount}
</div>
<div className={styles.buttons}>
<Button onClick={decrement} icon="minus" />
<Button
onClick={decrement}
data-id="product-decrement"
icon="minus"
/>
<Button
onClick={increment}
data-id="product-increment"
Expand Down
6 changes: 6 additions & 0 deletions src/components/product/product.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ describe('Product', () => {
expect(wrapper.find('[data-id="product-amount"]').text()).toBe('1');
});

it('should decrement amount', () => {
const wrapper = mount(<Product product={product} />);
wrapper.find('button[data-id="product-decrement"]').simulate('click');
expect(wrapper.find('[data-id="product-amount"]').text()).toBe('0');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это тест не на decrement, а на то, что у нас кол-во не уходит в минус

});

it('should fetch data', () => {
const fn = jest.fn();
mount(<Product product={product} fetchData={fn} />);
Expand Down
6 changes: 6 additions & 0 deletions src/components/rate/rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ReactComponent as Star } from '../../icons/star.svg';

import styles from './rate.module.css';

import PropTypes from 'prop-types';

const Rate = ({ value }) => (
<div>
{[...Array(5)].map((_, i) => (
Expand All @@ -15,4 +17,8 @@ const Rate = ({ value }) => (
</div>
);

Rate.propTypes = {
value: PropTypes.number,
};

export default Rate;
10 changes: 10 additions & 0 deletions src/components/restaurant/restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут reviews нужно глубже описать, т.к. нам нужен rating для расчета averageRating

}),
};

export default Restaurant;
11 changes: 11 additions & 0 deletions src/components/restaurants/restaurants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
})
),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут shape и arrayOf тоже должны быть isRequired

};
8 changes: 8 additions & 0 deletions src/components/reviews/review/review.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Rate from '../../rate';
import styles from './review.module.css';

import PropTypes from 'prop-types';

const Review = ({ user, text, rating }) => (
<div className={styles.review}>
<div className={styles.content}>
Expand All @@ -20,3 +22,9 @@ Review.defaultProps = {
};

export default Review;

Review.propTypes = {
user: PropTypes.string,
text: PropTypes.string,
rating: PropTypes.number,
};
14 changes: 12 additions & 2 deletions src/components/reviews/reviews.js
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,
})
),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут shape и arrayOf тоже должны быть isRequired

};
21 changes: 21 additions & 0 deletions src/components/reviews/reviews.test.js
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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут лучше проверять не наличие элементов, а сами имя юзера и прочее.

});
});
12 changes: 12 additions & 0 deletions src/components/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand All @@ -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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onChange должен быть тоже isRequired

};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8989,10 +8989,10 @@ prepend-http@^1.0.0:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=

prettier@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.0.tgz#a6370e2d4594e093270419d9cc47f7670488f893"
integrity sha512-FM/zAKgWTxj40rH03VxzIPdXmj39SwSjwG0heUcNFwI+EMZJnY93yAiKXM3dObIKAM5TA88werc8T/EwhB45eg==
prettier@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a"
integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==

pretty-bytes@^5.3.0:
version "5.6.0"
Expand Down