forked from nareshbhatia/react-testing-techniques
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProductViewStandalone.tsx
36 lines (32 loc) · 1.03 KB
/
ProductViewStandalone.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react';
import { NumberUtils } from '@react-force/number-utils';
import { Product } from '../../models';
import { CartService } from '../../services';
import { HorizontalContainer } from '../Containers';
import './ProductView.css';
export interface ProductViewStandaloneProps {
product: Product;
}
/** Standalone version of ProductView which handles the onClick internally */
export const ProductViewStandalone = ({
product,
}: ProductViewStandaloneProps) => {
const { id, name, description, price, photo } = product;
const handleClick = async () => {
await CartService.addProduct(id);
};
return (
<HorizontalContainer
testId="product"
className="product paper border-paper items-center"
onClick={handleClick}
>
<img className="product__photo" src={photo} alt={name} />
<div className="ml-4">
<h3>{name}</h3>
<p className="mt-0">{description}</p>
<p className="mb-0">${NumberUtils.formatAsMoney(price)}</p>
</div>
</HorizontalContainer>
);
};