feat: layout and overlays migrated to Next.js
This commit is contained in:
1 parent
c5a1b8e5d2
commit
72d2a5600a
42 files changed
+9064
-42
No files matched your search
@@ -0,0 +1,111 @@
|
||||
"use client";
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import Header from '../Header';
|
||||
import { useCartStore } from '../../store/cartStore';
|
||||
import { usePetStore } from '../../store/usePetStore';
|
||||
import { useUserStore } from '../../store/userStore';
|
||||
|
||||
vi.mock('../../store/cartStore', () => ({
|
||||
useCartStore: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../store/usePetStore', () => ({
|
||||
usePetStore: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../store/userStore', () => ({
|
||||
useUserStore: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('Header', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
vi.mocked(useCartStore).mockReturnValue({
|
||||
getTotalItems: () => 3,
|
||||
} as any);
|
||||
|
||||
vi.mocked(usePetStore).mockReturnValue({
|
||||
pets: [],
|
||||
activePetId: null,
|
||||
setActivePet: vi.fn(),
|
||||
getActivePet: () => null,
|
||||
} as any);
|
||||
|
||||
vi.mocked(useUserStore).mockReturnValue({
|
||||
role: 'User_Guest',
|
||||
isLoggedIn: false,
|
||||
logout: vi.fn(),
|
||||
profile: { firstName: '' },
|
||||
} as any);
|
||||
});
|
||||
|
||||
it('renders brand name and login button when guest', () => {
|
||||
render(
|
||||
<Header
|
||||
onNavigate={vi.fn()}
|
||||
onShopNavigate={vi.fn()}
|
||||
currentView="home"
|
||||
onCartOpen={vi.fn()}
|
||||
onSearch={vi.fn()}
|
||||
onB2BOpen={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Canina')).toBeInTheDocument();
|
||||
expect(screen.getByText('ایران')).toBeInTheDocument();
|
||||
expect(screen.getByText('ورود / ثبتنام')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders user first name and pet selection when logged in', () => {
|
||||
vi.mocked(useUserStore).mockReturnValue({
|
||||
role: 'User_PetOwner',
|
||||
isLoggedIn: true,
|
||||
logout: vi.fn(),
|
||||
profile: { firstName: 'کوروش' },
|
||||
} as any);
|
||||
|
||||
vi.mocked(usePetStore).mockReturnValue({
|
||||
pets: [{ id: 'pet-1', name: 'ملوس', type: 'گربه' }],
|
||||
activePetId: 'pet-1',
|
||||
setActivePet: vi.fn(),
|
||||
getActivePet: () => ({ id: 'pet-1', name: 'ملوس', type: 'گربه' }),
|
||||
} as any);
|
||||
|
||||
render(
|
||||
<Header
|
||||
onNavigate={vi.fn()}
|
||||
onShopNavigate={vi.fn()}
|
||||
currentView="home"
|
||||
onCartOpen={vi.fn()}
|
||||
onSearch={vi.fn()}
|
||||
onB2BOpen={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.queryByText('ورود / ثبتنام')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('کوروش')).toBeInTheDocument();
|
||||
expect(screen.getByText('ملوس')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onCartOpen when click on cart button', () => {
|
||||
const handleCartOpen = vi.fn();
|
||||
render(
|
||||
<Header
|
||||
onNavigate={vi.fn()}
|
||||
onShopNavigate={vi.fn()}
|
||||
currentView="home"
|
||||
onCartOpen={handleCartOpen}
|
||||
onSearch={vi.fn()}
|
||||
onB2BOpen={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
const cartBtn = screen.getByText('سبد خرید').closest('button');
|
||||
expect(cartBtn).toBeInTheDocument();
|
||||
fireEvent.click(cartBtn!);
|
||||
expect(handleCartOpen).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user