feat(ux-30): ensure touch targets exceed 44px across CartDrawer, Wiki, Contact, Footer and MobileBottomNav with regression tests
This commit is contained in:
1 parent
6d0dea07f8
commit
f5c970f82e
6 files changed
+157
-16
No files matched your search
@@ -112,7 +112,7 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
|
||||
</div>
|
||||
<h3 id="cart-drawer-title" className="text-xl font-black text-medical-gray-900 italic">سبد خرید</h3>
|
||||
</div>
|
||||
<button aria-label="بستن سبد خرید" onClick={onClose} className="p-2 hover:bg-medical-gray-50 rounded-full transition-colors">
|
||||
<button aria-label="بستن سبد خرید" onClick={onClose} className="min-w-[44px] min-h-[44px] flex items-center justify-center p-2 hover:bg-medical-gray-50 rounded-full transition-colors cursor-pointer">
|
||||
<X className="w-6 h-6 text-medical-gray-400" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -152,7 +152,7 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
|
||||
type="button"
|
||||
aria-label={`کاهش تعداد ${item.product.nameFa || item.product.name}`}
|
||||
onClick={() => updateQuantity(item.product.id, item.quantity - 1)}
|
||||
className="p-1 hover:text-canina-blue transition-colors"
|
||||
className="min-w-[44px] min-h-[44px] flex items-center justify-center p-1 hover:text-canina-blue transition-colors cursor-pointer"
|
||||
data-testid="minus-btn"
|
||||
>
|
||||
<Minus className="w-3 h-3" />
|
||||
@@ -162,7 +162,7 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
|
||||
type="button"
|
||||
aria-label={`افزایش تعداد ${item.product.nameFa || item.product.name}`}
|
||||
onClick={() => updateQuantity(item.product.id, item.quantity + 1)}
|
||||
className="p-1 hover:text-canina-blue transition-colors"
|
||||
className="min-w-[44px] min-h-[44px] flex items-center justify-center p-1 hover:text-canina-blue transition-colors cursor-pointer"
|
||||
data-testid="plus-btn"
|
||||
>
|
||||
<Plus className="w-3 h-3" />
|
||||
@@ -173,7 +173,7 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
|
||||
aria-label={`حذف ${item.product.nameFa || item.product.name} از سبد خرید`}
|
||||
data-testid="cart-item-delete-btn"
|
||||
onClick={() => setDeleteConfirmId(item.product.id)}
|
||||
className="text-medical-gray-300 hover:text-red-500 transition-colors"
|
||||
className="min-w-[44px] min-h-[44px] flex items-center justify-center text-medical-gray-300 hover:text-red-500 transition-colors cursor-pointer"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
|
||||
@@ -130,7 +130,7 @@ export default function ContactFormClient() {
|
||||
</p>
|
||||
<button
|
||||
onClick={() => setSuccess(false)}
|
||||
className="mt-4 px-6 py-2 bg-emerald-600 text-white rounded-xl text-xs font-black"
|
||||
className="mt-4 min-h-[44px] px-6 py-2.5 bg-emerald-600 text-white rounded-xl text-xs font-black cursor-pointer"
|
||||
>
|
||||
ارسال پیام جدید
|
||||
</button>
|
||||
|
||||
@@ -74,12 +74,12 @@ export default function Footer({
|
||||
<BrandLogo isDarkBackground size="lg" />
|
||||
<div className="flex gap-2.5 sm:hidden">
|
||||
{getText('contact_instagram', '') && (
|
||||
<a href={getText('contact_instagram', '#')} target="_blank" rel="noopener noreferrer" aria-label="صفحه اینستاگرام رسمی کنینا ایران" className="w-9 h-9 bg-white/10 rounded-xl flex items-center justify-center hover:bg-canina-blue hover:text-white transition-all text-slate-300">
|
||||
<a href={getText('contact_instagram', '#')} target="_blank" rel="noopener noreferrer" aria-label="صفحه اینستاگرام رسمی کنینا ایران" className="min-w-[44px] min-h-[44px] w-11 h-11 bg-white/10 rounded-xl flex items-center justify-center hover:bg-canina-blue hover:text-white transition-all text-slate-300">
|
||||
<Instagram className="w-4 h-4" />
|
||||
</a>
|
||||
)}
|
||||
{getText('contact_telegram', '') && (
|
||||
<a href={getText('contact_telegram', '#')} target="_blank" rel="noopener noreferrer" aria-label="کانال تلگرام رسمی کنینا ایران" className="w-9 h-9 bg-white/10 rounded-xl flex items-center justify-center hover:bg-canina-blue hover:text-white transition-all text-slate-300">
|
||||
<a href={getText('contact_telegram', '#')} target="_blank" rel="noopener noreferrer" aria-label="کانال تلگرام رسمی کنینا ایران" className="min-w-[44px] min-h-[44px] w-11 h-11 bg-white/10 rounded-xl flex items-center justify-center hover:bg-canina-blue hover:text-white transition-all text-slate-300">
|
||||
<Globe className="w-4 h-4" />
|
||||
</a>
|
||||
)}
|
||||
@@ -121,12 +121,12 @@ export default function Footer({
|
||||
|
||||
<div className="hidden sm:flex gap-4 pt-1">
|
||||
{getText('contact_instagram', '') && (
|
||||
<a href={getText('contact_instagram', '#')} target="_blank" rel="noopener noreferrer" aria-label="صفحه اینستاگرام رسمی کنینا ایران" className="w-10 h-10 bg-white/10 rounded-xl flex items-center justify-center hover:bg-canina-blue hover:text-white transition-all text-slate-300">
|
||||
<a href={getText('contact_instagram', '#')} target="_blank" rel="noopener noreferrer" aria-label="صفحه اینستاگرام رسمی کنینا ایران" className="min-w-[44px] min-h-[44px] w-11 h-11 bg-white/10 rounded-xl flex items-center justify-center hover:bg-canina-blue hover:text-white transition-all text-slate-300">
|
||||
<Instagram className="w-5 h-5" />
|
||||
</a>
|
||||
)}
|
||||
{getText('contact_telegram', '') && (
|
||||
<a href={getText('contact_telegram', '#')} target="_blank" rel="noopener noreferrer" aria-label="کانال تلگرام رسمی کنینا ایران" className="w-10 h-10 bg-white/10 rounded-xl flex items-center justify-center hover:bg-canina-blue hover:text-white transition-all text-slate-300">
|
||||
<a href={getText('contact_telegram', '#')} target="_blank" rel="noopener noreferrer" aria-label="کانال تلگرام رسمی کنینا ایران" className="min-w-[44px] min-h-[44px] w-11 h-11 bg-white/10 rounded-xl flex items-center justify-center hover:bg-canina-blue hover:text-white transition-all text-slate-300">
|
||||
<Globe className="w-5 h-5" />
|
||||
</a>
|
||||
)}
|
||||
@@ -209,7 +209,7 @@ export default function Footer({
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-8">
|
||||
<div className="flex flex-col sm:space-y-6 gap-2.5 sm:gap-0">
|
||||
<a href={getText('contact_phone_link', `tel:${getText('contact_phone', '').replace(/[^0-9+]/g, '')}`)} className="flex items-center sm:items-start gap-2.5 sm:gap-4 group hover:opacity-90 transition-opacity bg-white/[0.04] sm:bg-transparent p-3 sm:p-0 rounded-xl sm:rounded-none border border-white/5 sm:border-0">
|
||||
<div className="w-9 h-9 sm:w-12 sm:h-12 bg-white/5 rounded-xl sm:rounded-2xl flex items-center justify-center text-blue-400 group-hover:scale-110 transition-transform flex-shrink-0">
|
||||
<div className="min-w-[44px] min-h-[44px] w-11 h-11 sm:w-12 sm:h-12 bg-white/5 rounded-xl sm:rounded-2xl flex items-center justify-center text-blue-400 group-hover:scale-110 transition-transform flex-shrink-0">
|
||||
<Phone className="w-4 h-4 sm:w-6 sm:h-6" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
@@ -218,7 +218,7 @@ export default function Footer({
|
||||
</div>
|
||||
</a>
|
||||
<a href={`mailto:${getText('contact_email', '')}`} className="flex items-center sm:items-start gap-2.5 sm:gap-4 group hover:opacity-90 transition-opacity bg-white/[0.04] sm:bg-transparent p-3 sm:p-0 rounded-xl sm:rounded-none border border-white/5 sm:border-0">
|
||||
<div className="w-9 h-9 sm:w-12 sm:h-12 bg-white/5 rounded-xl sm:rounded-2xl flex items-center justify-center text-blue-400 group-hover:scale-110 transition-transform flex-shrink-0">
|
||||
<div className="min-w-[44px] min-h-[44px] w-11 h-11 sm:w-12 sm:h-12 bg-white/5 rounded-xl sm:rounded-2xl flex items-center justify-center text-blue-400 group-hover:scale-110 transition-transform flex-shrink-0">
|
||||
<Mail className="w-4 h-4 sm:w-6 sm:h-6" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
@@ -229,7 +229,7 @@ export default function Footer({
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-2.5 sm:gap-4 group bg-white/[0.04] sm:bg-transparent p-3 sm:p-0 rounded-xl sm:rounded-none border border-white/5 sm:border-0">
|
||||
<div className="w-9 h-9 sm:w-12 sm:h-12 bg-white/5 rounded-xl sm:rounded-2xl flex items-center justify-center text-blue-400 group-hover:scale-110 transition-transform flex-shrink-0">
|
||||
<div className="min-w-[44px] min-h-[44px] w-11 h-11 sm:w-12 sm:h-12 bg-white/5 rounded-xl sm:rounded-2xl flex items-center justify-center text-blue-400 group-hover:scale-110 transition-transform flex-shrink-0">
|
||||
<MapPin className="w-4 h-4 sm:w-6 sm:h-6" />
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
@@ -242,7 +242,7 @@ export default function Footer({
|
||||
{/* Trust and Verification Banner */}
|
||||
<div className="mt-4 sm:mt-10 p-3.5 sm:p-6 bg-white/5 rounded-2xl sm:rounded-[2rem] border border-white/10 flex flex-col sm:flex-row items-center justify-between gap-3.5 sm:gap-6 text-center sm:text-right">
|
||||
<div className="flex items-center gap-2.5 sm:gap-4 w-full sm:w-auto">
|
||||
<div className="w-9 h-9 sm:w-10 sm:h-10 bg-green-500/20 text-green-500 rounded-full flex items-center justify-center flex-shrink-0">
|
||||
<div className="min-w-[44px] min-h-[44px] w-11 h-11 sm:w-12 sm:h-12 bg-green-500/20 text-green-500 rounded-full flex items-center justify-center flex-shrink-0">
|
||||
<ShieldCheck className="w-4 h-4 sm:w-6 sm:h-6" />
|
||||
</div>
|
||||
<div className="text-right min-w-0 flex-1">
|
||||
|
||||
@@ -175,7 +175,7 @@ export default function IngredientWiki() {
|
||||
|
||||
<button
|
||||
onClick={() => router.push('/')}
|
||||
className="px-3.5 py-1.5 bg-white border border-medical-gray-200 rounded-lg text-medical-gray-600 shadow-xs flex items-center gap-1.5 font-bold text-xs hover:border-canina-blue hover:text-canina-blue transition-all whitespace-nowrap cursor-pointer"
|
||||
className="min-h-[44px] px-4 py-2 bg-white border border-medical-gray-200 rounded-xl text-medical-gray-600 shadow-xs flex items-center gap-1.5 font-bold text-xs hover:border-canina-blue hover:text-canina-blue transition-all whitespace-nowrap cursor-pointer"
|
||||
>
|
||||
<span>بازگشت</span>
|
||||
<ChevronLeft className="w-3.5 h-3.5" />
|
||||
@@ -269,7 +269,7 @@ export default function IngredientWiki() {
|
||||
if (next.has(ing.id)) next.delete(ing.id); else next.add(ing.id);
|
||||
return next;
|
||||
})}
|
||||
className="w-full min-h-11 flex items-center gap-3 text-right rounded-xl p-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-canina-blue focus-visible:ring-offset-2 cursor-pointer"
|
||||
className="w-full min-h-[48px] flex items-center gap-3 text-right rounded-xl p-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-canina-blue focus-visible:ring-offset-2 cursor-pointer"
|
||||
>
|
||||
<span className="w-10 h-10 sm:w-12 sm:h-12 rounded-xl sm:rounded-2xl bg-medical-gray-900 flex items-center justify-center text-white shadow-md shrink-0">
|
||||
<Beaker className="w-6 h-6 text-canina-gold" />
|
||||
|
||||
@@ -558,7 +558,7 @@ export default function MobileBottomNav({
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setCartOpen(true)}
|
||||
className="flex flex-col items-center justify-center flex-1 py-1 text-medical-gray-400 font-bold hover:text-medical-gray-700 relative"
|
||||
className="flex flex-col items-center justify-center flex-1 min-h-[48px] py-1 text-medical-gray-400 font-bold hover:text-medical-gray-700 relative"
|
||||
>
|
||||
<div className="relative mb-1">
|
||||
<ShoppingCart className="w-5 h-5" />
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import React from "react";
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
|
||||
// Mock next/navigation
|
||||
vi.mock("next/navigation", () => ({
|
||||
usePathname: () => "/",
|
||||
useRouter: () => ({ push: vi.fn(), replace: vi.fn(), back: vi.fn() }),
|
||||
useSearchParams: () => new URLSearchParams(),
|
||||
}));
|
||||
|
||||
vi.mock("next/link", () => ({
|
||||
default: ({ children, href, ...props }: any) => <a href={href} {...props}>{children}</a>,
|
||||
}));
|
||||
|
||||
vi.mock("next/image", () => ({
|
||||
default: (props: any) => <img {...props} />,
|
||||
}));
|
||||
|
||||
// Mock stores
|
||||
const mockCartState: any = {
|
||||
items: [
|
||||
{
|
||||
product: {
|
||||
id: "p1",
|
||||
name: "Canina Product",
|
||||
nameFa: "مکمل کنینا",
|
||||
priceValue: 100000,
|
||||
image: "/img.png",
|
||||
category: "سگ",
|
||||
},
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
totalPrice: 200000,
|
||||
updateQuantity: vi.fn(),
|
||||
removeItem: vi.fn(),
|
||||
hasItem: vi.fn().mockReturnValue(false),
|
||||
getTotalItems: vi.fn().mockReturnValue(2),
|
||||
getSubtotal: vi.fn().mockReturnValue(200000),
|
||||
getDiscount: vi.fn().mockReturnValue(0),
|
||||
getTotal: vi.fn().mockReturnValue(200000),
|
||||
couponCode: null,
|
||||
applyCoupon: vi.fn(),
|
||||
removeCoupon: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mock("../../lib/store/cartStore", () => ({
|
||||
useCartStore: (selector?: any) => (typeof selector === "function" ? selector(mockCartState) : mockCartState),
|
||||
}));
|
||||
|
||||
const mockSettingsState: any = {
|
||||
getText: (k: string, d: string) => {
|
||||
if (k === 'contact_instagram') return 'https://instagram.com/canina';
|
||||
if (k === 'contact_telegram') return 'https://t.me/canina';
|
||||
return d || 'mock';
|
||||
},
|
||||
getBoolean: () => true,
|
||||
};
|
||||
|
||||
vi.mock("../../lib/store/settingsStore", () => {
|
||||
const store = (selector?: any) => (typeof selector === "function" ? selector(mockSettingsState) : mockSettingsState);
|
||||
store.getState = () => mockSettingsState;
|
||||
return { useSettingsStore: store };
|
||||
});
|
||||
|
||||
const mockUIState = {
|
||||
setCartOpen: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mock("../../lib/store/uiStore", () => ({
|
||||
useUIStore: (selector?: any) => (typeof selector === "function" ? selector(mockUIState) : mockUIState),
|
||||
}));
|
||||
|
||||
vi.mock("../../lib/services/api", () => ({
|
||||
default: {
|
||||
get: vi.fn().mockResolvedValue({ data: [] }),
|
||||
post: vi.fn().mockResolvedValue({ data: {} }),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../../lib/services/productService", () => ({
|
||||
productService: {
|
||||
getProducts: vi.fn().mockResolvedValue({ data: [] }),
|
||||
},
|
||||
}));
|
||||
|
||||
import CartDrawer from "../CartDrawer";
|
||||
import IngredientWiki from "../IngredientWiki";
|
||||
import ContactFormClient from "../ContactFormClient";
|
||||
import Footer from "../Footer";
|
||||
import MobileBottomNav from "../MobileBottomNav";
|
||||
|
||||
describe("Touch Target >= 44px Verification (UX-30)", () => {
|
||||
it("ensures CartDrawer quantity and close buttons have min 44x44px touch targets", () => {
|
||||
render(<CartDrawer isOpen={true} onClose={vi.fn()} onCheckout={vi.fn()} onShopNavigate={vi.fn()} />);
|
||||
|
||||
const closeBtn = screen.getByLabelText("بستن سبد خرید");
|
||||
expect(closeBtn.className).toContain("min-w-[44px]");
|
||||
expect(closeBtn.className).toContain("min-h-[44px]");
|
||||
|
||||
const minusBtn = screen.getByTestId("minus-btn");
|
||||
expect(minusBtn.className).toContain("min-w-[44px]");
|
||||
expect(minusBtn.className).toContain("min-h-[44px]");
|
||||
|
||||
const plusBtn = screen.getByTestId("plus-btn");
|
||||
expect(plusBtn.className).toContain("min-w-[44px]");
|
||||
expect(plusBtn.className).toContain("min-h-[44px]");
|
||||
|
||||
const deleteBtn = screen.getByTestId("cart-item-delete-btn");
|
||||
expect(deleteBtn.className).toContain("min-w-[44px]");
|
||||
expect(deleteBtn.className).toContain("min-h-[44px]");
|
||||
});
|
||||
|
||||
it("ensures MobileBottomNav cart tab has min-h-[48px] (>= 44px) touch target", () => {
|
||||
render(<MobileBottomNav />);
|
||||
const cartBtn = screen.getByText("سبد خرید").closest("button");
|
||||
expect(cartBtn).not.toBeNull();
|
||||
expect(cartBtn?.className).toContain("min-h-[48px]");
|
||||
});
|
||||
|
||||
it("ensures IngredientWiki navigation has >= 44px touch targets", () => {
|
||||
render(<IngredientWiki />);
|
||||
const backBtn = screen.getByRole("button", { name: "بازگشت" });
|
||||
expect(backBtn.className).toContain("min-h-[44px]");
|
||||
});
|
||||
|
||||
it("ensures ContactForm submit retry button has min-h-[44px]", () => {
|
||||
render(<ContactFormClient />);
|
||||
expect(screen.getByText("اطلاعات نمایندگی")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("ensures Footer action links and social badges have >= 44px touch targets", () => {
|
||||
render(<Footer />);
|
||||
const socialLinks = screen.getAllByLabelText(/رسمی کنینا ایران/);
|
||||
socialLinks.forEach(link => {
|
||||
expect(link.className).toContain("min-w-[44px]");
|
||||
expect(link.className).toContain("min-h-[44px]");
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user