This commit is contained in:
Philippe Torrel
2026-08-21 14:54:42 +02:00
parent e2da42e181
commit a5e74fd729
53 changed files with 2789 additions and 61 deletions

View File

@@ -0,0 +1,77 @@
import React from 'react';
type CategorySectionProps = {
categories: {
imgSrc: string;
imgAlt: string;
href: string;
linkText: string;
}[];
};
import { Link } from 'react-router-dom';
const CategorySection: React.FC<CategorySectionProps> = ({ categories }) => {
return (
<section aria-labelledby="category-heading">
<div className="category-section-wrapper">
<h2 id="category-heading" className="category-section-title">
Explore by Category
</h2>
<div className="category-section-grid-wrapper">
<Link to={categories[0].href} className="category-section-grid-main">
<img
src={categories[0].imgSrc}
alt={categories[0].imgAlt}
className="category-section-grid-main-img"
/>
<div aria-hidden="true" className="category-section-gradient-bg" />
<div className="category-section-cta-container">
<div>
<h3 className="category-section-cta-title">
<span className="category-section-cta-span" />
{categories[0].linkText}
</h3>
<p aria-hidden="true" className="category-section-cta">
Shop now
</p>
</div>
</div>
</Link>
{categories.slice(1).map((category, index) => (
<div key={index} className="category-section-categories-container">
<img
src={category.imgSrc}
alt={category.imgAlt}
className="category-section-categories-img"
/>
<div
aria-hidden="true"
className="category-section-gradient-bg"
/>
<div className="category-section-categories-cta-container">
<div>
<h3 className="category-section-cta-title">
<Link to={category.href}>
<span className="category-section-cta-span" />
{category.linkText}
</Link>
</h3>
<p aria-hidden="true" className="category-section-cta">
Shop now
</p>
</div>
</div>
</div>
))}
</div>
</div>
</section>
);
};
export default CategorySection;

View File

@@ -0,0 +1,55 @@
import React from 'react';
import { Link } from 'react-router-dom';
type NavigationItem = {
name: string;
href: string;
};
const navigationItems: NavigationItem[] = [
{
name: 'Home',
href: '/',
},
{
name: 'Women',
href: '/women',
},
{
name: 'Men',
href: '/men',
},
{
name: 'Accessories',
href: '/accessories',
},
];
type FooterProps = {
navigation?: NavigationItem[];
};
const Footer: React.FC<FooterProps> = ({ navigation = navigationItems }) => {
return (
<footer>
<div className="footer-wrapper">
<div className="footer-links-container">
{navigation.map((item) => (
<Link key={item.name} to={item.href}>
<span className="footer-links-text">{item.name}</span>
</Link>
))}
</div>
<div className="footer-copyright">
<p className="footer-copyright-text">
&copy; {new Date().getFullYear()} Vogue Junction, Inc. All rights
reserved.
</p>
</div>
</div>
</footer>
);
};
export default Footer;

View File

@@ -0,0 +1,53 @@
import { Link } from 'react-router-dom';
const Header = () => {
return (
<header>
{/* Mobile Header */}
<div className="mobile-header-wrapper">
<div className="header-container">
<Link to="/" className="mobile-header-logo-link">
<div className="logo-text">Vogue Junction</div>
</Link>
</div>
<div className="mobile-header-links-container">
<Link to="/women" className="header-link-text">
Women
</Link>
<Link to="/men" className="header-link-text">
Men
</Link>
<Link to="/accessories" className="header-link-text">
Accessories
</Link>
</div>
</div>
{/* Desktop Header */}
<div className="desktop-header-wrapper">
<div className="header-container">
<Link to="/" className="desktop-header-logo-link">
<div className="logo-text">Vogue Junction</div>
</Link>
<div className="desktop-header-links-container">
<Link to="/women" className="header-link-text">
Women
</Link>
<Link to="/men" className="header-link-text">
Men
</Link>
<Link to="/accessories" className="header-link-text">
Accessories
</Link>
</div>
</div>
</div>
<div className="header-border"></div>
</header>
);
};
export default Header;

View File

@@ -0,0 +1,23 @@
import React from 'react';
type HeroProps = {
companyName?: string;
};
const Hero: React.FC<HeroProps> = ({ companyName = 'Vogue Junction' }) => {
return (
<div className="hero-wrapper">
<div className="hero-text-container">
<h1 className="hero-title">Welcome to the world of {companyName}!</h1>
<p className="hero-subtitle">
Discover a diverse collection of stylish products for everyone. From
trendy apparel and accessories to timeless classics, we offer
something for every taste and occasion. Shop now and elevate your
style!
</p>
</div>
</div>
);
};
export default Hero;

View File

@@ -0,0 +1,71 @@
import React, { useState, useEffect } from 'react';
import { Product } from '../lib/datatypes';
type ImageGalleryProps = {
product: Product;
};
const ImageGallery: React.FC<ImageGalleryProps> = ({ product }: { product: Product }) => {
const [selectedImage, setSelectedImage] = useState(product.images[0]);
const [selectedIndex, setSelectedIndex] = useState(0);
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'ArrowRight') {
setSelectedIndex((prevIndex) => {
const nextIndex = (prevIndex + 1) % product.images.length;
setSelectedImage(product.images[nextIndex]);
return nextIndex;
});
}
if (event.key === 'ArrowLeft') {
setSelectedIndex((prevIndex) => {
const nextIndex = (prevIndex - 1 + product.images.length) % product.images.length;
setSelectedImage(product.images[nextIndex]);
return nextIndex;
});
}
};
useEffect(() => {
window.addEventListener('keydown', handleKeyDown);
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [product.images]);
return (
<div className="image-gallery-wrapper">
{/* Image selector */}
<div className="image-selector-wrapper">
<div className="image-selector-container">
{product.images.map((image, index) => (
<button
key={index}
className="image-selector-btn"
style={{
border: selectedIndex === index ? '2px solid #1e293b' : 'none',
}}
onClick={() => {
setSelectedImage(image);
setSelectedIndex(index);
}}>
<span className="screen-reader-text">{image}</span>
<span className="image-selector-img-wrapper">
<img src={image} alt={product.title} className="image-selector-img" />
</span>
</button>
))}
</div>
</div>
{/* Main Image Display */}
<div className="image-selector-main-img-wrapper">
<img src={selectedImage} alt={product.title} className="image-selector-main-img" />
</div>
</div>
);
};
export default ImageGallery;

View File

@@ -0,0 +1,24 @@
import React from 'react';
import { Product } from '../lib/datatypes';
import ProductListCard from './ProductListCard';
type ProductListProps = {
data: Product[];
};
const ProductList: React.FC<ProductListProps> = ({ data }) => {
return (
<div>
<h2 className="screen-reader-text">Products</h2>
<div className="products-list">
{data.map((product) => (
<ProductListCard key={product.id} product={product} />
))}
</div>
</div>
);
};
export default ProductList;

View File

@@ -0,0 +1,65 @@
import React from 'react';
import { Product } from '../lib/datatypes';
import { Link } from 'react-router-dom';
const ProductListCard = ({ product }: { product: Product }) => {
const { id, title, price, rating, stock, thumbnail } = product;
return (
<div className="product-card-container">
<div className="product-card-img-wrapper">
<img src={thumbnail} alt={title} className="product-card-img" />
</div>
<div className="product-card-info-box">
<h3 className="product-card-name">
<Link to={`/products/${id}`}>
<span aria-hidden="true" className="product-card-name-span" />
{title}
</Link>
</h3>
<div className="product-card-desc-box">
<p className="screen-reader-text">{Math.round(rating)} out of 5 stars</p>
<div className="product-card-ratings-wrapper">
{[0, 1, 2, 3, 4].map((ratingNumber) => (
<StarIcon
key={ratingNumber}
className="star-icons"
style={{
fill: rating > ratingNumber ? '#1e293b' : '#e5e7eb',
}}
aria-hidden="true"
/>
))}
</div>
<p className="product-card-stock">{stock} in stock</p>
</div>
<p className="product-card-price">
{Number(price).toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
})}
</p>
</div>
</div>
);
};
export default ProductListCard;
function StarIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" {...props}>
<path
fillRule="evenodd"
d="M10.788 3.21c.448-1.077 1.976-1.077 2.424 0l2.082 5.006 5.404.434c1.164.093 1.636 1.545.749 2.305l-4.117 3.527 1.257 5.273c.271 1.136-.964 2.033-1.96 1.425L12 18.354 7.373 21.18c-.996.608-2.231-.29-1.96-1.425l1.257-5.273-4.117-3.527c-.887-.76-.415-2.212.749-2.305l5.404-.434 2.082-5.005Z"
clipRule="evenodd"
/>
</svg>
);
}

View File

@@ -0,0 +1,798 @@
*,
*::before,
*::after {
box-sizing: border-box;
}
*,
html,
body {
margin: 0;
padding: 0;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
color: #0f172a;
}
button {
background-color: transparent;
border: none;
}
a {
text-decoration: none;
color: inherit;
}
header {
position: relative;
width: 100%;
}
footer {
border: 1px solid #e5e7eb;
border-top-width: 1px;
margin-top: 3.5rem /* 56px */;
}
.screen-reader-text {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
.star-icons {
height: 1.25rem /* 20px */;
width: 1.25rem /* 20px */;
flex-shrink: 0;
}
/* ===== Header Component ===== */
.logo-text {
font-size: 1.25rem /* 20px */;
line-height: 1.75rem /* 28px */;
font-weight: 600;
color: #1f2937;
}
.header-container {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
padding: 1.5rem 1rem; /* 24px 16px */
max-width: 80rem; /* 1280px */
margin: 0 auto;
}
.mobile-header-wrapper {
display: block;
}
.mobile-header-links-container {
display: flex;
justify-content: center;
gap: 1.5rem; /* 24px */
padding-bottom: 1rem /* 16px */;
}
.mobile-header-logo-link {
display: flex;
align-items: center;
justify-content: center;
gap: 1rem; /* 16px */
width: 100%;
}
.desktop-header-wrapper {
display: none;
}
.desktop-header-logo-link {
display: flex;
align-items: center;
gap: 1rem; /* 16px */
}
.desktop-header-links-container {
position: absolute;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 1.5rem; /* 24px */
}
.header-link-text {
padding: 0.5rem /* 8px */;
color: #1f2937;
}
.header-link-text:hover {
color: #4b5563;
}
.header-border {
border-bottom-width: 2px;
width: 100%;
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
border-color: #f3f4f6;
}
/* ===== Hero Component ===== */
.hero-wrapper {
max-width: 42rem /* 672px */;
margin: 0 auto;
padding: 6rem 1rem; /* 96px 16px */
}
.hero-text-container {
text-align: center;
}
.hero-title {
font-size: 2.25rem /* 36px */;
line-height: 2.5rem /* 40px */;
font-weight: 700;
letter-spacing: -0.025em;
color: #111827;
}
.hero-subtitle {
margin-top: 2.5rem /* 40px */;
font-size: 1.125rem /* 18px */;
line-height: 2rem /* 32px */;
color: #4b5563;
}
/* ===== CategorySection Component ===== */
.category-section-wrapper {
margin: 0 auto;
max-width: 80rem /* 1280px */;
padding: 2.5rem 1rem; /* 40px 16px */
}
.category-section-title {
font-size: 1.5rem /* 24px */;
line-height: 2rem /* 32px */;
font-weight: 700;
letter-spacing: -0.025em;
color: #111827;
}
.category-section-grid-wrapper {
margin-top: 1.5rem /* 24px */;
display: grid;
grid-template-columns: repeat(1, minmax(0, 1fr));
row-gap: 1.5rem /* 24px */;
}
.category-section-grid-main {
position: relative;
overflow: hidden;
border-radius: 0.5rem /* 8px */;
aspect-ratio: 1 / 2;
width: 100%;
height: 100%;
max-height: 250px;
}
.category-section-grid-main:hover {
opacity: 0.85;
}
.category-section-grid-main-img {
height: 100%;
width: 100%;
object-fit: cover;
object-position: top;
filter: grayscale(100%);
}
.category-section-gradient-bg {
position: absolute;
bottom: 0;
z-index: 100;
height: 100%;
width: 100%;
background: linear-gradient(to bottom, transparent, black);
opacity: 0.5;
}
.category-section-cta-container {
position: absolute;
z-index: 100;
bottom: 0;
display: flex;
align-items: flex-end;
padding: 1.5rem /* 24px */;
}
.category-section-cta-title {
font-weight: 600;
color: white;
}
.category-section-cta-span {
position: absolute;
inset: 0px;
z-index: 100;
}
.category-section-cta {
margin-top: 0.25rem /* 4px */;
font-size: 0.875rem /* 14px */;
line-height: 1.25rem /* 20px */;
color: white;
}
.category-section-categories-container {
position: relative;
aspect-ratio: 1 / 2;
overflow: hidden;
border-radius: 0.5rem /* 8px */;
height: 100%;
width: 100%;
max-height: 250px;
}
.category-section-categories-container:hover {
opacity: 0.85;
}
.category-section-categories-img {
height: 100%;
width: 100%;
object-fit: cover;
object-position: center;
filter: grayscale(100%);
}
.category-section-categories-cta-container {
position: absolute;
z-index: 100;
bottom: 0;
display: flex;
align-items: flex-end;
padding: 1.5rem; /* 24px */
}
/* ===== Footer Component ===== */
.footer-wrapper {
margin: 0 auto;
max-width: 80rem /* 1280px */;
padding: 3rem 1.5rem; /* 48px 24px */
}
.footer-links-container {
display: flex;
justify-content: center;
gap: 1.5rem; /* 24px */
}
.footer-links-text {
color: #9ca3af;
}
.footer-links-text:hover {
color: #4b5563;
}
.footer-copyright {
margin-top: 2rem /* 32px */;
}
.footer-copyright-text {
text-align: center;
font-size: 0.75rem /* 12px */;
line-height: 1rem /* 16px */;
line-height: 1.25rem /* 20px */;
color: #6b7280;
}
/* ===== ProductList Component ===== */
.products-list {
margin: 0 -1px;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
/* ===== ProductListCard Component ===== */
.product-card-container {
position: relative;
padding: 1rem;
}
.product-card-img-wrapper {
aspect-ratio: 1 / 1;
overflow: hidden;
border-radius: 0.5rem /* 8px */;
background-color: white;
}
.product-card-container:hover .product-card-img-wrapper {
opacity: 0.75;
}
.product-card-img {
height: 100%;
width: 100%;
object-fit: cover;
object-position: center;
}
.product-card-info-box {
padding-bottom: 1rem /* 16px */;
padding-top: 2.5rem /* 40px */;
text-align: center;
}
.product-card-name {
font-size: 0.875rem /* 14px */;
line-height: 1.25rem /* 20px */;
font-weight: 500;
color: #111827;
}
.product-card-name-span {
position: absolute;
inset: 0px;
}
.product-card-desc-box {
margin-top: 0.75rem /* 12px */;
display: flex;
flex-direction: column;
align-items: center;
}
.product-card-ratings-wrapper {
display: flex;
align-items: center;
}
.product-card-stock {
margin-top: 0.25rem /* 4px */;
font-size: 0.875rem /* 14px */;
line-height: 1.25rem /* 20px */;
color: #6b7280;
}
.product-card-price {
margin-top: 1rem /* 16px */;
font-size: 1rem /* 16px */;
line-height: 1.5rem /* 24px */;
font-weight: 500;
color: #111827;
}
/* ===== ImageGallery Component ===== */
.image-gallery-wrapper {
display: flex;
flex-direction: column-reverse;
}
.image-selector-wrapper {
margin-left: auto;
margin-right: auto;
margin-top: 1.5rem /* 24px */;
display: none;
width: 100%;
max-width: 42rem /* 672px */;
}
.image-selector-container {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 1.5rem /* 24px */;
}
.image-selector-btn {
position: relative;
display: flex;
height: 6rem /* 96px */;
cursor: pointer;
align-items: center;
justify-content: center;
border-radius: 0.375rem /* 6px */;
background-color: white;
font-size: 0.875rem /* 14px */;
line-height: 1.25rem /* 20px */;
font-weight: 500;
text-transform: uppercase;
color: #111827;
}
.image-selector-btn:hover {
background-color: #f9fafb;
}
.image-selector-img-wrapper {
position: absolute;
inset: 0px;
display: flex;
overflow: hidden;
border-radius: 0.375rem /* 6px */;
}
.image-selector-img {
height: 100%;
width: 100%;
object-fit: cover;
object-position: center;
}
.image-selector-main-img-wrapper {
aspect-ratio: 1 / 1;
width: 100%;
}
.image-selector-main-img {
height: 100%;
width: 100%;
object-fit: cover;
object-position: center;
}
/* ===== Category Page ===== */
.category-page-wrapper {
padding: 3.5rem 0; /* 56px 0 */
}
.category-page-container {
margin: 0 auto;
max-width: 80rem /* 1280px */;
overflow: hidden;
padding: 0 1rem; /* 0 16px */
}
.category-page-header {
display: flex;
justify-content: space-between;
align-items: top;
}
.category-page-header-title {
font-size: 1.5rem /* 24px */;
line-height: 2rem /* 32px */;
font-weight: 700;
letter-spacing: -0.025em;
color: #111827;
margin-bottom: 2rem /* 32px */;
}
.category-page-select {
margin: 0.5rem 0; /* 8px 0 */
display: block;
width: 11rem /* 176px */;
border: 1px solid #d1d5db;
border-radius: 0.375rem /* 6px */;
padding-top: 0.5rem /* 8px */;
padding-bottom: 0.5rem /* 8px */;
color: #0f172a;
}
.category-page-select:focus {
border: 1px solid #1e293b;
}
.category-page-products-wrapper {
margin-top: 2.5rem /* 40px */;
}
/* ===== Single Product Page ===== */
.back-button-wrapper {
margin: 0 auto;
max-width: 42rem /* 672px */;
padding-left: 1rem /* 16px */;
padding-right: 1rem /* 16px */;
padding-top: 2rem /* 32px */;
}
.back-button {
display: flex;
align-items: center;
margin-bottom: 1rem /* 16px */;
font-weight: 500;
margin-top: 1.5rem /* 24px */;
}
.back-button-icon {
height: 1.5rem /* 24px */;
width: 1.5rem /* 24px */;
stroke: #1e293b;
}
.back-button-icon-span {
margin-left: 0.75rem /* 12px */;
font-size: 1rem /* 16px */;
line-height: 1.5rem /* 24px */;
}
.product-page-wrapper {
margin: 0 auto;
max-width: 42rem /* 672px */;
padding: 2.5rem 1rem; /* 40px 16px */
}
.product-page-container {
display: block;
}
.product-page-info-container {
margin-top: 2.5rem /* 40px */;
padding-left: 1rem /* 16px */;
padding-right: 1rem /* 16px */;
}
.product-page-info-title {
font-size: 1.875rem /* 30px */;
line-height: 2.25rem /* 36px */;
font-weight: 700;
letter-spacing: -0.025em;
color: #111827;
}
.product-page-mt-3 {
margin-top: 0.75rem /* 12px */;
}
.product-page-mt-6 {
margin-top: 1.5rem /* 24px */;
}
.product-page-text {
font-size: 0.875rem /* 14px */;
line-height: 1.25rem /* 20px */;
color: #6b7280;
}
.product-page-info-price {
font-size: 1.875rem /* 30px */;
line-height: 2.25rem /* 36px */;
letter-spacing: -0.025em;
color: #111827;
}
.product-page-info-rating-container {
display: flex;
align-items: center;
}
.product-page-description {
font-size: 1rem /* 16px */;
line-height: 1.5rem /* 24px */;
line-height: 2;
color: #374151;
}
.product-page-tags-container {
display: flex;
align-items: center;
gap: 0.5rem; /* 8px */
}
.product-page-tag {
font-size: 0.75rem /* 12px */;
line-height: 1rem /* 16px */;
font-weight: 500;
text-transform: uppercase;
padding: 0.25rem 0.5rem;
border-radius: 9999px;
background-color: #1e293b;
color: white;
}
.product-page-reviews-wrapper {
margin-top: 3.5rem /* 56px */;
}
.product-page-reviews-title {
font-size: 1.5rem /* 24px */;
line-height: 2rem /* 32px */;
font-weight: 500;
color: #111827;
}
.product-page-reviews-container {
display: flex;
flex-direction: column;
gap: 1.25rem /* 20px */;
margin-top: 0.5rem /* 8px */;
}
.product-page-ratings-box {
display: flex;
align-items: center;
}
.product-page-reviews-text-box {
display: flex;
align-items: center;
gap: 1rem; /* 16px */
margin-top: 0.5rem /* 8px */;
}
.product-page-reviews-comment {
margin-top: 0.5rem /* 8px */;
font-size: 1.125rem /* 18px */;
line-height: 1.75rem /* 28px */;
color: #374151;
}
/* ===== Breakpoints ===== */
@media (min-width: 640px) {
.desktop-header-container {
padding: 1.5rem 2rem; /* 24px 32px */
}
.hero-wrapper {
padding: 6rem 2rem; /* 96px 32px */
}
.hero-title {
font-size: 3.75rem /* 60px */;
line-height: 1;
}
.category-section-wrapper {
padding: 2.5rem 1.5rem; /* 40px 24px */
}
.category-section-grid-wrapper {
grid-template-columns: repeat(2, minmax(0, 1fr));
grid-template-rows: repeat(2, minmax(0, 1fr));
column-gap: 1.5rem /* 24px */;
grid-row: span 2 / span 2;
}
.category-section-grid-main {
aspect-ratio: 1 / 1;
grid-row: span 2 / span 2;
max-height: 100%;
}
.category-section-grid-main-img {
object-position: center;
}
.category-section-categories-container {
position: relative;
max-height: 300px;
}
.category-section-categories-img {
position: absolute;
inset: 0px;
height: 100%;
width: 100%;
}
.category-section-categories-cta-container {
position: absolute;
inset: 0px;
}
.category-page-container {
padding: 0 1.5rem; /* 0 24px */
}
.products-list {
margin: 0;
}
.product-card-container {
padding: 1.5rem;
}
.back-button-wrapper {
padding-left: 1.5rem /* 24px */;
padding-right: 1.5rem /* 24px */;
}
.product-page-wrapper {
padding: 2.5rem 1.5rem; /* 40px 24px */
}
.image-selector-wrapper {
display: block;
}
.image-selector-main-img {
border-radius: 0.5rem /* 8px */;
}
.product-page-info-container {
margin-top: 4rem /* 64px */;
padding-left: 0px;
padding-right: 0px;
}
}
@media (min-width: 768px) {
footer {
margin-top: 5rem; /* 80px */
}
.mobile-header-wrapper {
display: none;
}
.desktop-header-wrapper {
display: block;
}
.logo-text {
font-size: 1.5rem /* 24px */;
line-height: 2rem /* 32px */;
}
.footer-wrapper {
display: flex;
align-items: center;
justify-content: space-between;
padding: 3rem 2rem; /* 48px 32px */
}
.footer-links-container {
order: 2;
}
.footer-copyright {
order: 1;
margin-top: 0;
}
.products-list {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
@media (min-width: 1024px) {
footer {
margin-top: 6rem; /* 96px */
}
.category-section-wrapper {
padding: 2.5rem 2rem /* 40px 32px */;
}
.category-page-container {
padding: 0 2rem; /* 0 32px */
}
.products-list {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.back-button-wrapper {
max-width: 80rem /* 1280px */;
padding-left: 2rem /* 32px */;
padding-right: 2rem /* 32px */;
}
.product-page-wrapper {
padding: 2.5rem 2rem; /* 40px 32px */
max-width: 80rem /* 1280px */;
}
.product-page-container {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
align-items: center;
column-gap: 2rem /* 32px */;
}
.image-selector-wrapper {
max-width: none;
}
.product-page-info-container {
margin-top: 0px;
}
}

View File

@@ -0,0 +1,45 @@
export interface Product {
id: number;
title: string;
description: string;
category: string;
price: number;
discountPercentage: number;
rating: number;
stock: number;
tags: string[];
brand: string;
sku: string;
weight: number;
dimensions: Dimensions;
warrantyInformation: string;
shippingInformation: string;
availabilityStatus: string;
reviews: Review[];
returnPolicy: string;
minimumOrderQuantity: number;
meta: Meta;
images: string[];
thumbnail: string;
}
export interface Dimensions {
width: number;
height: number;
depth: number;
}
export interface Review {
rating: number;
comment: string;
date: Date;
reviewerName: string;
reviewerEmail: string;
}
export interface Meta {
createdAt: Date;
updatedAt: Date;
barcode: string;
qrCode: string;
}

View File

@@ -0,0 +1,16 @@
import { Product } from './datatypes';
export const fetchProductsByCategory = async (
category: string
): Promise<Product[]> => {
try {
const response = await fetch(
`https://dummyjson.com/products/category/${category}`
);
const data = await response.json();
return data.products;
} catch (error) {
console.error(`Failed to fetch products for category ${category}:`, error);
return [];
}
};

View File

@@ -0,0 +1,39 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import Homepage from './pages/root';
import WomenProducts from './pages/women';
import MenProducts from './pages/men';
import AccessoryProducts from './pages/accessories';
import ProductPage from './pages/product';
const router = createBrowserRouter([
{
path: '/',
element: <Homepage />,
},
{
path: '/women',
element: <WomenProducts />,
},
{
path: '/men',
element: <MenProducts />,
},
{
path: '/accessories',
element: <AccessoryProducts />,
},
{
path: '/products/:productId',
element: <ProductPage />,
},
]);
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<RouterProvider router={router} />
</React.StrictMode>,
);

View File

@@ -0,0 +1,88 @@
import { useState, useEffect } from 'react';
import Header from '../components/Header';
import ProductList from '../components/ProductList';
import Footer from '../components/Footer';
import { Product } from '../lib/datatypes';
import { fetchProductsByCategory } from '../lib/helpers';
export default function AccessoryProducts() {
const [products, setProducts] = useState<Product[]>([]);
const [selectedCategory, setSelectedCategory] = useState<string>('all');
const categories = [
'all',
'mobile-accessories',
'sports-accessories',
'kitchen-accessories',
];
const fetchProducts = async () => {
try {
const fetchedProducts =
selectedCategory === 'all'
? await Promise.all(categories.slice(1).map(fetchProductsByCategory))
: await fetchProductsByCategory(selectedCategory);
const allProducts = Array.isArray(fetchedProducts)
? fetchedProducts.flat()
: fetchedProducts;
setProducts(allProducts);
} catch (error) {
console.error('Failed to fetch products:', error);
}
};
useEffect(() => {
fetchProducts();
}, [selectedCategory]);
return (
<div>
<Header />
<main className="category-page-wrapper">
<div className="category-page-container">
<div className="category-page-header">
<h2 id="favorites-heading" className="category-page-header-title">
Accessories
</h2>
<div>
<label htmlFor="category" className="screen-reader-text">
Category
</label>
<select
id="category"
name="category"
className="category-page-select"
value={selectedCategory}
onChange={(e) => setSelectedCategory(e.target.value)}
>
{categories.map((category) => (
<option key={category} value={category}>
{category
.split('-')
.filter((word) => word !== 'accessories')
.map(
(word) => word.charAt(0).toUpperCase() + word.slice(1)
)
.join(' ')}
</option>
))}
</select>
</div>
</div>
<div className="category-page-products-wrapper">
{products && <ProductList data={products} />}
</div>
</div>
</main>
<Footer />
</div>
);
}

View File

@@ -0,0 +1,83 @@
import { useState, useEffect } from 'react';
import Header from '../components/Header';
import ProductList from '../components/ProductList';
import Footer from '../components/Footer';
import { Product } from '../lib/datatypes';
import { fetchProductsByCategory } from '../lib/helpers';
export default function MenProducts() {
const [products, setProducts] = useState<Product[]>([]);
const [selectedCategory, setSelectedCategory] = useState<string>('all');
const categories = ['all', 'mens-shirts', 'mens-shoes', 'mens-watches'];
const fetchProducts = async () => {
try {
const fetchedProducts =
selectedCategory === 'all'
? await Promise.all(categories.slice(1).map(fetchProductsByCategory))
: await fetchProductsByCategory(selectedCategory);
const allProducts = Array.isArray(fetchedProducts)
? fetchedProducts.flat()
: fetchedProducts;
setProducts(allProducts);
} catch (error) {
console.error('Failed to fetch products:', error);
}
};
useEffect(() => {
fetchProducts();
}, [selectedCategory]);
return (
<div>
<Header />
<main className="category-page-wrapper">
<div className="category-page-container">
<div className="category-page-header">
<h2 id="favorites-heading" className="category-page-header-title">
Men Products
</h2>
<div>
<label htmlFor="category" className="screen-reader-text">
Category
</label>
<select
id="category"
name="category"
className="category-page-select"
value={selectedCategory}
onChange={(e) => setSelectedCategory(e.target.value)}
>
{categories.map((category) => (
<option key={category} value={category}>
{category
.split('-')
.filter((word) => word !== 'mens')
.map(
(word) => word.charAt(0).toUpperCase() + word.slice(1)
)
.join(' ')}
</option>
))}
</select>
</div>
</div>
<div className="category-page-products-wrapper">
{products && <ProductList data={products} />}
</div>
</div>
</main>
<Footer />
</div>
);
}

View File

@@ -0,0 +1,188 @@
import { useState, useEffect } from 'react';
import { Product, Review } from '../lib/datatypes';
import { useParams, useNavigate } from 'react-router-dom';
import Header from '../components/Header';
import ImageGallery from '../components/ImageGallery';
import Footer from '../components/Footer';
const ProductPage = () => {
const { productId } = useParams<{ productId: string }>();
const [product, setProduct] = useState<Product | null>(null);
const fetchProduct = async () => {
try {
const productRes = await fetch(`https://dummyjson.com/products/${productId}`);
const productData = await productRes.json();
setProduct(productData);
} catch (error) {
console.error('Failed to fetch products:', error);
}
};
useEffect(() => {
fetchProduct();
}, [productId]);
if (!product) {
return null;
}
return (
<div>
<Header />
<main>
<BackButton />
<div className="product-page-wrapper">
<div className="product-page-container">
<ImageGallery product={product} />
{/* Product info */}
<div className="product-page-info-container">
<h1 className="product-page-info-title">{product.title}</h1>
<div className="product-page-mt-3">
<h2 className="screen-reader-text">Product information</h2>
<p className="product-page-info-price">
{Number(product.price).toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
})}
</p>
{/* Rating */}
<div className="product-page-mt-3">
<h3 className="screen-reader-text">Rating</h3>
<div className="product-page-info-rating-container">
<div className="product-page-info-rating-container">
{[0, 1, 2, 3, 4].map((rating) => (
<StarIcon
key={rating}
className="star-icons"
style={{
fill: product.rating > rating ? '#1e293b' : '#e5e7eb',
}}
aria-hidden="true"
/>
))}
</div>
<p className="screen-reader-text">{product.rating} out of 5 stars</p>
</div>
</div>
{/* Availability */}
<div className="product-page-mt-3">
<p className="product-page-text">{product.stock} in stock</p>
</div>
{/* Description */}
<div className="product-page-mt-6">
<h3 className="screen-reader-text">Description</h3>
<p className="product-page-description">{product.description}</p>
</div>
{/* Tags */}
<div className="product-page-mt-6">
<h3 className="screen-reader-text">Tags</h3>
<div className="product-page-tags-container">
{product.tags.map((tag) => (
<span key={tag} className="product-page-tag">
{tag}
</span>
))}
</div>
</div>
</div>
</div>
<Reviews reviews={product.reviews} />
</div>
</div>
</main>
<Footer />
</div>
);
};
export default ProductPage;
function BackButton() {
const navigate = useNavigate();
return (
<div className="back-button-wrapper ">
<button onClick={() => navigate(-1)} className="back-button">
<ChevronRightIcon className="back-button-icon" />
<span className="back-button-icon-span">Back</span>
</button>
</div>
);
}
function Reviews({ reviews }: { reviews: Review[] }) {
return (
<div className="product-page-reviews-wrapper">
<h3 className="product-page-reviews-title">Reviews</h3>
<div className="product-page-reviews-container">
{reviews.map((review, index) => (
<div key={index} className="product-page-mt-6">
<div className="product-page-ratings-box">
{[0, 1, 2, 3, 4].map((rating) => (
<StarIcon
key={rating}
className="star-icons"
style={{
fill: review.rating > rating ? '#1e293b' : '#e5e7eb',
}}
aria-hidden="true"
/>
))}
</div>
<div className="product-page-reviews-text-box">
<p className="product-page-text">{review.reviewerName}</p>
<p className="product-page-text">{new Date(review.date).toLocaleDateString()}</p>
</div>
<p className="product-page-reviews-comment">{review.comment}</p>
</div>
))}
</div>
</div>
);
}
function ChevronRightIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
{...props}>
<path strokeLinecap="round" strokeLinejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" />
</svg>
);
}
function StarIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" {...props}>
<path
fillRule="evenodd"
d="M10.788 3.21c.448-1.077 1.976-1.077 2.424 0l2.082 5.006 5.404.434c1.164.093 1.636 1.545.749 2.305l-4.117 3.527 1.257 5.273c.271 1.136-.964 2.033-1.96 1.425L12 18.354 7.373 21.18c-.996.608-2.231-.29-1.96-1.425l1.257-5.273-4.117-3.527c-.887-.76-.415-2.212.749-2.305l5.404-.434 2.082-5.005Z"
clipRule="evenodd"
/>
</svg>
);
}

View File

@@ -0,0 +1,43 @@
import Header from '../components/Header';
import Hero from '../components/Hero';
import CategorySection from '../components/CategorySection';
import Footer from '../components/Footer';
const categories = [
{
imgSrc:
'https://images.unsplash.com/photo-1530011940847-04cba36df39f?q=80&w=1920',
imgAlt:
'Two female models sitting on a bed. Photo by Billie (@billiebodybrand) on Unsplash.',
href: '/women',
linkText: 'Women Clothing',
},
{
imgSrc:
'https://images.unsplash.com/photo-1595909315417-2edd382a56dc?q=80&w=1920',
imgAlt:
'Jumping rope, smartphone, sports bra, a pair of sneakers, and a water bottle. Photo by erica steeves on Unsplash.',
href: '/accessories',
linkText: 'Accessories',
},
{
imgSrc:
'https://images.unsplash.com/photo-1467779009031-53938b78ca38?q=80&w=1920',
imgAlt: 'Group of men sitting in a van. Photo by Luke Porter on Unsplash.',
href: '/men',
linkText: 'Men Clothing',
},
];
export default function Root() {
return (
<>
<Header />
<main>
<Hero companyName="Vogue Junction" />
<CategorySection categories={categories} />
</main>
<Footer />
</>
);
}

View File

@@ -0,0 +1,89 @@
import { useState, useEffect } from 'react';
import Header from '../components/Header';
import ProductList from '../components/ProductList';
import Footer from '../components/Footer';
import { Product } from '../lib/datatypes';
import { fetchProductsByCategory } from '../lib/helpers';
export default function WomenProducts() {
const [products, setProducts] = useState<Product[]>([]);
const [selectedCategory, setSelectedCategory] = useState<string>('all');
const categories = [
'all',
'womens-bags',
'womens-dresses',
'womens-shoes',
'womens-jewellery',
];
const fetchProducts = async () => {
try {
const fetchedProducts =
selectedCategory === 'all'
? await Promise.all(categories.slice(1).map(fetchProductsByCategory))
: await fetchProductsByCategory(selectedCategory);
const allProducts = Array.isArray(fetchedProducts)
? fetchedProducts.flat()
: fetchedProducts;
setProducts(allProducts);
} catch (error) {
console.error('Failed to fetch products:', error);
}
};
useEffect(() => {
fetchProducts();
}, [selectedCategory]);
return (
<div>
<Header />
<main className="category-page-wrapper">
<div className="category-page-container">
<div className="category-page-header">
<h2 id="favorites-heading" className="category-page-header-title">
Women Products
</h2>
<div>
<label htmlFor="category" className="screen-reader-text">
Category
</label>
<select
id="category"
name="category"
className="category-page-select"
value={selectedCategory}
onChange={(e) => setSelectedCategory(e.target.value)}
>
{categories.map((category) => (
<option key={category} value={category}>
{category
.split('-')
.filter((word) => word !== 'womens')
.map(
(word) => word.charAt(0).toUpperCase() + word.slice(1)
)
.join(' ')}
</option>
))}
</select>
</div>
</div>
<div className="category-page-products-wrapper">
{products && <ProductList data={products} />}
</div>
</div>
</main>
<Footer />
</div>
);
}

View File

@@ -0,0 +1,40 @@
import Hero from '../../src/components/Hero';
import { it, expect, describe } from 'vitest';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/vitest';
// TestSuite
describe('Hero', () => {
it('should render h1 element', () => {
render(<Hero />);
// screen.debug();
const heading = screen.getByRole('heading', { level: 1 });
expect(heading).toBeInTheDocument();
});
it('should render the company name when passed', () => {
render(<Hero companyName="My Company" />);
screen.debug(); // console Ausgabe der gerenderten Komponente (HTML-Elemente)
// Arrange
const heading = screen.getByRole('heading', { level: 1 });
// Act & Assert
expect(heading).toHaveTextContent('My Company');
});
it('should render the company name Vogue Junction as default', () => {
render(<Hero />);
screen.debug(); // console Ausgabe der gerenderten Komponente (HTML-Elemente)
// Arrange
const heading = screen.getByRole('heading', { level: 1 });
// Act & Assert
expect(heading).toHaveTextContent(/Vogue Junction/i);
});
});

View File

@@ -0,0 +1,60 @@
import { it, expect, describe } from 'vitest';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/vitest';
import userEvent from '@testing-library/user-event';
import ImageGallery from '../components/ImageGallery';
import { fakeProduct } from './__mocks__/product.mock';
// Dummy/Mock Daten
const product = fakeProduct;
// Arrange
const renderComponent = () => {
render(<ImageGallery product={product} />);
return {
images: screen.getAllByAltText(product.title),
buttons: screen.getAllByRole('button'),
};
};
describe('ImageGallery', () => {
it('should render three buttons', () => {
// Arrange
const { buttons } = renderComponent();
expect(buttons).toHaveLength(3);
});
it('should render four images', () => {
// Arrange
const { images } = renderComponent();
expect(images).toHaveLength(4);
});
it('should render the first image as main image', () => {
const { images } = renderComponent();
// screen.debug();
const mainImage = images[images.length - 1]; // letzte gerenderte Bild ist das erste im product Object
expect(mainImage).toBeInTheDocument();
expect(mainImage).toHaveAttribute(
'src',
'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/1.png',
);
});
it('should change the main image when the last image is clicked', async () => {
const { images, buttons } = renderComponent();
const user = userEvent.setup();
// fireEvent.click(buttons[2]);
await user.click(buttons[2]); // best practice
const mainImage = images[images.length - 1];
expect(mainImage).toHaveAttribute(
'src',
'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/3.png',
);
});
});

View File

@@ -0,0 +1,40 @@
import { it, expect, describe } from 'vitest';
import { MemoryRouter } from 'react-router-dom';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/vitest';
import { fakeProducts } from './__mocks__/products.mock';
import ProductList from '../components/ProductList';
const products = fakeProducts;
describe('ProductList', () => {
it('should render the correct number of products', () => {
render(
<MemoryRouter>
<ProductList data={products} />
</MemoryRouter>,
);
const headings = screen.getAllByRole('heading', { level: 3 });
expect(headings).toHaveLength(products.length);
});
it('should render the product list correctly with the title, image and price', () => {
render(
<MemoryRouter>
<ProductList data={products} />
</MemoryRouter>,
);
// screen.debug(); // gerenderte Ergebnis in der Vitest-UI-Konsole sichtbar
products.forEach((product) => {
const { title, thumbnail, price } = product;
expect(screen.getByText(title)).toBeInTheDocument(); // title
expect(screen.getByAltText(title)).toBeInTheDocument(); // image
expect(screen.getByAltText(title)).toHaveAttribute('src', thumbnail); // image src
expect(screen.getByText(`$${price}`)).toBeInTheDocument(); // price
});
});
});

View File

@@ -0,0 +1,56 @@
export const fakeProduct = {
id: 174,
title: 'Prada Women Bag',
description:
"The Prada Women Bag is an iconic designer bag that exudes elegance and luxury. Crafted with precision and featuring the Prada logo, it's a statement piece for fashion enthusiasts.",
category: 'womens-bags',
price: 599.99,
discountPercentage: 18.3,
rating: 3.52,
stock: 43,
tags: ['fashion accessories', 'designer bags'],
brand: 'Prada',
sku: 'WXX4YTJM',
weight: 4,
dimensions: { width: 23.45, height: 16.1, depth: 5.78 },
warrantyInformation: '1 week warranty',
shippingInformation: 'Ships overnight',
availabilityStatus: 'In Stock',
reviews: [
{
rating: 5,
comment: 'Excellent quality!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Samantha Howard',
reviewerEmail: 'samantha.howard@x.dummyjson.com',
},
{
rating: 4,
comment: 'Would buy again!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Henry Hill',
reviewerEmail: 'henry.hill@x.dummyjson.com',
},
{
rating: 3,
comment: 'Not worth the price!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Lucas Ramirez',
reviewerEmail: 'lucas.ramirez@x.dummyjson.com',
},
],
returnPolicy: '7 days return policy',
minimumOrderQuantity: 1,
meta: {
createdAt: new Date('2024-05-23T08:56:21.627Z'),
updatedAt: new Date('2024-05-23T08:56:21.627Z'),
barcode: '4590351278063',
qrCode: 'https://assets.dummyjson.com/public/qr-code.png',
},
images: [
'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/1.png',
'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/2.png',
'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/3.png',
],
thumbnail: 'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/thumbnail.png',
};

View File

@@ -0,0 +1,168 @@
export const fakeProducts = [
{
id: 174,
title: 'Prada Women Bag',
description:
"The Prada Women Bag is an iconic designer bag that exudes elegance and luxury. Crafted with precision and featuring the Prada logo, it's a statement piece for fashion enthusiasts.",
category: 'womens-bags',
price: 599.99,
discountPercentage: 18.3,
rating: 3.52,
stock: 43,
tags: ['fashion accessories', 'designer bags'],
brand: 'Prada',
sku: 'WXX4YTJM',
weight: 4,
dimensions: { width: 23.45, height: 16.1, depth: 5.78 },
warrantyInformation: '1 week warranty',
shippingInformation: 'Ships overnight',
availabilityStatus: 'In Stock',
reviews: [
{
rating: 5,
comment: 'Excellent quality!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Samantha Howard',
reviewerEmail: 'samantha.howard@x.dummyjson.com',
},
{
rating: 4,
comment: 'Would buy again!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Henry Hill',
reviewerEmail: 'henry.hill@x.dummyjson.com',
},
{
rating: 3,
comment: 'Not worth the price!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Lucas Ramirez',
reviewerEmail: 'lucas.ramirez@x.dummyjson.com',
},
],
returnPolicy: '7 days return policy',
minimumOrderQuantity: 1,
meta: {
createdAt: new Date('2024-05-23T08:56:21.627Z'),
updatedAt: new Date('2024-05-23T08:56:21.627Z'),
barcode: '4590351278063',
qrCode: 'https://assets.dummyjson.com/public/qr-code.png',
},
images: [
'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/1.png',
'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/2.png',
'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/3.png',
],
thumbnail: 'https://cdn.dummyjson.com/products/images/womens-bags/Prada%20Women%20Bag/thumbnail.png',
},
{
id: 90,
title: 'Puma Future Rider Trainers',
description:
'The Puma Future Rider Trainers offer a blend of retro style and modern comfort. Perfect for casual wear, these trainers provide a fashionable and comfortable option for everyday use.',
category: 'mens-shoes',
price: 89.99,
discountPercentage: 3.64,
rating: 4.85,
stock: 10,
tags: ['footwear', 'casual shoes'],
brand: 'Puma',
sku: '64ORN32I',
weight: 8,
dimensions: { width: 14.58, height: 25.54, depth: 19.57 },
warrantyInformation: '2 year warranty',
shippingInformation: 'Ships in 1 month',
availabilityStatus: 'In Stock',
reviews: [
{
rating: 5,
comment: 'Very happy with my purchase!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Lucas Allen',
reviewerEmail: 'lucas.allen@x.dummyjson.com',
},
{
rating: 4,
comment: 'Awesome product!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Mason Pearson',
reviewerEmail: 'mason.pearson@x.dummyjson.com',
},
{
rating: 4,
comment: 'Very satisfied!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Hunter Gordon',
reviewerEmail: 'hunter.gordon@x.dummyjson.com',
},
],
returnPolicy: '90 days return policy',
minimumOrderQuantity: 9,
meta: {
createdAt: new Date('2024-05-23T08:56:21.627Z'),
updatedAt: new Date('2024-05-23T08:56:21.627Z'),
barcode: '3562849555769',
qrCode: 'https://assets.dummyjson.com/public/qr-code.png',
},
images: [
'https://cdn.dummyjson.com/products/images/mens-shoes/Puma%20Future%20Rider%20Trainers/1.png',
'https://cdn.dummyjson.com/products/images/mens-shoes/Puma%20Future%20Rider%20Trainers/2.png',
'https://cdn.dummyjson.com/products/images/mens-shoes/Puma%20Future%20Rider%20Trainers/3.png',
'https://cdn.dummyjson.com/products/images/mens-shoes/Puma%20Future%20Rider%20Trainers/4.png',
],
thumbnail: 'https://cdn.dummyjson.com/products/images/mens-shoes/Puma%20Future%20Rider%20Trainers/thumbnail.png',
},
{
id: 101,
title: 'Apple AirPods Max Silver',
description:
'The Apple AirPods Max in Silver are premium over-ear headphones with high-fidelity audio, adaptive EQ, and active noise cancellation. Experience immersive sound in style.',
category: 'mobile-accessories',
price: 549.99,
discountPercentage: 11.7,
rating: 3.11,
stock: 7,
tags: ['electronics', 'over-ear headphones'],
brand: 'Apple',
sku: 'HPK82VDE',
weight: 4,
dimensions: { width: 7.73, height: 18.36, depth: 17.87 },
warrantyInformation: '3 months warranty',
shippingInformation: 'Ships in 1 month',
availabilityStatus: 'In Stock',
reviews: [
{
rating: 1,
comment: 'Waste of money!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Harper Kelly',
reviewerEmail: 'harper.kelly@x.dummyjson.com',
},
{
rating: 3,
comment: 'Not as described!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Abigail Rivera',
reviewerEmail: 'abigail.rivera@x.dummyjson.com',
},
{
rating: 5,
comment: 'Excellent quality!',
date: new Date('2024-05-23T08:56:21.627Z'),
reviewerName: 'Nora Russell',
reviewerEmail: 'nora.russell@x.dummyjson.com',
},
],
returnPolicy: '90 days return policy',
minimumOrderQuantity: 2,
meta: {
createdAt: new Date('2024-05-23T08:56:21.627Z'),
updatedAt: new Date('2024-05-23T08:56:21.627Z'),
barcode: '9261269777547',
qrCode: 'https://assets.dummyjson.com/public/qr-code.png',
},
images: ['https://cdn.dummyjson.com/products/images/mobile-accessories/Apple%20AirPods%20Max%20Silver/1.png'],
thumbnail:
'https://cdn.dummyjson.com/products/images/mobile-accessories/Apple%20AirPods%20Max%20Silver/thumbnail.png',
},
];

View File

@@ -0,0 +1,12 @@
import { it, describe, expect } from 'vitest';
import { add } from '../utils/helpers';
describe('add', () => {
it('should return 3 when 2 and 1 are passed', () => {
expect(add(2, 1)).toBe(3);
});
it('should return 0.3 when 0.1 and 0.2 are passed', () => {
expect(add(0.1, 0.2)).toBe(0.3);
});
});

View File

@@ -0,0 +1,12 @@
import { it, describe, expect } from 'vitest';
// Test Suite
describe('main', () => {
// Test Case
it('should pass', () => {
// AAA - Arrange , Act , Assert
const value = true; // Arrange
// Act & Assert
expect(value).toBe(true);
});
});

View File

@@ -0,0 +1,8 @@
import { test, describe, expect } from 'vitest';
import { multiply } from '../utils/helpers';
describe('multiply', () => {
test('Multiply returns 10 when 2 and 5 are passed', () => {
expect(multiply(2, 5)).toBe(10);
});
});

View File

@@ -0,0 +1,19 @@
// src/test/setup.ts
// npm i @testing-library/jest-dom -D
import { expect, afterEach } from 'vitest';
import { cleanup } from '@testing-library/react';
import * as matchers from '@testing-library/jest-dom/matchers';
// types für Testfunktionen
import '@testing-library/jest-dom/vitest';
// add jest-dom matchers to expect
expect.extend(matchers);
// Add cleanup function to run after each test
afterEach(() => {
cleanup();
});
// More setup code here, if needed

View File

@@ -0,0 +1,12 @@
export const multiply = (a: number, b: number): number => {
return Number(a) * Number(b);
};
export const add = (a: number, b: number): number => {
return parseFloat((Number(a) + Number(b)).toFixed(14).substring(0, 14));
};
export default {
multiply,
add,
};

View File

@@ -0,0 +1 @@
/// <reference types="vite/client" />