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

Fix: Inconsistent product cards #99

Merged
merged 1 commit into from
Jul 17, 2024
Merged
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
12 changes: 10 additions & 2 deletions src/__test__/home/ProductGridFour.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,16 @@ describe('ProductGridFour Component', () => {

// Check that product details are displayed correctly
mockProducts.slice(0, 4).forEach((product) => {
expect(screen.getByText(product.name)).toBeInTheDocument();
expect(screen.getByText(product.shortDesc)).toBeInTheDocument();
expect(
screen.getByText(
`${product.name.substring(0, 17)}${product.name.length > 18 ? '...' : ''}`
)
).toBeInTheDocument();
expect(
screen.getAllByText(
`${product.shortDesc.substring(0, 27)}${product.shortDesc.length > 28 ? '...' : ''}`
)[0]
).toBeInTheDocument();
expect(screen.getByAltText(product.name)).toBeInTheDocument();
expect(screen.getByAltText(product.name)).toHaveAttribute(
'src',
Expand Down
8 changes: 6 additions & 2 deletions src/__test__/home/productCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ describe('ProductCard Component', () => {
it('renders the ProductCard component with product details', () => {
render(<ProductCard product={mockProduct} />);

const productName = screen.getByText(mockProduct.name);
const productName = screen.getByText(
`${mockProduct.name.substring(0, 17)}${mockProduct.name.length > 18 ? '...' : ''}`
);
expect(productName).toBeInTheDocument();

const productDesc = screen.getByText(mockProduct.shortDesc);
const productDesc = screen.getByText(
`${mockProduct.shortDesc.substring(0, 27)}${mockProduct.shortDesc.length > 28 ? '...' : ''}`
);
expect(productDesc).toBeInTheDocument();

const productImage = screen.getByAltText(mockProduct.name);
Expand Down
8 changes: 6 additions & 2 deletions src/__test__/home/productList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ describe('ProductsList Component', () => {
);

mockProducts.forEach((product) => {
const productName = screen.getByText(product.name);
const productName = screen.getByText(
`${product.name.substring(0, 17)}${product.name.length > 18 ? '...' : ''}`
);
expect(productName).toBeInTheDocument();

const productDesc = screen.getByText(product.shortDesc);
const productDesc = screen.getByText(
`${product.shortDesc.substring(0, 27)}${product.shortDesc.length > 28 ? '...' : ''}`
);
expect(productDesc).toBeInTheDocument();

const productImage = screen.getByAltText(product.name);
Expand Down
23 changes: 20 additions & 3 deletions src/__test__/shop.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,18 @@ describe('Shop Component', () => {
mock.onGet(`${import.meta.env.VITE_BASE_URL}/search`).reply(200, {
message: 'success',
data: [
{ id: 1, name: 'Product 1', image: '/product1.jpg' },
{ id: 2, name: 'Product 2', image: '/product2.jpg' },
{
id: 1,
name: 'Product 1',
shortDesc: 'short desc',
image: '/product1.jpg',
},
{
id: 2,
name: 'Product 2',
shortDesc: 'short desc',
image: '/product2.jpg',
},
],
});

Expand All @@ -75,7 +85,14 @@ describe('Shop Component', () => {
it('filters products based on user input', async () => {
mock.onGet(`${import.meta.env.VITE_BASE_URL}/search`).reply(200, {
message: 'success',
data: [{ id: 1, name: 'Product 1', image: '/product1.jpg' }],
data: [
{
id: 1,
name: 'Product 1',
shortDesc: 'short desc',
image: '/product1.jpg',
},
],
});

renderWithProviders(<Shop />);
Expand Down
6 changes: 4 additions & 2 deletions src/components/home/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ function ProductCard({ product }: ProductCardProps) {
>
<div className="flex justify-between items-center">
<h3 className="text-lg font-semibold text-gray-800">
{product.name}
{product.name.substring(0, 17)}
{product.name.length > 18 && '...'}
</h3>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -42,7 +43,8 @@ function ProductCard({ product }: ProductCardProps) {
</svg>
</div>
<p className="text-gray-400 tracking-wide font-light text-sm">
{product.shortDesc}
{product.shortDesc.substring(0, 27)}
{product.shortDesc.length > 28 && '...'}
</p>
<div className="flex items-center gap-2 py-2 w-fit">
<div className="flex items-center font-medium gap-2 relative w-fit">
Expand Down
Loading