feat: add MFA/TOTP auth, PII encryption, agents/leads/inquiries modules, and comprehensive tests
- Add TOTP-based MFA with setup, verify, disable, backup codes, and challenge flow - Add PII field encryption middleware with AES-256-GCM and deterministic search hashes - Add agents, inquiries, and leads domain modules with entities, events, value objects - Add web dashboard pages for inquiries and leads with detail dialogs - Add 30+ component tests (valuation, charts, listings, search, providers, UI) - Add Prisma migrations for encryption hash columns and MFA TOTP support - Fix all ESLint errors (unused imports, duplicate imports, lint auto-fixes) - Update dependencies and lock file - Clean up obsolete exploration/QA docs, add audit documentation Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
103
apps/web/components/leads/__tests__/create-lead-dialog.spec.tsx
Normal file
103
apps/web/components/leads/__tests__/create-lead-dialog.spec.tsx
Normal file
@@ -0,0 +1,103 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { CreateLeadDialog } from '../create-lead-dialog';
|
||||
|
||||
// Mock the hook
|
||||
const mockMutate = vi.fn();
|
||||
vi.mock('@/lib/hooks/use-leads', () => ({
|
||||
useCreateLead: () => ({
|
||||
mutate: mockMutate,
|
||||
isPending: false,
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock Dialog components with simplified versions
|
||||
vi.mock('@/components/ui/dialog', () => ({
|
||||
Dialog: ({ children, open }: { children: React.ReactNode; open: boolean }) =>
|
||||
open ? <div data-testid="dialog">{children}</div> : null,
|
||||
DialogContent: ({ children, className }: { children: React.ReactNode; className?: string }) => (
|
||||
<div data-testid="dialog-content" className={className}>{children}</div>
|
||||
),
|
||||
DialogHeader: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
DialogTitle: ({ children }: { children: React.ReactNode }) => <h2>{children}</h2>,
|
||||
DialogDescription: ({ children }: { children: React.ReactNode }) => <p>{children}</p>,
|
||||
DialogFooter: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
}));
|
||||
|
||||
describe('CreateLeadDialog', () => {
|
||||
beforeEach(() => {
|
||||
mockMutate.mockClear();
|
||||
});
|
||||
|
||||
it('renders dialog when open', () => {
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
expect(screen.getByText('Thêm lead mới')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render when closed', () => {
|
||||
render(<CreateLeadDialog open={false} onOpenChange={vi.fn()} />);
|
||||
expect(screen.queryByText('Thêm lead mới')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders customer name input', () => {
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
expect(screen.getByLabelText('Tên khách hàng *')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders phone input', () => {
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
expect(screen.getByLabelText('Số điện thoại *')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders email input', () => {
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
expect(screen.getByLabelText('Email')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders source select', () => {
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
expect(screen.getByLabelText('Nguồn')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders score input', () => {
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
expect(screen.getByLabelText('Điểm (0-100)')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders notes textarea', () => {
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
expect(screen.getByLabelText('Ghi chú')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders cancel and submit buttons', () => {
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
expect(screen.getByText('Hủy')).toBeInTheDocument();
|
||||
expect(screen.getByText('Tạo lead')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onOpenChange when cancel clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onOpenChange = vi.fn();
|
||||
render(<CreateLeadDialog open={true} onOpenChange={onOpenChange} />);
|
||||
|
||||
await user.click(screen.getByText('Hủy'));
|
||||
expect(onOpenChange).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
||||
it('calls mutate when form is submitted', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
|
||||
await user.type(screen.getByLabelText('Tên khách hàng *'), 'Nguyễn Văn Test');
|
||||
await user.type(screen.getByLabelText('Số điện thoại *'), '0901234567');
|
||||
await user.click(screen.getByText('Tạo lead'));
|
||||
|
||||
expect(mockMutate).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('renders description text', () => {
|
||||
render(<CreateLeadDialog open={true} onOpenChange={vi.fn()} />);
|
||||
expect(screen.getByText('Nhập thông tin khách hàng tiềm năng')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user