Cover critical-path and feature components that were missing tests: - charts: district-heatmap - chuyen-nhuong: detail-client, transfer-wizard-client - du-an: detail-client, project-ai-advice-card, project-map - khu-cong-nghiep: detail-client, listing-search-client, park-compare-client, park-map All 49 new tests pass with Vitest + React Testing Library. Co-Authored-By: Paperclip <noreply@paperclip.ing>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
|
|
vi.mock('@/lib/analytics-api', () => ({
|
|
analyticsApi: { getProjectAiAdvice: vi.fn().mockReturnValue(new Promise(() => {})) },
|
|
}));
|
|
|
|
vi.mock('@/lib/api-client', () => ({
|
|
ApiError: class extends Error { status = 500; },
|
|
}));
|
|
|
|
vi.mock('@/lib/auth-store', () => ({
|
|
useAuthStore: (selector: (s: { user: null }) => unknown) => selector({ user: null }),
|
|
}));
|
|
|
|
import { ProjectAiAdviceCard } from '../project-ai-advice-card';
|
|
|
|
function wrapper({ children }: { children: React.ReactNode }) {
|
|
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
return <QueryClientProvider client={qc}>{children}</QueryClientProvider>;
|
|
}
|
|
|
|
describe('ProjectAiAdviceCard', () => {
|
|
it('renders trigger button initially', () => {
|
|
render(<ProjectAiAdviceCard projectId="p1" />, { wrapper });
|
|
expect(screen.getByText('Xem phân tích AI về dự án')).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows loading state when clicked', async () => {
|
|
const user = userEvent.setup();
|
|
render(<ProjectAiAdviceCard projectId="p1" />, { wrapper });
|
|
await user.click(screen.getByText('Xem phân tích AI về dự án'));
|
|
expect(screen.getByText(/AI đang phân tích/)).toBeInTheDocument();
|
|
});
|
|
});
|