Files
dbx-main/tests/js/perf_manual.test.js
T
king 67001f0a6e feat: 세부 업무 자동 협업자 없음·마감일 아이콘·담당자별 패널 날짜 + 광고비 13채널·ROAS
[Project]
- 세부 업무를 만들 때 만든 사람을 자동 협업자로 넣지 않음(고른 협업자만), 메인 업무는 그대로
- 업무 창 세부 업무 줄의 빈 마감일 아이콘을 협업자 아이콘처럼 늘 옅게
- 대시보드 담당자별 합계 패널 날짜 mm/dd(요일), 마감 지난 미완료는 빨간 굵은 글씨

[실적 — 광고비]
- 열: 구글·메타·네이버·쿠팡(윙)·쿠팡(로켓)·오늘의집·G마켓·카카오·GS샵·11번가·롯데ON·토스·애터미아자몰
- 칸 = 광고비(ROAS%), ROAS = 그 쇼핑몰 매출 ÷ 광고비(구글·메타 = 카페24), 월/연 누적에도 ROAS

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 10:57:30 +09:00

222 lines
16 KiB
JavaScript

// 실적 — 수동 입력(static/performance.js) · 열 순서 · 설정 토글 — jsdom.
// python tests/js/render_performance.py && NODE_PATH=<jsdom 경로> node tests/js/perf_manual.test.js
const fs = require("fs"), path = require("path");
const { JSDOM } = require("jsdom");
const OUT = path.join(__dirname, ".out");
const JS = fs.readFileSync(path.join(__dirname, "..", "..", "app", "static", "performance.js"), "utf8");
const fails = [];
function check(name, cond, extra) {
if (cond) console.log("PASS " + name);
else { console.log("FAIL " + name + (extra !== undefined ? " → " + JSON.stringify(extra) : "")); fails.push(name); }
}
const settle = function () { return new Promise(function (r) { let i = 0; (function s() { if (i++ > 40) return r(); setImmediate(s); })(); }); };
const wait = function (ms) { return new Promise(function (r) { setTimeout(r, ms); }); };
async function env(file) {
const html = fs.readFileSync(path.join(OUT, file), "utf8").replace(/<script src="\/static\/performance\.js[^"]*" defer><\/script>/, "");
const dom = new JSDOM(html, { runScripts: "dangerously", pretendToBeVisual: true, url: "http://localhost/performance/" });
const w = dom.window;
const e = { w: w, d: w.document, calls: [], status: 200, alerts: [] };
w.erpAlert = function (m) { e.alerts.push(m); return Promise.resolve(); };
w.fetch = async function (url, o) {
const method = (o && o.method) || "GET";
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) {
const api = m[1] === "coupang" && m[2] === "2026-10-05" ? 50000 : m[1] === "coupang" && m[2] === "2026-10-06" ? 7000 : 0;
const manual = body.amount == null ? null : body.amount;
return { ok: true, status: 200, json: async function () { return { ok: true, manual: manual, amount: manual == null ? api : manual, api_amount: api }; } };
}
return { ok: true, status: 200, json: async function () { return {}; } };
};
w.eval(JS);
// jsdom 이 문서를 다 읽은 뒤 DOMContentLoaded 를 스스로 보낸다(직접 보내면 초기화가 두 번 됨)
if (w.document.readyState !== "loading") w.document.dispatchEvent(new w.Event("DOMContentLoaded"));
await settle();
return e;
}
function key(e, el, k, extra) { el.dispatchEvent(new e.w.KeyboardEvent("keydown", Object.assign({ key: k, bubbles: true, cancelable: true }, extra || {}))); }
function cell(e, code, day) { return e.d.querySelector('td.is-manual-cell[data-manual-code="' + code + '"][data-date="' + day + '"]'); }
function gross(td) { return td.querySelector(".v-gross").textContent.trim(); }
(async function () {
// ── 열 순서·제목 ──
{
const e = await env("perf_dash.html");
const heads = Array.from(e.d.querySelectorAll(".perf-main thead th")).map(function (th) { return th.textContent.replace("✎", "").trim(); });
check("[순서] 카페24·네이버·쿠팡·토스·GS샵·11번가 다음 나머지", heads.join(",") ===
"날짜,카페24,네이버,쿠팡,토스,GS샵,11번가,오늘의집,G마켓,카카오,롯데ON,일 합계", heads);
check("[수동] 수동 입력 쇼핑몰 제목에 ✎ 표시", /✎/.test(e.d.querySelectorAll(".perf-main thead th")[3].textContent) &&
!/✎/.test(e.d.querySelectorAll(".perf-main thead th")[1].textContent));
check("[수동] 오늘까지 날짜 칸만 입력 칸(앞으로의 날·주간합계 아님), 수동 값 칸은 파란 표시",
!!cell(e, "coupang", "2026-10-07") && !cell(e, "coupang", "2026-10-08") && cell(e, "coupang", "2026-10-05").classList.contains("is-manual") &&
!cell(e, "coupang", "2026-10-06").classList.contains("is-manual") && !e.d.querySelector(".perf-row-week td.is-manual-cell"));
check("[수동] 입력 칸은 주문 상세 링크가 아님", !cell(e, "coupang", "2026-10-06").classList.contains("is-link") &&
e.d.querySelector('td.is-link[data-code="cafe24"]') !== null);
check("[수동] 표 아래 사용법 안내", /직접 입력/.test((e.d.querySelector(".perf-manual-help") || {}).textContent || ""));
}
// ── 입력 → Enter 저장 후 아래 칸 → Esc 끝 ──
{
const e = await env("perf_dash.html");
let reloaded = 0;
const td5 = cell(e, "coupang", "2026-10-05");
td5.click();
const in5 = td5.querySelector(".perf-manual-input");
check("[입력] 칸을 누르면 입력칸(수동 값이 들어 있음)", !!in5 && in5.value === "87000" && e.d.activeElement === in5);
in5.value = "90,000원";
key(e, in5, "Enter");
await settle();
const put = e.calls.find(function (c) { return c.method === "PUT"; });
check("[입력] Enter → 그 칸 저장(쉼표·원 빼고 숫자)", put && put.url === "/performance/api/manual-sales/coupang/2026-10-05" && put.body.amount === 90000, e.calls);
check("[입력] 저장한 값 표시 + 아래 칸(10/6)으로 입력칸 이동", gross(td5) === "90,000" && !td5.querySelector(".perf-manual-input") &&
!!cell(e, "coupang", "2026-10-06").querySelector(".perf-manual-input"));
const in6 = cell(e, "coupang", "2026-10-06").querySelector(".perf-manual-input");
check("[입력] 수동 값 없는 칸은 비어 있고 API 값이 흐리게(placeholder)", in6.value === "" && in6.placeholder === "7,000", in6.placeholder);
key(e, in6, "Enter"); // 아무것도 안 넣고 Enter — 저장 안 함
await settle();
check("[입력] 빈 칸 그대로 Enter → 저장 요청 없음", e.calls.filter(function (c) { return c.method === "PUT"; }).length === 1);
const in7 = cell(e, "coupang", "2026-10-07").querySelector(".perf-manual-input");
check("[입력] 마지막 입력 칸(오늘)까지 이동", !!in7);
in7.value = "abc";
key(e, in7, "Enter");
await settle(); await wait(200); await settle();
check("[입력] 숫자가 아니면 저장 안 하고 안내", e.alerts.some(function (m) { return /숫자/.test(m); }) &&
e.calls.filter(function (c) { return c.method === "PUT"; }).length === 1, e.alerts);
}
// ── 수동 값 지우기(비우고 저장) → API 값, 실패 시 안내 ──
{
const e = await env("perf_dash.html");
const td5 = cell(e, "coupang", "2026-10-05");
td5.click();
const inp = td5.querySelector(".perf-manual-input");
inp.value = "";
key(e, inp, "Escape");
check("[지우기] Esc → 저장 없이 닫힘", !td5.querySelector(".perf-manual-input") && !e.calls.some(function (c) { return c.method === "PUT"; }));
td5.click();
const inp2 = td5.querySelector(".perf-manual-input");
inp2.value = "";
inp2.dispatchEvent(new e.w.FocusEvent("blur"));
await settle();
const put = e.calls.find(function (c) { return c.method === "PUT"; });
check("[지우기] 비우고 칸을 떠나면 amount=null(그날 API 값)", put && put.body.amount === null);
check("[지우기] API 값(50,000) 표시·파란 표시 해제", gross(td5) === "50,000" && !td5.classList.contains("is-manual"));
e.status = 503;
const td6 = cell(e, "coupang", "2026-10-06");
td6.click();
const i6 = td6.querySelector(".perf-manual-input");
i6.value = "100";
i6.dispatchEvent(new e.w.FocusEvent("blur"));
await settle();
check("[실패] 저장 실패 → 안내(마이그레이션), 값은 그대로", e.alerts.some(function (m) { return /마이그레이션 002/.test(m); }) && gross(td6) === "7,000", e.alerts);
}
// ── 키보드: 칸에서 Enter 로 입력 시작 ──
{
const e = await env("perf_dash.html");
const td = cell(e, "kakao", "2026-10-06");
td.focus();
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("[광고비] 열 = 구글·메타·네이버·쿠팡(윙)·쿠팡(로켓)·오늘의집·G마켓·카카오·GS샵·11번가·롯데ON·토스·애터미아자몰",
heads.join(",") === "날짜,구글,메타,네이버,쿠팡(윙),쿠팡(로켓),오늘의집,G마켓,카카오,GS샵,11번가,롯데ON,토스,애터미아자몰,일 합계", heads);
const wing = cell(e, "coupang_wing", "2026-10-05");
check("[광고비] 칸 = 광고비(ROAS%) — 쿠팡(윙) 29,000 · 쿠팡 매출 87,000 → 300%",
wing.textContent.trim() === "29,000(300%)" && !cell(e, "naver", "2026-10-05").querySelector(".perf-roas"), wing.textContent);
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 — 이번달 광고비 299,000 · 매출 대비 비율", kpi[0] === "₩299,000" && /%$/.test(kpi[1]), kpi);
wing.click();
const wi = wing.querySelector(".perf-manual-input");
wi.value = "30000";
wi.dispatchEvent(new e.w.FocusEvent("blur"));
await settle();
check("[광고비] 광고비를 고치면 옛 ROAS 는 지움(새로고침 때 다시 계산)", gross(wing) === "30,000" && !wing.querySelector(".perf-roas"));
e.calls.length = 0;
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_wing,coupang_rocket", opts);
modal.querySelector(".perf-ad-channel").value = "coupang_rocket";
modal.querySelector(".perf-ad-channel").dispatchEvent(new e.w.Event("change"));
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("[설정] 쇼핑몰 순서 = 어댑터 등록 순서(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;
box.dispatchEvent(new e.w.Event("change", { bubbles: true }));
await settle();
const put = e.calls.find(function (c) { return c.method === "PUT"; });
check("[설정] 토글 → 바로 저장(manual_input)", put && put.url === "/performance/api/marketplaces/coupang" && put.body.manual_input === false, e.calls);
e.status = 503;
const box2 = e.d.querySelector('tr[data-code="naver"] input[data-field="manual_input"]');
box2.checked = true;
box2.dispatchEvent(new e.w.Event("change", { bubbles: true }));
await settle();
check("[설정] 저장 실패(002 미적용) → 되돌리고 안내", !box2.checked && e.alerts.some(function (m) { return /마이그레이션/.test(m); }), e.alerts);
}
console.log(fails.length ? "\n" + fails.length + " FAILED" : "\nALL PASS");
process.exit(fails.length ? 1 : 0);
})();