test(e2e): refactor 6 e2e suites with strict assertions, add mutation verification and update test coverage map
This commit is contained in:
1 parent
3c325c412c
commit
6ef293ea59
28 files changed
+20676
-16743
No files matched your search
@@ -73,6 +73,7 @@ const CATEGORY_MAP: Record<string, { category?: string; query?: string; symptoms
|
||||
|
||||
const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
const { addItem } = useCartStore();
|
||||
const cartItem = useCartStore((s) => s.items.find(i => i.product.id === product.id));
|
||||
const [isAdding, setIsAdding] = useState(false);
|
||||
const activePet = usePetStore(state => state.pets.find(p => p.id === state.activePetId) || null);
|
||||
const productUrl = `/shop/${product.slug || product.id}`;
|
||||
@@ -83,7 +84,7 @@ const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
setIsAdding(true);
|
||||
addItem(product, 1);
|
||||
toast.success(`${product.name} به سبد خرید اضافه شد`);
|
||||
setTimeout(() => setIsAdding(false), 800);
|
||||
setTimeout(() => setIsAdding(false), 400);
|
||||
};
|
||||
|
||||
const compatibility = useMemo(() => {
|
||||
@@ -180,41 +181,37 @@ const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
<span className="px-2.5 py-1.5 rounded-xl bg-rose-50 text-rose-600 border border-rose-100 text-[11px] font-bold font-vazir">
|
||||
ناموجود
|
||||
</span>
|
||||
) : !useSettingsStore.getState().getText("catalog_disable_cart", "false").includes("true") && (() => {
|
||||
const cartItem = useCartStore.getState().items.find(i => i.product.id === product.id);
|
||||
if (cartItem && cartItem.quantity > 0) {
|
||||
return (
|
||||
<div
|
||||
onClick={(e) => { e.preventDefault(); e.stopPropagation(); }}
|
||||
className="flex items-center gap-1 bg-canina-blue/10 border border-canina-blue/20 rounded-xl p-1"
|
||||
) : !useSettingsStore.getState().getText("catalog_disable_cart", "false").includes("true") && (
|
||||
cartItem && cartItem.quantity > 0 ? (
|
||||
<div
|
||||
onClick={(e) => { e.preventDefault(); e.stopPropagation(); }}
|
||||
className="flex items-center gap-1 bg-canina-blue/10 border border-canina-blue/20 rounded-xl p-1"
|
||||
>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
useCartStore.getState().updateQuantity(product.id, cartItem.quantity + 1);
|
||||
}}
|
||||
className="w-7 h-7 rounded-lg bg-canina-blue text-white flex items-center justify-center font-bold text-xs"
|
||||
>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
useCartStore.getState().updateQuantity(product.id, cartItem.quantity + 1);
|
||||
}}
|
||||
className="w-7 h-7 rounded-lg bg-canina-blue text-white flex items-center justify-center font-bold text-xs"
|
||||
>
|
||||
+
|
||||
</button>
|
||||
<span className="w-5 text-center font-black text-canina-blue text-xs font-vazir">
|
||||
{toPersian(cartItem.quantity)}
|
||||
</span>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
useCartStore.getState().updateQuantity(product.id, cartItem.quantity - 1);
|
||||
}}
|
||||
className="w-7 h-7 rounded-lg bg-white text-medical-gray-700 flex items-center justify-center font-bold text-xs shadow-sm"
|
||||
>
|
||||
-
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
+
|
||||
</button>
|
||||
<span className="w-5 text-center font-black text-canina-blue text-xs font-vazir">
|
||||
{toPersian(cartItem.quantity)}
|
||||
</span>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
useCartStore.getState().updateQuantity(product.id, cartItem.quantity - 1);
|
||||
}}
|
||||
className="w-7 h-7 rounded-lg bg-white text-medical-gray-700 flex items-center justify-center font-bold text-xs shadow-sm"
|
||||
>
|
||||
-
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
onClick={handleAddToCart}
|
||||
disabled={isAdding}
|
||||
@@ -223,8 +220,8 @@ const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
{isAdding ? <Loader2 className="w-3.5 h-3.5 animate-spin" /> : <Plus className="w-3.5 h-3.5" />}
|
||||
<span>خرید</span>
|
||||
</button>
|
||||
);
|
||||
})()}
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
@@ -35,7 +35,12 @@ export default function CheckoutPage() {
|
||||
const { items, getTotal, getSubtotal, isSubscribed, charityDonation, setCharityDonation, addOrder, clearCart } = useCartStore();
|
||||
const { pets, activePetId, getActivePet, updatePet } = usePetStore();
|
||||
const { profile, isLoggedIn } = useUserStore();
|
||||
const [isHydrated, setIsHydrated] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsHydrated(true);
|
||||
}, []);
|
||||
const [useRoundUp, setUseRoundUp] = useState(false);
|
||||
const [paymentMethod, setPaymentMethod] = useState<string>('card');
|
||||
const [showTopUpModal, setShowTopUpModal] = useState(false);
|
||||
@@ -246,7 +251,7 @@ export default function CheckoutPage() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (items.length === 0) {
|
||||
if (isHydrated && items.length === 0) {
|
||||
return (
|
||||
<div className="min-h-screen bg-medical-gray-50 flex items-center justify-center p-6" dir="rtl">
|
||||
<div className="text-center space-y-6">
|
||||
@@ -627,7 +632,7 @@ export default function CheckoutPage() {
|
||||
{items.map((item) => (
|
||||
<div key={item.product.id} className="flex justify-between items-center text-xs gap-2">
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="font-bold text-white/90 truncate">{item.product.name}</p>
|
||||
<p data-testid="checkout-item-name" className="font-bold text-white/90 truncate">{item.product.name}</p>
|
||||
<p className="text-[10px] text-white/50">{toPersian(item.quantity)} بسته</p>
|
||||
</div>
|
||||
<span className="font-bold font-vazir text-white whitespace-nowrap">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use client";
|
||||
import React, { useState } from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import {
|
||||
Package,
|
||||
Truck,
|
||||
@@ -19,13 +19,17 @@ export default function OrderTracking() {
|
||||
const router = useRouter();
|
||||
const { orders } = useCartStore();
|
||||
const [searchId, setSearchId] = useState("");
|
||||
const [activeOrder, setActiveOrder] = useState(orders[0] || null);
|
||||
const [activeOrder, setActiveOrder] = useState<typeof orders[0] | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (orders.length > 0 && !activeOrder && !searchId) {
|
||||
setActiveOrder(orders[0]);
|
||||
}
|
||||
}, [orders, activeOrder, searchId]);
|
||||
|
||||
const handleSearch = () => {
|
||||
const found = orders.find(o => o.id === searchId || o.trackingNumber === searchId);
|
||||
if (found) {
|
||||
setActiveOrder(found);
|
||||
}
|
||||
setActiveOrder(found || null);
|
||||
};
|
||||
|
||||
const steps = [
|
||||
|
||||
Reference in new issue
Block a user