Files
goodgo-platform/apps/web/components/valuation/__tests__/ai-estimate-button.spec.tsx
Ho Ngoc Hai 1fbe2f4e73 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>
2026-04-11 23:43:20 +07:00

58 lines
1.8 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';
import { AiEstimateButton } from '../ai-estimate-button';
// Mock the hook
const mockMutate = vi.fn();
vi.mock('@/lib/hooks/use-valuation', () => ({
useValuationPredictForListing: () => ({
mutate: mockMutate,
isPending: false,
data: null,
}),
}));
describe('AiEstimateButton', () => {
beforeEach(() => {
mockMutate.mockClear();
});
it('renders the button', () => {
render(<AiEstimateButton listingId="listing-1" />);
expect(screen.getByText('Dinh gia AI')).toBeInTheDocument();
});
it('calls mutate when clicked', async () => {
const user = userEvent.setup();
render(<AiEstimateButton listingId="listing-1" />);
await user.click(screen.getByText('Dinh gia AI'));
expect(mockMutate).toHaveBeenCalledWith('listing-1', expect.any(Object));
});
it('renders as a button element', () => {
render(<AiEstimateButton listingId="listing-1" />);
expect(screen.getByRole('button', { name: /Dinh gia AI/ })).toBeInTheDocument();
});
});
describe('AiEstimateButton - loading state', () => {
it('shows loading text when pending', () => {
vi.mocked(vi.fn()).mockReturnValue(undefined);
// Re-mock with isPending
vi.doMock('@/lib/hooks/use-valuation', () => ({
useValuationPredictForListing: () => ({
mutate: vi.fn(),
isPending: true,
data: null,
}),
}));
// This test validates the loading button text exists in the component
render(<AiEstimateButton listingId="listing-1" />);
// Component shows 'Dinh gia AI' or 'Dang dinh gia...' based on isPending
expect(screen.getByRole('button')).toBeInTheDocument();
});
});