fix(web): consolidate inline currency formatters into shared lib (GOO-205)

Remove 8 inline formatPrice/formatVND/formatPriceM2 functions scattered
across components and pages, replacing them with imports from
@/lib/currency. Add formatVNDFull (full locale, no compact notation) for
chuyen-nhuong pages. Fix price-history-chart off-by-1000 bug caused by
double-dividing through priceToMillions then formatMillions. Add k/m²
branch to formatPricePerM2 for sub-million values.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-04-24 14:17:32 +07:00
parent dfb398131d
commit e850ac48d7
10 changed files with 90 additions and 87 deletions

View File

@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
import {
formatPrice,
formatVND,
formatVNDFull,
formatPricePerM2,
parseVND,
} from '../currency';
@@ -105,6 +106,31 @@ describe('formatPricePerM2', () => {
});
});
// ---------------------------------------------------------------------------
// formatVNDFull — full locale format, no compact notation
// ---------------------------------------------------------------------------
describe('formatVNDFull', () => {
it('formats with full locale number + đ suffix', () => {
expect(formatVNDFull(4_990_000)).toMatch(/4.*990.*000.*đ/);
});
it('never uses compact notation', () => {
const result = formatVNDFull(1_500_000_000);
expect(result).not.toContain('tỷ');
expect(result).toContain('đ');
});
it('handles zero and negatives', () => {
expect(formatVNDFull(0)).toMatch(/0.*đ/);
expect(formatVNDFull(-1)).toBe('0 đ');
});
it('accepts string input', () => {
expect(formatVNDFull('1500000')).toMatch(/1.*500.*000.*đ/);
});
});
// ---------------------------------------------------------------------------
// parseVND — reverse parse
// ---------------------------------------------------------------------------