test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
This commit is contained in:
1 parent
1e73715169
commit
ddbf1ca026
439 files changed
+32911
-6107
No files matched your search
@@ -0,0 +1,196 @@
|
||||
import React from 'react';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import MobileBottomNav from '../MobileBottomNav';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import { useCartStore } from '../../lib/store/cartStore';
|
||||
import { useUserStore } from '../../lib/store/userStore';
|
||||
import { useUIStore } from '../../lib/store/uiStore';
|
||||
import { useSettingsStore } from '../../lib/store/settingsStore';
|
||||
import { useCatalogMode } from '../../lib/useCatalogMode';
|
||||
|
||||
vi.mock('next/navigation', () => ({
|
||||
usePathname: vi.fn(),
|
||||
useRouter: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../lib/store/cartStore', () => ({
|
||||
useCartStore: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../lib/store/userStore', () => ({
|
||||
useUserStore: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../lib/store/uiStore', () => ({
|
||||
useUIStore: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../lib/store/settingsStore', () => ({
|
||||
useSettingsStore: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../lib/useCatalogMode', () => ({
|
||||
useCatalogMode: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('MobileBottomNav Component', () => {
|
||||
const mockRouterPush = vi.fn();
|
||||
const mockSetAuthModalOpen = vi.fn();
|
||||
const mockSetCartOpen = vi.fn();
|
||||
const mockSetB2BPortalOpen = vi.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
vi.mocked(usePathname).mockReturnValue('/');
|
||||
vi.mocked(useRouter).mockReturnValue({
|
||||
push: mockRouterPush,
|
||||
replace: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
back: vi.fn(),
|
||||
} as any);
|
||||
|
||||
vi.mocked(useCartStore).mockReturnValue({
|
||||
getTotalItems: vi.fn().mockReturnValue(0),
|
||||
} as any);
|
||||
|
||||
vi.mocked(useUserStore).mockReturnValue({
|
||||
isLoggedIn: false,
|
||||
setAuthModalOpen: mockSetAuthModalOpen,
|
||||
} as any);
|
||||
|
||||
vi.mocked(useUIStore).mockImplementation((selector: any) => {
|
||||
const state = {
|
||||
setCartOpen: mockSetCartOpen,
|
||||
setB2BPortalOpen: mockSetB2BPortalOpen,
|
||||
};
|
||||
return selector(state);
|
||||
});
|
||||
|
||||
vi.mocked(useSettingsStore).mockImplementation((selector: any) => {
|
||||
const state = {
|
||||
getBoolean: vi.fn().mockReturnValue(true),
|
||||
getText: vi.fn().mockReturnValue('true'),
|
||||
};
|
||||
return selector(state);
|
||||
});
|
||||
|
||||
vi.mocked(useCatalogMode).mockReturnValue({
|
||||
isCatalogOnly: false,
|
||||
allowCart: true,
|
||||
} as any);
|
||||
});
|
||||
|
||||
it('renders all default 5 navigation tabs', () => {
|
||||
render(<MobileBottomNav />);
|
||||
|
||||
expect(screen.getByText('خانه')).toBeInTheDocument();
|
||||
expect(screen.getByText('منو')).toBeInTheDocument();
|
||||
expect(screen.getByText('فروشگاه')).toBeInTheDocument();
|
||||
expect(screen.getByText('سبد خرید')).toBeInTheDocument();
|
||||
expect(screen.getByText('حساب من')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides component on product detail page (/shop/[id])', () => {
|
||||
vi.mocked(usePathname).mockReturnValue('/shop/canina-glucosamine-123');
|
||||
const { container } = render(<MobileBottomNav />);
|
||||
|
||||
expect(container.firstChild).toBeNull();
|
||||
});
|
||||
|
||||
it('highlights the active tab according to current path', () => {
|
||||
vi.mocked(usePathname).mockReturnValue('/');
|
||||
render(<MobileBottomNav />);
|
||||
|
||||
const homeLink = screen.getByText('خانه').closest('a');
|
||||
expect(homeLink).toHaveClass('text-canina-blue');
|
||||
expect(homeLink).toHaveClass('font-black');
|
||||
});
|
||||
|
||||
it('displays cart item badge with Persian formatted count when cart has items', () => {
|
||||
vi.mocked(useCartStore).mockReturnValue({
|
||||
getTotalItems: vi.fn().mockReturnValue(3),
|
||||
} as any);
|
||||
|
||||
render(<MobileBottomNav />);
|
||||
|
||||
// 3 in Persian is ۳
|
||||
expect(screen.getByText('۳')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('opens cart drawer when cart tab is clicked', () => {
|
||||
render(<MobileBottomNav />);
|
||||
|
||||
const cartBtn = screen.getByText('سبد خرید').closest('button');
|
||||
expect(cartBtn).toBeInTheDocument();
|
||||
fireEvent.click(cartBtn!);
|
||||
|
||||
expect(mockSetCartOpen).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it('hides cart tab when catalog mode disables cart', () => {
|
||||
vi.mocked(useCatalogMode).mockReturnValue({
|
||||
isCatalogOnly: true,
|
||||
allowCart: false,
|
||||
} as any);
|
||||
|
||||
render(<MobileBottomNav />);
|
||||
|
||||
expect(screen.queryByText('سبد خرید')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('triggers auth modal when clicking account tab while not logged in', () => {
|
||||
vi.mocked(useUserStore).mockReturnValue({
|
||||
isLoggedIn: false,
|
||||
setAuthModalOpen: mockSetAuthModalOpen,
|
||||
} as any);
|
||||
|
||||
render(<MobileBottomNav />);
|
||||
|
||||
const accountBtn = screen.getByText('حساب من').closest('button');
|
||||
expect(accountBtn).toBeInTheDocument();
|
||||
fireEvent.click(accountBtn!);
|
||||
|
||||
expect(mockSetAuthModalOpen).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it('navigates to /dashboard when clicking account tab while logged in', () => {
|
||||
vi.mocked(useUserStore).mockReturnValue({
|
||||
isLoggedIn: true,
|
||||
setAuthModalOpen: mockSetAuthModalOpen,
|
||||
} as any);
|
||||
|
||||
render(<MobileBottomNav />);
|
||||
|
||||
const accountBtn = screen.getByText('حساب من').closest('button');
|
||||
expect(accountBtn).toBeInTheDocument();
|
||||
fireEvent.click(accountBtn!);
|
||||
|
||||
expect(mockRouterPush).toHaveBeenCalledWith('/dashboard');
|
||||
});
|
||||
|
||||
it('opens shop bottom sheet when shop tab is clicked', () => {
|
||||
render(<MobileBottomNav />);
|
||||
|
||||
const shopBtn = screen.getByText('فروشگاه').closest('button');
|
||||
expect(shopBtn).toBeInTheDocument();
|
||||
fireEvent.click(shopBtn!);
|
||||
|
||||
// Sheet displays shop navigation elements
|
||||
expect(screen.getByPlaceholderText(/جستجوی دارو، ترکیب یا علامت بالینی/i)).toBeInTheDocument();
|
||||
expect(screen.getByText('مشاهده کاتالوگ و همه محصولات')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('opens menu bottom sheet when menu tab is clicked', () => {
|
||||
render(<MobileBottomNav />);
|
||||
|
||||
const menuBtn = screen.getByText('منو').closest('button');
|
||||
expect(menuBtn).toBeInTheDocument();
|
||||
fireEvent.click(menuBtn!);
|
||||
|
||||
expect(screen.getByText('دانشنامه علمی')).toBeInTheDocument();
|
||||
expect(screen.getByText('مجله سلامت پت')).toBeInTheDocument();
|
||||
expect(screen.getByText('ویدیوهای بالینی')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user