feat(stock): WatchlistTab 컴포넌트 + wl-* 스타일 + 스모크 테스트

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-03 01:58:24 +09:00
parent a52fd0db8f
commit e8091a0391
3 changed files with 294 additions and 0 deletions

View File

@@ -3232,3 +3232,121 @@
display: none;
}
}
/* ── 관심종목 탭 (Watchlist) ───────────────────────────────── */
.wl-form {
display: flex;
flex-wrap: wrap;
gap: 8px;
align-items: center;
}
.wl-form__input {
flex: 1 1 140px;
min-width: 120px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.03);
color: inherit;
font-size: 13px;
}
.wl-form__input:focus {
outline: none;
border-color: var(--accent-stock);
}
.wl-list {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
gap: 8px;
}
.wl-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(148, 163, 184, 0.12);
border-radius: 10px;
padding: 10px 14px;
}
.wl-row__meta {
display: flex;
align-items: baseline;
flex-wrap: wrap;
gap: 8px;
min-width: 0;
}
.wl-row__name { font-size: 14px; }
.wl-row__ticker { font-size: 12px; color: var(--muted); }
.wl-row__note { font-size: 12px; color: var(--muted); opacity: 0.85; }
.wl-del {
flex: none;
border: none;
background: transparent;
color: #94a3b8;
cursor: pointer;
font-size: 14px;
line-height: 1;
padding: 4px 6px;
border-radius: 6px;
}
.wl-del:hover { color: #ef4444; background: rgba(239, 68, 68, 0.1); }
.wl-period-toggle { display: flex; gap: 4px; }
.wl-period {
border: 1px solid var(--line);
background: transparent;
color: var(--muted);
border-radius: 8px;
padding: 4px 10px;
font-size: 12px;
cursor: pointer;
}
.wl-period.is-active {
color: var(--accent-stock);
border-color: var(--accent-stock);
background: rgba(148, 163, 184, 0.08);
}
.wl-alerts {
display: flex;
flex-direction: column;
gap: 10px;
}
.wl-alert {
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(148, 163, 184, 0.12);
border-radius: 10px;
padding: 12px 14px;
display: flex;
flex-direction: column;
gap: 6px;
}
.wl-alert__head {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.wl-kind-badge {
font-size: 11px;
font-weight: 700;
padding: 2px 8px;
border-radius: 999px;
}
.wl-alert__name { font-size: 14px; }
.wl-alert__ticker { font-size: 12px; color: var(--muted); }
.wl-alert__time { font-size: 11px; color: var(--muted); margin-left: auto; }
.wl-alert__body {
display: flex;
align-items: baseline;
gap: 10px;
flex-wrap: wrap;
}
.wl-cond { font-size: 13px; font-weight: 600; }
.wl-alert__price { font-size: 13px; color: var(--muted); }
.wl-alert__detail { font-size: 12px; color: var(--muted); }

View File

@@ -0,0 +1,145 @@
import React, { useState } from 'react';
import Loading from '../../../components/Loading';
import { kindMeta, conditionLabel, relativeTime } from '../watchlistUtils';
import { formatNumber } from '../stockUtils';
const DAYS_OPTIONS = [
{ value: 1, label: '1D' },
{ value: 7, label: '7D' },
{ value: 30, label: '30D' },
];
const AlertCard = ({ a }) => {
const meta = kindMeta(a.kind);
return (
<div className="wl-alert">
<div className="wl-alert__head">
<span className="wl-kind-badge" style={{ color: meta.color, background: meta.bg }}>{meta.label}</span>
<strong className="wl-alert__name">{a.name || a.ticker}</strong>
<span className="wl-alert__ticker">{a.ticker}</span>
<span className="wl-alert__time">{relativeTime(a.fired_at)}</span>
</div>
<div className="wl-alert__body">
<span className="wl-cond">{conditionLabel(a.condition)}</span>
{a.price != null && <span className="wl-alert__price">{formatNumber(a.price)}</span>}
</div>
{a.detail && <div className="wl-alert__detail">{a.detail}</div>}
</div>
);
};
const WatchlistTab = ({ wl }) => {
const [form, setForm] = useState({ ticker: '', name: '', note: '' });
const submit = async (e) => {
e.preventDefault();
if (!form.ticker.trim()) return;
await wl.add(form);
setForm({ ticker: '', name: '', note: '' });
};
return (
<>
{/* 관심종목 관리 */}
<section className="stock-panel stock-panel--wide wl-panel">
<div className="stock-panel__head">
<div>
<p className="stock-panel__eyebrow">관심종목</p>
<h3>관심종목 관리</h3>
<p className="stock-panel__sub">등록한 종목은 매매 시그널 감시 유니버스에 포함됩니다.</p>
</div>
<div className="stock-panel__actions">{wl.loading && <Loading type="spinner" message="" />}</div>
</div>
<form className="wl-form" onSubmit={submit}>
<input
className="wl-form__input"
placeholder="종목코드 (예: 005930)"
value={form.ticker}
onChange={(e) => setForm((f) => ({ ...f, ticker: e.target.value }))}
/>
<input
className="wl-form__input"
placeholder="종목명 (선택)"
value={form.name}
onChange={(e) => setForm((f) => ({ ...f, name: e.target.value }))}
/>
<input
className="wl-form__input"
placeholder="메모 (선택)"
value={form.note}
onChange={(e) => setForm((f) => ({ ...f, note: e.target.value }))}
/>
<button className="button" type="submit" disabled={!form.ticker.trim() || wl.adding}>
{wl.adding ? '추가 중…' : '추가'}
</button>
</form>
{wl.error && <p className="stock-error">{wl.error}</p>}
{wl.items.length === 0 ? (
<p className="stock-empty">아직 관심종목이 없습니다. 종목코드를 추가해 보세요.</p>
) : (
<ul className="wl-list">
{wl.items.map((it) => (
<li key={it.ticker} className="wl-row">
<div className="wl-row__meta">
<strong className="wl-row__name">{it.name || it.ticker}</strong>
<span className="wl-row__ticker">{it.ticker}</span>
{it.note && <span className="wl-row__note">{it.note}</span>}
</div>
<button
className="wl-del"
type="button"
aria-label={`${it.ticker} 삭제`}
onClick={() => wl.remove(it.ticker)}
>
</button>
</li>
))}
</ul>
)}
</section>
{/* 최근 시그널 알림 */}
<section className="stock-panel stock-panel--wide wl-panel">
<div className="stock-panel__head">
<div>
<p className="stock-panel__eyebrow">시그널</p>
<h3>최근 매매 알림</h3>
<p className="stock-panel__sub">감시 종목에서 발생한 매수·매도 시그널 이력입니다.</p>
</div>
<div className="wl-period-toggle">
{DAYS_OPTIONS.map((o) => (
<button
key={o.value}
type="button"
className={`wl-period ${wl.alertDays === o.value ? 'is-active' : ''}`}
onClick={() => wl.setAlertDays(o.value)}
>
{o.label}
</button>
))}
</div>
</div>
{wl.alertError && <p className="stock-error">{wl.alertError}</p>}
{wl.alerts.length === 0 ? (
<p className="stock-empty">해당 기간에 발생한 알림이 없습니다.</p>
) : (
<div className="wl-alerts">
{wl.alerts.map((a) => (
<AlertCard key={a.id ?? `${a.ticker}-${a.fired_at}`} a={a} />
))}
</div>
)}
<p className="hi-disclaimer"> 어드바이저리 알림이며 자동매매가 아닙니다. 최종 판단은 본인 책임입니다.</p>
</section>
</>
);
};
export default WatchlistTab;

View File

@@ -0,0 +1,31 @@
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import WatchlistTab from './WatchlistTab.jsx';
const baseWl = {
items: [], alerts: [], alertDays: 7, setAlertDays: vi.fn(),
loading: false, error: '', alertError: '', adding: false,
add: vi.fn(), remove: vi.fn(), reload: vi.fn(),
};
describe('WatchlistTab', () => {
it('빈 상태: 헤딩과 빈 안내 노출', () => {
render(<WatchlistTab wl={baseWl} />);
expect(screen.getByText('관심종목 관리')).toBeInTheDocument();
expect(screen.getByText(/아직 관심종목이 없습니다/)).toBeInTheDocument();
expect(screen.getByText(/발생한 알림이 없습니다/)).toBeInTheDocument();
});
it('종목·알림이 있으면 렌더', () => {
const wl = {
...baseWl,
items: [{ ticker: '005930', name: '삼성전자', note: '반도체 대장', added_at: '2026-07-01T00:00:00Z' }],
alerts: [{ id: 1, ticker: '005930', name: '삼성전자', kind: 'buy', condition: 'buy_breakout', price: 81000, detail: '박스권 돌파', fired_at: '2026-07-03T01:00:00Z' }],
};
render(<WatchlistTab wl={wl} />);
// '삼성전자'는 관심종목 목록 행과 알림 카드 양쪽에 렌더되므로 getAllByText로 확인
expect(screen.getAllByText('삼성전자')).toHaveLength(2);
expect(screen.getByText('매수')).toBeInTheDocument();
expect(screen.getByText('박스 상단 돌파')).toBeInTheDocument();
});
});