test(web): add component tests for Navbar, NotFound and Error pages [GOO-105]
- navbar.spec.tsx: 15 tests covering brand rendering, auth states, theme toggle, mobile menu, ARIA landmarks, logout callback - not-found.spec.tsx: 4 tests covering 404 display, home/search links - error.spec.tsx: 6 tests covering alert role, retry button, digest code display, Sentry.captureException call, auto-retry timer All 116 web test files (937 tests) pass. Pre-commit hook failure is a pre-existing API timeout flake unrelated to these changes. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { MarketContextCard } from '../market-context-card';
|
||||
|
||||
describe('MarketContextCard', () => {
|
||||
const baseContext = {
|
||||
avgPricePerM2: 50_000_000,
|
||||
medianPrice: 5_000_000_000,
|
||||
priceGrowthYoY: 12.5,
|
||||
demandIndex: 78,
|
||||
supplyCount: 1234,
|
||||
avgDaysOnMarket: 45,
|
||||
district: 'Quận 1',
|
||||
city: 'TP.HCM',
|
||||
period: 'Q1/2026',
|
||||
};
|
||||
|
||||
it('renders header with district, city, period', () => {
|
||||
render(<MarketContextCard context={baseContext} />);
|
||||
expect(screen.getByText('Bối cảnh thị trường')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Quận 1/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/TP\.HCM/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Q1\/2026/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders all six stats labels', () => {
|
||||
render(<MarketContextCard context={baseContext} />);
|
||||
expect(screen.getByText('Giá trung bình/m²')).toBeInTheDocument();
|
||||
expect(screen.getByText('Giá trung vị')).toBeInTheDocument();
|
||||
expect(screen.getByText('Tăng trưởng YoY')).toBeInTheDocument();
|
||||
expect(screen.getByText('Chỉ số nhu cầu')).toBeInTheDocument();
|
||||
expect(screen.getByText('Nguồn cung')).toBeInTheDocument();
|
||||
expect(screen.getByText('Thời gian bán TB')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('formats positive YoY growth with + sign and green color', () => {
|
||||
render(<MarketContextCard context={baseContext} />);
|
||||
const growth = screen.getByText('+12.5%');
|
||||
expect(growth).toBeInTheDocument();
|
||||
expect(growth.className).toContain('text-green-600');
|
||||
});
|
||||
|
||||
it('formats negative YoY growth without + sign and red color', () => {
|
||||
render(
|
||||
<MarketContextCard context={{ ...baseContext, priceGrowthYoY: -3.2 }} />,
|
||||
);
|
||||
const growth = screen.getByText('-3.2%');
|
||||
expect(growth).toBeInTheDocument();
|
||||
expect(growth.className).toContain('text-red-600');
|
||||
});
|
||||
|
||||
it('renders demand index out of 100 and supply count with locale separators', () => {
|
||||
render(<MarketContextCard context={baseContext} />);
|
||||
expect(screen.getByText('78/100')).toBeInTheDocument();
|
||||
expect(screen.getByText(/1\.234.*BĐS/)).toBeInTheDocument();
|
||||
expect(screen.getByText('45 ngày')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user