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>
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('mapbox-gl', () => {
|
|
class MockMap {
|
|
addControl = vi.fn();
|
|
fitBounds = vi.fn();
|
|
flyTo = vi.fn();
|
|
setStyle = vi.fn();
|
|
remove = vi.fn();
|
|
on = vi.fn();
|
|
}
|
|
class MockNavigationControl {}
|
|
class MockAttributionControl {}
|
|
class MockMarker {
|
|
setLngLat() { return this; }
|
|
setPopup() { return this; }
|
|
addTo() { return this; }
|
|
remove() {}
|
|
}
|
|
class MockPopup {
|
|
setHTML() { return this; }
|
|
setLngLat() { return this; }
|
|
addTo() { return this; }
|
|
remove() {}
|
|
}
|
|
class MockLngLatBounds {
|
|
extend() { return this; }
|
|
isEmpty() { return false; }
|
|
}
|
|
return {
|
|
default: {
|
|
accessToken: '',
|
|
Map: MockMap,
|
|
NavigationControl: MockNavigationControl,
|
|
AttributionControl: MockAttributionControl,
|
|
Marker: MockMarker,
|
|
Popup: MockPopup,
|
|
LngLatBounds: MockLngLatBounds,
|
|
},
|
|
};
|
|
});
|
|
vi.mock('mapbox-gl/dist/mapbox-gl.css', () => ({}));
|
|
vi.mock('@/lib/mapbox-style', () => ({ useMapboxStyle: () => 'mapbox://styles/mapbox/light-v11' }));
|
|
vi.mock('@/lib/currency', () => ({ formatPrice: (v: string | number) => `${v} VNĐ` }));
|
|
vi.mock('@/lib/du-an-api', () => ({
|
|
PROJECT_STATUS_LABELS: { SELLING: 'Đang bán' },
|
|
PROJECT_STATUS_COLORS: { SELLING: 'bg-green-100 text-green-800' },
|
|
}));
|
|
|
|
import { ProjectMap } from '../project-map';
|
|
|
|
const projects = [
|
|
{ id: 'p1', name: 'Vinhomes', slug: 'vinhomes', status: 'SELLING' as const, district: 'Q9', city: 'HCMC', minPrice: '2000000000', latitude: 10.84, longitude: 106.83 },
|
|
] as never[];
|
|
|
|
describe('ProjectMap', () => {
|
|
it('renders fallback when no token', () => {
|
|
delete (process.env as Record<string, string | undefined>)['NEXT_PUBLIC_MAPBOX_TOKEN'];
|
|
render(<ProjectMap projects={[]} />);
|
|
expect(screen.getByText(/NEXT_PUBLIC_MAPBOX_TOKEN/)).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows project count overlay', () => {
|
|
render(<ProjectMap projects={projects} />);
|
|
expect(screen.getByText(/1 dự án trên bản đồ/)).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows 0 projects when empty', () => {
|
|
render(<ProjectMap projects={[]} />);
|
|
expect(screen.getByText(/0 dự án trên bản đồ/)).toBeInTheDocument();
|
|
});
|
|
});
|