fix(ux): harden dialogs and remove unsupported contact fallbacks
Deploy Canina / deploy (push) Successful in 2m10s
Deploy Canina / deploy (push) Successful in 2m10s
This commit is contained in:
1 parent
86cfa4b3c8
commit
26f5f68708
6 files changed
+42
-21
No files matched your search
@@ -434,6 +434,9 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
|
||||
{/* Modal Container */}
|
||||
<motion.div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="auth-modal-title"
|
||||
initial={{ opacity: 0, scale: 0.96, y: 20 }}
|
||||
animate={{ opacity: 1, scale: 1, y: 0 }}
|
||||
exit={{ opacity: 0, scale: 0.96, y: 20 }}
|
||||
@@ -447,11 +450,13 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
<ShieldCheck className="w-4 h-4" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-sm font-black tracking-tight text-medical-gray-900 font-vazir">احراز هویت کنینا</h3>
|
||||
<h3 id="auth-modal-title" className="text-sm font-black tracking-tight text-medical-gray-900 font-vazir">احراز هویت کنینا</h3>
|
||||
<p className="text-[10px] text-medical-gray-400 font-bold font-vazir">ورود امن به حساب کاربری</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="بستن پنجره احراز هویت"
|
||||
onClick={onClose}
|
||||
className="w-8 h-8 rounded-full bg-white border border-medical-gray-200 flex items-center justify-center text-medical-gray-400 hover:text-medical-gray-700 hover:bg-medical-gray-100 transition-all cursor-pointer"
|
||||
>
|
||||
|
||||
@@ -94,6 +94,9 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
|
||||
className="fixed inset-0 bg-medical-gray-900/40 backdrop-blur-sm z-[100]"
|
||||
/>
|
||||
<motion.div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="cart-drawer-title"
|
||||
initial={{ x: "100%" }}
|
||||
animate={{ x: 0 }}
|
||||
exit={{ x: "100%" }}
|
||||
@@ -107,9 +110,9 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
|
||||
<div className="w-10 h-10 bg-medical-gray-50 rounded-xl flex items-center justify-center text-canina-blue">
|
||||
<ShoppingBag className="w-6 h-6" />
|
||||
</div>
|
||||
<h3 className="text-xl font-black text-medical-gray-900 italic">سبد خرید</h3>
|
||||
<h3 id="cart-drawer-title" className="text-xl font-black text-medical-gray-900 italic">سبد خرید</h3>
|
||||
</div>
|
||||
<button onClick={onClose} className="p-2 hover:bg-medical-gray-50 rounded-full transition-colors">
|
||||
<button aria-label="بستن سبد خرید" onClick={onClose} className="p-2 hover:bg-medical-gray-50 rounded-full transition-colors">
|
||||
<X className="w-6 h-6 text-medical-gray-400" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -146,6 +149,8 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2 bg-white rounded-lg border border-medical-gray-200 p-1">
|
||||
<button
|
||||
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"
|
||||
data-testid="minus-btn"
|
||||
@@ -154,6 +159,8 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
|
||||
</button>
|
||||
<span data-testid="cart-item-quantity" className="text-xs font-black min-w-[20px] text-center font-vazir">{toPersian(item.quantity)}</span>
|
||||
<button
|
||||
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"
|
||||
data-testid="plus-btn"
|
||||
@@ -162,6 +169,8 @@ export default function CartDrawer({ isOpen, onClose, onCheckout, onShopNavigate
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
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"
|
||||
|
||||
@@ -14,8 +14,9 @@ export default function MaintenancePage() {
|
||||
);
|
||||
const badge = getText("maintenance_badge", "سامانه در حال بهروزرسانی و ارتقا");
|
||||
const eta = getText("maintenance_eta", "زمان تقریبی بازگشایی: کمتر از ۲ ساعت آینده");
|
||||
const phone = getText("contact_phone", "");
|
||||
const phoneLink = getText("contact_phone_link", "");
|
||||
const phone = getText("contact_phone", "").trim();
|
||||
const configuredPhoneLink = getText("contact_phone_link", "").trim();
|
||||
const phoneLink = configuredPhoneLink || (phone ? `tel:${phone.replace(/[^0-9+]/g, "")}` : "");
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-medical-gray-900 text-white flex flex-col items-center justify-center p-6 text-center font-vazir relative overflow-hidden" dir="rtl">
|
||||
@@ -52,15 +53,17 @@ export default function MaintenancePage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="pt-2 flex flex-col sm:flex-row items-center justify-center gap-4">
|
||||
<a
|
||||
href={phoneLink}
|
||||
{phone && phoneLink && (
|
||||
<div className="pt-2 flex flex-col sm:flex-row items-center justify-center gap-4">
|
||||
<a
|
||||
href={phoneLink}
|
||||
className="w-full sm:w-auto px-6 py-3.5 bg-canina-blue hover:bg-canina-dark text-white font-black text-xs rounded-xl flex items-center justify-center gap-2 shadow-lg transition-all"
|
||||
>
|
||||
<Phone className="w-4 h-4" />
|
||||
<span>پشتیبانی اضطراری: {phone}</span>
|
||||
</a>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="absolute bottom-6 text-xs text-medical-gray-500 font-bold flex items-center gap-2">
|
||||
|
||||
@@ -6,24 +6,30 @@ import SupportChat from './SupportChat';
|
||||
afterEach(() => { cleanup(); vi.restoreAllMocks(); localStorage.clear(); });
|
||||
describe('support widget', () => {
|
||||
it('submits only message without scope tabs, renders text safely', async () => {
|
||||
const fetcher=vi.spyOn(globalThis,'fetch').mockResolvedValue({ok:true,json:async()=>({answer:'<script>bad</script>'})} as Response);
|
||||
render(<SupportChat/>); fireEvent.click(screen.getByRole('button',{name:/گفتگو با پشتیبان/}));
|
||||
const fetcher=vi.spyOn(globalThis,'fetch')
|
||||
.mockResolvedValueOnce({ok:true,json:async()=>({enabled:true,label:'گفتگو با پشتیبان',icon:'chat'})} as Response)
|
||||
.mockResolvedValueOnce({ok:true,json:async()=>({answer:'<script>bad</script>'})} as Response);
|
||||
render(<SupportChat/>); await waitFor(() => expect(screen.getByRole('button',{name:/گفتگو با پشتیبان/})).toBeTruthy()); fireEvent.click(screen.getByRole('button',{name:/گفتگو با پشتیبان/}));
|
||||
fireEvent.change(screen.getByLabelText('پیام شما'),{target:{value:'مکمل سگ'}}); fireEvent.click(screen.getByRole('button',{name:'ارسال'}));
|
||||
await waitFor(()=>expect(screen.getByText('<script>bad</script>')).toBeTruthy());
|
||||
expect(JSON.parse(fetcher.mock.calls[0][1]!.body as string)).toEqual({message:'مکمل سگ'});
|
||||
expect(JSON.parse(fetcher.mock.calls[1][1]!.body as string)).toEqual({message:'مکمل سگ', entryPath:'/'});
|
||||
expect(document.querySelector('script')).toBeNull();
|
||||
for (const label of ['محصولات و عمومی','سفارشهای من','کیف پول']) expect(screen.queryByRole('button',{name:label})).toBeNull();
|
||||
});
|
||||
it('does not expose upstream errors', async()=> {
|
||||
vi.spyOn(globalThis,'fetch').mockResolvedValue({ok:false,status:503,json:async()=>({message:'secret-provider'})} as Response);
|
||||
render(<SupportChat/>); fireEvent.click(screen.getByRole('button',{name:/گفتگو با پشتیبان/}));
|
||||
vi.spyOn(globalThis,'fetch')
|
||||
.mockResolvedValueOnce({ok:true,json:async()=>({enabled:true,label:'گفتگو با پشتیبان',icon:'chat'})} as Response)
|
||||
.mockResolvedValueOnce({ok:false,status:503,json:async()=>({message:'secret-provider'})} as Response);
|
||||
render(<SupportChat/>); await waitFor(() => expect(screen.getByRole('button',{name:/گفتگو با پشتیبان/})).toBeTruthy()); fireEvent.click(screen.getByRole('button',{name:/گفتگو با پشتیبان/}));
|
||||
fireEvent.change(screen.getByLabelText('پیام شما'),{target:{value:'سلام'}}); fireEvent.click(screen.getByRole('button',{name:'ارسال'}));
|
||||
await waitFor(()=>expect(screen.getByText(/فعلاً در دسترس نیست/)).toBeTruthy()); expect(screen.queryByText('secret-provider')).toBeNull();
|
||||
});
|
||||
it('clears transcript on account transition', async()=> {
|
||||
localStorage.setItem('accessToken','alice');
|
||||
vi.spyOn(globalThis,'fetch').mockResolvedValue({ok:true,json:async()=>({answer:'private Alice'})} as Response);
|
||||
render(<SupportChat/>); fireEvent.click(screen.getByRole('button',{name:/گفتگو با پشتیبان/})); fireEvent.change(screen.getByLabelText('پیام شما'),{target:{value:'کیف پول'}}); fireEvent.click(screen.getByRole('button',{name:'ارسال'}));
|
||||
vi.spyOn(globalThis,'fetch')
|
||||
.mockResolvedValueOnce({ok:true,json:async()=>({enabled:true,label:'گفتگو با پشتیبان',icon:'chat'})} as Response)
|
||||
.mockResolvedValueOnce({ok:true,json:async()=>({answer:'private Alice'})} as Response);
|
||||
render(<SupportChat/>); await waitFor(() => expect(screen.getByRole('button',{name:/گفتگو با پشتیبان/})).toBeTruthy()); fireEvent.click(screen.getByRole('button',{name:/گفتگو با پشتیبان/})); fireEvent.change(screen.getByLabelText('پیام شما'),{target:{value:'کیف پول'}}); fireEvent.click(screen.getByRole('button',{name:'ارسال'}));
|
||||
await waitFor(()=>expect(screen.getByText('private Alice')).toBeTruthy());
|
||||
localStorage.setItem('accessToken','bob'); fireEvent.focus(window);
|
||||
await waitFor(()=>expect(screen.queryByText('private Alice')).toBeNull());
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('Footer', () => {
|
||||
|
||||
expect(screen.getByText('Canina')).toBeInTheDocument();
|
||||
expect(screen.getByText('ایران')).toBeInTheDocument();
|
||||
expect(screen.getByText('تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹')).toBeInTheDocument();
|
||||
expect(screen.queryByText('تهران، جردن، خیابان سعیدی، ساختمان کنینا، طبقه ۵، واحد ۱۹')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders navigation links properly', () => {
|
||||
|
||||
@@ -42,9 +42,7 @@ describe('MaintenancePage Component', () => {
|
||||
screen.getByText('CANINA PHARMA GMBH GERMANY — نماینده رسمی ایران')
|
||||
).toBeInTheDocument();
|
||||
|
||||
const emergencyButton = screen.getByRole('link', { name: /پشتیبانی اضطراری/ });
|
||||
expect(emergencyButton).toBeInTheDocument();
|
||||
expect(emergencyButton).toHaveAttribute('href', 'tel:02188884444');
|
||||
expect(screen.queryByRole('link', { name: /پشتیبانی اضطراری/ })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders custom maintenance messages and phone number from settings store texts', () => {
|
||||
|
||||
Reference in new issue
Block a user