feat(performance): 광고비 탭(구글·메타·쿠팡 윙/로켓) + 탭 개편·설정 톱니
- 탭: [매출 실적](검정) · [광고비](주황) 큰 탭 + 맨 오른쪽 설정 톱니(Material Symbols settings)
- /performance/ads: 연·월·일 표(채널 × 날짜)·추이·비중·월/연 누적, 매출 대비 광고비 KPI
- 날짜 칸 직접 입력(PUT /api/ad-spend/{channel}/{day}), 쿠팡(로켓) 광고 보고서 업로드
(CSV/엑셀, 1열 날짜·19열 청구금액(+부가가치세), 잘못된 줄 있으면 전부 거절)
- performance_db 마이그레이션 005 perf_ad_spend
- 설정 화면 쇼핑몰 순서 jsdom 기대값을 003 열 순서로 갱신(기존 실패)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,8 +20,17 @@ async function env(file) {
|
||||
w.erpAlert = function (m) { e.alerts.push(m); return Promise.resolve(); };
|
||||
w.fetch = async function (url, o) {
|
||||
const method = (o && o.method) || "GET";
|
||||
const body = o && o.body ? JSON.parse(o.body) : null;
|
||||
e.calls.push({ method: method, url: url, body: body });
|
||||
const isForm = o && o.body && typeof o.body !== "string";
|
||||
const body = o && o.body && !isForm ? JSON.parse(o.body) : null;
|
||||
e.calls.push({ method: method, url: url, body: body, form: isForm ? o.body : null });
|
||||
if (/^\/performance\/api\/ad-spend\/upload/.test(url)) {
|
||||
return { ok: true, status: 200, json: async function () {
|
||||
return { ok: true, saved: 12, name: "쿠팡(로켓)", total: 2636494, from: "2026-10-01", to: "2026-10-12" }; } };
|
||||
}
|
||||
const ad = /^\/performance\/api\/ad-spend\/([^/]+)\/([\d-]+)$/.exec(url);
|
||||
if (ad) {
|
||||
return { ok: true, status: 200, json: async function () { return { ok: true, manual: body.amount, amount: body.amount || 0 }; } };
|
||||
}
|
||||
if (e.status >= 400) return { ok: false, status: e.status, json: async function () { return { detail: "수동 입력을 쓰려면 마이그레이션 002" }; } };
|
||||
const m = /^\/performance\/api\/manual-sales\/([^/]+)\/([\d-]+)$/.exec(url);
|
||||
if (m) {
|
||||
@@ -119,13 +128,67 @@ function gross(td) { return td.querySelector(".v-gross").textContent.trim(); }
|
||||
key(e, td, "Enter");
|
||||
check("[키보드] 칸에 포커스 후 Enter → 입력칸", !!td.querySelector(".perf-manual-input"));
|
||||
}
|
||||
// ── 탭: [매출 실적] [광고비] + 맨 오른쪽 설정 톱니 ──
|
||||
{
|
||||
const e = await env("perf_dash.html");
|
||||
const tabs = Array.from(e.d.querySelectorAll(".perf-tabs-main .perf-tab")).map(function (a) { return a.textContent.replace(/monitoring|campaign/, "").trim(); });
|
||||
check("[탭] 매출 실적 · 광고비", tabs.join(",") === "매출 실적,광고비", tabs);
|
||||
check("[탭] 매출 실적이 고른 탭", e.d.querySelector(".perf-tab-sales").classList.contains("is-active") &&
|
||||
!e.d.querySelector(".perf-tab-ads").classList.contains("is-active"));
|
||||
const gear = e.d.querySelector(".perf-tabs > .perf-tab-gear");
|
||||
check("[탭] 설정 = 맨 오른쪽 톱니 아이콘(settings)", gear && gear === e.d.querySelector(".perf-tabs").lastElementChild &&
|
||||
gear.getAttribute("href") === "/performance/settings" && gear.textContent.trim() === "settings" && !!gear.title);
|
||||
}
|
||||
// ── 광고비 화면 ──
|
||||
{
|
||||
const e = await env("perf_ads.html");
|
||||
check("[광고비] 광고비 탭이 고른 탭", e.d.querySelector(".perf-tab-ads").classList.contains("is-active"));
|
||||
const heads = Array.from(e.d.querySelectorAll(".perf-main thead th")).map(function (th) { return th.textContent.replace("✎", "").trim(); });
|
||||
check("[광고비] 열 = 구글·메타·쿠팡(윙)·쿠팡(로켓)", heads.join(",") === "날짜,구글,메타,쿠팡(윙),쿠팡(로켓),일 합계", heads);
|
||||
const up = cell(e, "coupang_rocket", "2026-10-01"), man = cell(e, "google", "2026-10-02");
|
||||
check("[광고비] 업로드 값 = 주황(is-upload), 직접 입력 = 파랑(is-manual)", up.classList.contains("is-upload") &&
|
||||
!up.classList.contains("is-manual") && man.classList.contains("is-manual") && gross(up) === "220,000");
|
||||
check("[광고비] 앞으로의 날은 입력 칸 아님", !cell(e, "google", "2026-10-08") && !!cell(e, "google", "2026-10-07"));
|
||||
const kpi = Array.from(e.d.querySelectorAll(".perf-kpi-value")).map(function (n) { return n.textContent.trim(); });
|
||||
check("[광고비] KPI — 이번달 광고비 270,000 · 매출 대비 비율", kpi[0] === "₩270,000" && /%$/.test(kpi[1]), kpi);
|
||||
check("[광고비] 매출 실적의 수수료 전환 없음", !e.d.querySelector(".perf-metric") && e.d.getElementById("perf-dash").dataset.metric === "gross");
|
||||
const td = cell(e, "meta", "2026-10-03");
|
||||
td.click();
|
||||
const inp = td.querySelector(".perf-manual-input");
|
||||
check("[광고비] 칸을 누르면 입력칸(광고비)", !!inp && /광고비/.test(inp.getAttribute("aria-label")));
|
||||
inp.value = "33,000";
|
||||
key(e, inp, "Escape");
|
||||
td.click();
|
||||
const inp2 = td.querySelector(".perf-manual-input");
|
||||
inp2.value = "33,000";
|
||||
inp2.dispatchEvent(new e.w.FocusEvent("blur"));
|
||||
await settle();
|
||||
const put = e.calls.find(function (c) { return c.method === "PUT"; });
|
||||
check("[광고비] 저장 → /api/ad-spend/meta/2026-10-03 (33000)", put && put.url === "/performance/api/ad-spend/meta/2026-10-03" &&
|
||||
put.body.amount === 33000, e.calls);
|
||||
check("[광고비] 저장 후 파란 표시", gross(td) === "33,000" && td.classList.contains("is-manual"));
|
||||
// 파일 업로드 창
|
||||
e.d.getElementById("perf-ad-upload").click();
|
||||
const modal = e.d.querySelector(".perf-modal");
|
||||
const opts = Array.from(modal.querySelectorAll(".perf-ad-channel option")).map(function (o) { return o.value; });
|
||||
check("[업로드] 채널 선택 = 양식이 정해진 쿠팡(로켓)", opts.join(",") === "coupang_rocket", opts);
|
||||
check("[업로드] 양식 안내(19열 청구금액)", /19열/.test(modal.querySelector(".perf-ad-help").textContent));
|
||||
const fileInput = modal.querySelector(".perf-upload-file");
|
||||
const f = new e.w.File(["날짜"], "rocket.csv", { type: "text/csv" });
|
||||
Object.defineProperty(fileInput, "files", { value: [f] });
|
||||
Array.from(modal.querySelectorAll(".perf-modal-foot button, button")).filter(function (b) { return b.textContent === "업로드"; })[0].click();
|
||||
await settle();
|
||||
const post = e.calls.find(function (c) { return c.method === "POST"; });
|
||||
check("[업로드] POST /api/ad-spend/upload?channel=coupang_rocket (파일)", post && post.url === "/performance/api/ad-spend/upload?channel=coupang_rocket" && !!post.form, e.calls);
|
||||
check("[업로드] 결과 안내(12일 반영)", /12일 반영/.test(modal.querySelector(".perf-upload-result").textContent));
|
||||
}
|
||||
// ── 설정: 수동 입력 토글 ──
|
||||
{
|
||||
const e = await env("perf_settings.html");
|
||||
const heads = Array.from(e.d.querySelectorAll(".perf-set-table thead th")).map(function (th) { return th.textContent.trim(); });
|
||||
check("[설정] '수동 입력' 열(매출 집계 다음)", heads.indexOf("수동 입력") === heads.indexOf("매출 집계") + 1, heads);
|
||||
const rows = Array.from(e.d.querySelectorAll(".perf-set-table tbody tr")).map(function (tr) { return tr.dataset.code; });
|
||||
check("[설정] 쇼핑몰 순서 = 표 순서", rows.join(",") === "cafe24,naver,coupang,toss,gsshop,elevenst,ohouse,gmarket,kakao,lotteon", rows);
|
||||
check("[설정] 쇼핑몰 순서 = 어댑터 등록 순서(003 열 순서)", rows.join(",") === "cafe24,naver,coupang,ohouse,gmarket,kakao,gsshop,elevenst,lotteon,toss", rows);
|
||||
const box = e.d.querySelector('tr[data-code="coupang"] input[data-field="manual_input"]');
|
||||
check("[설정] 켜진 쇼핑몰은 체크", box && box.checked && !e.d.querySelector('tr[data-code="cafe24"] input[data-field="manual_input"]').checked);
|
||||
box.checked = false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""실적 대시보드(index.html)·설정(settings.html)을 테스트용 HTML 로 렌더한다(erp_base.html 은 최소 스텁, 가상의 데이터).
|
||||
"""실적 대시보드(index.html)·광고비(ads.html)·설정(settings.html)을 테스트용 HTML 로 렌더한다(erp_base.html 은 최소 스텁, 가상의 데이터).
|
||||
|
||||
python tests/js/render_performance.py # → tests/js/.out/perf_dash.html · perf_settings.html
|
||||
python tests/js/render_performance.py # → tests/js/.out/perf_dash.html · perf_ads.html · perf_settings.html
|
||||
|
||||
화면 데이터는 실제 build_dashboard·build_settings 로 만든다(저장소만 가짜). DB·쇼핑몰 API 는 쓰지 않는다.
|
||||
쿠팡은 수동 입력 켬(10/5 수동 값 87,000, 10/6 은 API 값만), 카카오도 켬(값 없음), 나머지는 끔.
|
||||
@@ -19,6 +19,7 @@ ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)
|
||||
sys.path.insert(0, ROOT)
|
||||
OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
|
||||
|
||||
from app.modules.performance.ad_spend import build_ad_dashboard # noqa: E402
|
||||
from app.modules.performance.dashboard import build_dashboard, build_settings # noqa: E402
|
||||
|
||||
BASE_STUB = ("{% block head_extra %}{% endblock %}<body><main class='erp-page'>{% block content %}{% endblock %}</main>"
|
||||
@@ -56,6 +57,11 @@ class FakeStore:
|
||||
def running_codes(self):
|
||||
return []
|
||||
|
||||
def ad_amounts(self, start, end):
|
||||
rows = {(date(2026, 10, 1), "coupang_rocket"): (220000, "upload"), (date(2026, 10, 2), "google"): (50000, "manual")}
|
||||
rows = {k: v for k, v in rows.items() if start <= k[0] <= end}
|
||||
return {k: v[0] for k, v in rows.items()}, {k: v[1] for k, v in rows.items()}
|
||||
|
||||
|
||||
def env() -> jinja2.Environment:
|
||||
e = jinja2.Environment(loader=jinja2.ChoiceLoader([
|
||||
@@ -73,6 +79,11 @@ def main() -> None:
|
||||
html = e.get_template("performance/index.html").render(**base, active_tab="dashboard", metric="gross", **ctx)
|
||||
with open(os.path.join(OUT_DIR, "perf_dash.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
actx = build_ad_dashboard(FakeStore(), kind="month", anchor=date(2026, 10, 7), today=date(2026, 10, 7),
|
||||
sales_codes=["cafe24", "coupang"])
|
||||
html = e.get_template("performance/ads.html").render(**base, active_tab="ads", **actx)
|
||||
with open(os.path.join(OUT_DIR, "perf_ads.html"), "w", encoding="utf-8") as f:
|
||||
f.write(html)
|
||||
sctx = build_settings(FakeStore(), configured={}, key_info={}, key_versions_in_use={}, sample_count=0)
|
||||
html = e.get_template("performance/settings.html").render(**base, active_tab="settings", **sctx)
|
||||
with open(os.path.join(OUT_DIR, "perf_settings.html"), "w", encoding="utf-8") as f:
|
||||
|
||||
Reference in New Issue
Block a user