Files
lcbp3/frontend/components/layout/__tests__/navbar.test.tsx
T
admin 7e8f4859cd
CI / CD Pipeline / build (push) Failing after 6m24s
CI / CD Pipeline / deploy (push) Has been skipped
feat(ai): add ADR-036 unified OCR architecture and frontend test coverage
- Add ADR-036 unified OCR architecture (typhoon-ocr via Ollama)
- Extend AI execution profiles for OCR sandbox configuration
- Add comprehensive frontend test coverage (components, hooks, services)
- Add backend test coverage for document-numbering services
- Update OCR sidecar with typhoon-ocr integration
- Add AI policy service and execution profile management
- Update AGENTS.md and architecture documentation
2026-06-14 06:34:07 +07:00

72 lines
2.3 KiB
TypeScript

// File: frontend/components/layout/__tests__/navbar.test.tsx
// Change Log:
// - 2026-06-13: Initial creation - test coverage for Navbar component
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import { act } from '@testing-library/react';
import { Navbar } from '../navbar';
import { useUIStore } from '@/lib/stores/ui-store';
import { useSession } from 'next-auth/react';
// Mock dependencies
vi.mock('next-auth/react', () => ({
useSession: vi.fn(),
signOut: vi.fn(),
}));
vi.mock('next/navigation', () => ({
useRouter: () => ({ push: vi.fn() }),
}));
vi.mock('next/link', () => ({
default: ({ children, href }: { children: React.ReactNode; href: string }) => (
<a href={href}>{children}</a>
),
}));
describe('Navbar', () => {
beforeEach(() => {
vi.clearAllMocks();
// รีเซ็ต ui store
act(() => {
useUIStore.setState({ isSidebarOpen: true, toggleSidebar: vi.fn() });
});
vi.mocked(useSession).mockReturnValue({
data: { user: { name: 'John Doe', email: 'john@example.com', role: 'Admin' } },
} as any);
});
it('ควรเรนเดอร์ header ได้ถูกต้อง', () => {
render(<Navbar />);
expect(screen.getByRole('banner')).toBeInTheDocument();
});
it('ควรแสดงข้อความ Document Management System', () => {
render(<Navbar />);
expect(screen.getByText('Document Management System')).toBeInTheDocument();
});
it('ควรมีปุ่ม Toggle navigation menu สำหรับ mobile', () => {
render(<Navbar />);
expect(screen.getByText('Toggle navigation menu')).toBeInTheDocument();
});
it('ควรมีปุ่ม Notifications', () => {
render(<Navbar />);
expect(screen.getByText('Notifications')).toBeInTheDocument();
});
it('ควรเรียก toggleSidebar เมื่อคลิกปุ่ม menu', () => {
const mockToggle = vi.fn();
act(() => {
useUIStore.setState({ isSidebarOpen: true, toggleSidebar: mockToggle });
});
render(<Navbar />);
// ปุ่ม menu บน mobile
const menuButton = screen.getByRole('button', { name: /toggle navigation menu/i });
fireEvent.click(menuButton);
expect(mockToggle).toHaveBeenCalledOnce();
});
});