Files
goodgo-platform/apps/web/components/chuyen-nhuong/__tests__/transfer-wizard-client.spec.tsx
Ho Ngoc Hai 7d26436461 test(web): add component tests for 10 untested frontend components (GOO-54)
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>
2026-04-23 20:29:19 +07:00

90 lines
2.9 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
vi.mock('next/navigation', () => ({
useRouter: () => ({ push: vi.fn() }),
}));
vi.mock('@/lib/chuyen-nhuong-api', () => ({
CATEGORY_LABELS: { FURNITURE: 'Nội thất', APPLIANCE: 'Thiết bị', OFFICE_EQUIPMENT: 'Văn phòng', KITCHEN: 'Bếp', PREMISES: 'Mặt bằng', FULL_UNIT: 'Trọn gói' },
CATEGORY_ICONS: {
FURNITURE: () => <span data-testid="icon-furniture" />,
APPLIANCE: () => <span data-testid="icon-appliance" />,
OFFICE_EQUIPMENT: () => <span data-testid="icon-office" />,
KITCHEN: () => <span data-testid="icon-kitchen" />,
PREMISES: () => <span data-testid="icon-premises" />,
FULL_UNIT: () => <span data-testid="icon-full" />,
},
CONDITION_LABELS: { NEW: 'Mới', LIKE_NEW: 'Như mới', GOOD: 'Tốt', FAIR: 'Trung bình', WORN: 'Cũ' },
transferApi: { estimate: vi.fn(), create: vi.fn() },
}));
vi.mock('@/lib/transfer-wizard-store', () => {
const state = {
currentStep: 0,
category: null as string | null,
items: [] as unknown[],
title: '',
description: '',
address: '',
district: '',
city: '',
askingPriceVND: 0,
pricingSource: 'MANUAL',
isNegotiable: false,
aiEstimate: null,
isEstimating: false,
setCategory: vi.fn(),
setStep: vi.fn(),
addItem: vi.fn(),
removeItem: vi.fn(),
setAiEstimate: vi.fn(),
setIsEstimating: vi.fn(),
setListingDetails: vi.fn(),
reset: vi.fn(),
};
return {
useTransferWizardStore: () => state,
};
});
import { TransferWizardClient } from '../transfer-wizard-client';
describe('TransferWizardClient', () => {
it('renders wizard title', () => {
render(<TransferWizardClient />);
expect(screen.getByText('Đăng tin chuyển nhượng')).toBeInTheDocument();
});
it('renders step indicators (4 steps)', () => {
render(<TransferWizardClient />);
expect(screen.getByText('1')).toBeInTheDocument();
expect(screen.getByText('2')).toBeInTheDocument();
expect(screen.getByText('3')).toBeInTheDocument();
expect(screen.getByText('4')).toBeInTheDocument();
});
it('renders current step label "Danh mục" for step 0', () => {
render(<TransferWizardClient />);
expect(screen.getByText('Danh mục')).toBeInTheDocument();
});
it('renders category selection buttons', () => {
render(<TransferWizardClient />);
expect(screen.getByText('Nội thất')).toBeInTheDocument();
expect(screen.getByText('Thiết bị')).toBeInTheDocument();
});
it('renders navigation buttons', () => {
render(<TransferWizardClient />);
expect(screen.getByText(/Quay lại/)).toBeInTheDocument();
expect(screen.getByText(/Tiếp theo/)).toBeInTheDocument();
});
it('disables back button on first step', () => {
render(<TransferWizardClient />);
const backBtn = screen.getByText(/Quay lại/).closest('button');
expect(backBtn).toBeDisabled();
});
});