refactor(realestate): 상수·데이터·순수헬퍼를 realEstateUtils로 추출 + 테스트

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UHXzpsZQxKG9hQmNRfZjRS
This commit is contained in:
2026-07-09 22:57:01 +09:00
parent 96de7e714d
commit e578c41485
3 changed files with 176 additions and 141 deletions

View File

@@ -0,0 +1,31 @@
import { describe, it, expect } from 'vitest';
import { formatDate, formatPrice, getDDays } from './realEstateUtils.js';
describe('formatPrice', () => {
it('만원 표기 / falsy → -', () => {
expect(formatPrice(4500)).toBe('4,500만원');
expect(formatPrice(0)).toBe('-');
expect(formatPrice(null)).toBe('-');
});
});
describe('getDDays (오늘 기준)', () => {
const iso = (off) => {
const d = new Date(); d.setHours(0,0,0,0); d.setDate(d.getDate() + off);
const p = (n) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${p(d.getMonth()+1)}-${p(d.getDate())}`;
};
it('오늘=D-Day, 미래=D-N, 과거=D+N, null→null', () => {
expect(getDDays(iso(0))).toBe('D-Day');
expect(getDDays(iso(4))).toBe('D-4');
expect(getDDays(iso(-2))).toBe('D+2');
expect(getDDays(null)).toBe(null);
});
});
describe('formatDate', () => {
it('유효 날짜 한국어 포맷 / falsy → -', () => {
expect(formatDate('2026-04-10')).toContain('2026');
expect(formatDate(null)).toBe('-');
});
});