refactor(subscription): 상수·순수헬퍼를 subscriptionUtils로 추출 + 테스트
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:
42
src/pages/subscription/subscriptionUtils.test.js
Normal file
42
src/pages/subscription/subscriptionUtils.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { extractTier, getDDays, getDDayColor, fmtPrice } from './subscriptionUtils.js';
|
||||
|
||||
describe('extractTier', () => {
|
||||
it('자치구 티어 문자열에서 등급 추출', () => {
|
||||
expect(extractTier(['자치구 S티어: 강남구 (+25)'])).toBe('S');
|
||||
expect(extractTier(['면적 +10', '자치구 B티어: 노원구 (+15)'])).toBe('B');
|
||||
});
|
||||
it('미매치/빈 입력 → null', () => {
|
||||
expect(extractTier(['면적 적합'])).toBe(null);
|
||||
expect(extractTier(null)).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDDays / getDDayColor (오늘 기준 경계)', () => {
|
||||
const iso = (offsetDays) => {
|
||||
const d = new Date(); d.setHours(0,0,0,0); d.setDate(d.getDate() + offsetDays);
|
||||
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', () => {
|
||||
expect(getDDays(iso(0))).toBe('D-Day');
|
||||
expect(getDDays(iso(5))).toBe('D-5');
|
||||
expect(getDDays(iso(-3))).toBe('D+3');
|
||||
expect(getDDays(null)).toBe(null);
|
||||
});
|
||||
it('색 임계: 지남=빨강, ≤3=주황, ≤7=파랑, 그 외=dim', () => {
|
||||
expect(getDDayColor(iso(-1))).toBe('#f87171');
|
||||
expect(getDDayColor(iso(2))).toBe('#f59e0b');
|
||||
expect(getDDayColor(iso(6))).toBe('#00d4ff');
|
||||
expect(getDDayColor(iso(30))).toBe('var(--text-dim)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('fmtPrice (현 구현 동작 고정)', () => {
|
||||
it('억/만 변환', () => {
|
||||
expect(fmtPrice(10000)).toBe('1억');
|
||||
expect(fmtPrice(15000)).toBe('1.5억');
|
||||
expect(fmtPrice(9999)).toBe('9,999만');
|
||||
expect(fmtPrice(null)).toBe(null);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user