fix(stock): 매매알람 detail 객체 렌더 크래시(React #31) 방지
/api/stock/trade-alerts의 alerts[].detail은 condition별 가변 객체
({ma50,ma200,severity} 등)인데 JSX 자식으로 직접 렌더 → React #31로
페이지 크래시(워커가 실제 알람 발화 시작하며 발현, BE msg #17).
formatDetail 헬퍼 추가: 객체를 안전 문자열로 변환(알려진 키 한글 라벨,
*_pct 퍼센트, null 값 스킵, 미정의 키도 원문 폴백 — 스키마 가정 없음).
AlertCard가 detail 대신 formatDetail(detail) 렌더.
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:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { kindMeta, conditionLabel, normalizeTicker, relativeTime } from './watchlistUtils.js';
|
||||
import { kindMeta, conditionLabel, normalizeTicker, relativeTime, formatDetail } from './watchlistUtils.js';
|
||||
|
||||
describe('kindMeta', () => {
|
||||
it('buy/sell 라벨과 색을 반환', () => {
|
||||
@@ -53,6 +53,34 @@ describe('normalizeTicker', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatDetail (알림 detail 객체 → 안전 문자열, React #31 방지)', () => {
|
||||
it('객체 detail을 읽기 좋은 문자열로 변환하고 절대 객체를 반환하지 않는다', () => {
|
||||
const s = formatDetail({ avg_price: 75325, pnl_pct: -0.1012, stop_pct: 0.08 });
|
||||
expect(typeof s).toBe('string');
|
||||
expect(s).toContain('75,325'); // avg_price 천단위 포맷
|
||||
expect(s).toContain('-10.12%'); // *_pct 는 퍼센트로
|
||||
expect(s).toContain('8.00%');
|
||||
});
|
||||
it('값이 null인 필드는 건너뛴다', () => {
|
||||
const s = formatDetail({ ma50: 33309.8, ma200: null, severity: 'normal' });
|
||||
expect(typeof s).toBe('string');
|
||||
expect(s).toContain('normal');
|
||||
expect(s).not.toContain('null');
|
||||
});
|
||||
it('문자열 detail은 그대로 반환', () => {
|
||||
expect(formatDetail('박스권 돌파')).toBe('박스권 돌파');
|
||||
});
|
||||
it('null/undefined 는 빈 문자열', () => {
|
||||
expect(formatDetail(null)).toBe('');
|
||||
expect(formatDetail(undefined)).toBe('');
|
||||
});
|
||||
it('미정의 키(스키마 가정 없음)도 크래시 없이 문자열로', () => {
|
||||
const s = formatDetail({ some_new_field: 42 });
|
||||
expect(typeof s).toBe('string');
|
||||
expect(s).toContain('42');
|
||||
});
|
||||
});
|
||||
|
||||
describe('relativeTime', () => {
|
||||
const now = new Date('2026-07-03T12:00:00Z').getTime();
|
||||
it('60초 미만은 방금', () => {
|
||||
|
||||
Reference in New Issue
Block a user