cebe5719a5
메모 대상을 수동 입력 칸(td.is-manual-cell)에서 쇼핑몰 날짜 칸 전부(td[data-memo-code])로 넓힘. 왼쪽 클릭은 그대로(입력 칸 = 금액 입력, API 칸 = 주문 내역). 그룹 열·주간합계·합계 줄은 아님. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
140 lines
10 KiB
JavaScript
140 lines
10 KiB
JavaScript
// 실적 — 날짜 칸 메모·광고비 표 모양(2026-10-22) — 실제 브라우저(Chromium).
|
|
// python tests/js/render_performance.py
|
|
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/perf_memo_ads.browser.test.js
|
|
// 매출·광고비: 입력 칸 우클릭 → 메모 삽입(창) → 저장(PUT /api/cell-memos/{kind}/{코드}/{날짜}) → 빨간 삼각형, 마우스 올리면 메모 상자,
|
|
// 우클릭 → 메모 수정·메모 삭제. 광고비 표: 기타광고비 열(애터미아자몰 오른쪽), 열 너비 = 내용 길이, 날짜 열 고정.
|
|
const fs = require("fs"), path = require("path");
|
|
const { chromium } = require("playwright");
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
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); }
|
|
}
|
|
function page(file) {
|
|
const css = fs.readFileSync(path.join(ROOT, "app", "static", "performance.css"), "utf8");
|
|
const js = fs.readFileSync(path.join(ROOT, "app", "static", "performance.js"), "utf8");
|
|
return fs.readFileSync(path.join(__dirname, ".out", file), "utf8")
|
|
.replace(/<link rel="stylesheet" href="\/static\/performance\.css[^"]*" \/>/, function () { return "<style>" + css + "</style>"; })
|
|
.replace(/<script src="\/static\/performance\.js[^"]*" defer><\/script>/, function () { return "<script>" + js + "</script>"; });
|
|
}
|
|
|
|
async function memoFlow(browser, file, kind, code, day, hasMemo, label, manual) {
|
|
const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 } });
|
|
const p = await ctx.newPage();
|
|
const puts = [];
|
|
await p.route("**/*", function (r) {
|
|
const req = r.request(), url = new URL(req.url()).pathname;
|
|
if (url.startsWith("/performance/api/cell-memos/")) {
|
|
const body = JSON.parse(req.postData() || "{}");
|
|
puts.push({ url: url, memo: body.memo });
|
|
r.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ ok: true, memo: (body.memo || "").trim() }) });
|
|
return;
|
|
}
|
|
if (url.startsWith("/performance/api/")) { r.fulfill({ status: 200, contentType: "application/json", body: "{}" }); return; }
|
|
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: page(file) });
|
|
});
|
|
await p.goto("http://perf.test/performance/");
|
|
// 칸 풍선 도움말 없음(2026-10-22) — 표 몸통 칸(날짜·금액·광고비 줄)과 그 안 어디에도 title 이 없다(열 머리글은 그대로)
|
|
const tips = await p.evaluate(function () {
|
|
return Array.from(document.querySelectorAll(".perf-main tbody [title]")).map(function (n) { return n.tagName + ":" + n.getAttribute("title"); });
|
|
});
|
|
check(label + " 표 칸에 풍선 도움말(title) 없음", tips.length === 0, tips.slice(0, 5));
|
|
const td = 'td[data-memo-code="' + code + '"][data-date="' + day + '"]';
|
|
// 표를 스크롤하면 열린 메뉴는 닫힌다(사람은 스크롤한 뒤 우클릭) — 오른쪽 끝 열(기타광고비)은 먼저 보이게 스크롤해 둔다
|
|
const show = async function (sel) { await p.locator(sel).scrollIntoViewIfNeeded(); await p.waitForTimeout(80); };
|
|
const memoed = 'td[data-memo-code="' + hasMemo[0] + '"][data-date="' + hasMemo[1] + '"]';
|
|
// 기존 메모 = 빨간 삼각형 + 마우스 올리면 메모 상자
|
|
const mark = await p.evaluate(function (sel) {
|
|
const el = document.querySelector(sel);
|
|
const after = getComputedStyle(el, "::after");
|
|
return { has: el.classList.contains("has-memo"), color: after.borderTopColor, content: after.content };
|
|
}, memoed);
|
|
check(label + " 메모 있는 칸 = 빨간 삼각형", mark.has && /rgb\(224, 49, 49\)/.test(mark.color) && mark.content === '""', mark);
|
|
await p.hover(memoed);
|
|
const tip = await p.evaluate(function () { const t = document.querySelector(".perf-memo-tip"); return t ? t.textContent : null; });
|
|
check(label + " 마우스 올리면 메모 상자", tip === hasMemo[2], tip);
|
|
// 메모 없는 칸 우클릭 → 메모 삽입만
|
|
await p.mouse.move(5, 5);
|
|
await show(td);
|
|
await p.click(td, { button: "right" });
|
|
const menu1 = await p.$$eval(".perf-ctx button", function (bs) { return bs.map(function (b) { return b.textContent; }); });
|
|
check(label + " 메모 없는 칸 우클릭 = [메모 삽입]", JSON.stringify(menu1) === JSON.stringify(["메모 삽입"]), menu1);
|
|
await p.click(".perf-ctx button");
|
|
await p.waitForSelector(".perf-memo-input");
|
|
const title = await p.textContent(".perf-modal-head h3");
|
|
check(label + " 메모 삽입 창(제목에 칸 이름·날짜)", /메모 삽입/.test(title) && title.indexOf(day.replace(/-/g, ".")) >= 0, title);
|
|
await p.fill(".perf-memo-input", "첫 메모\n둘째 줄");
|
|
await p.click(".perf-modal-foot .erp-btn-primary");
|
|
await p.waitForFunction(function (sel) { return document.querySelector(sel).classList.contains("has-memo"); }, td);
|
|
const put1 = puts[puts.length - 1];
|
|
check(label + " 저장 → PUT /api/cell-memos/" + kind + "/…, 칸에 표시", put1 && put1.url === "/performance/api/cell-memos/" + kind + "/" + code + "/" + day &&
|
|
put1.memo === "첫 메모\n둘째 줄" && !(await p.$(".perf-modal")), put1);
|
|
// 메모 있는 칸 우클릭 → 메모 수정·메모 삭제
|
|
await p.click(td, { button: "right" });
|
|
const menu2 = await p.$$eval(".perf-ctx button", function (bs) { return bs.map(function (b) { return b.textContent; }); });
|
|
check(label + " 메모 있는 칸 우클릭 = [메모 수정][메모 삭제]", JSON.stringify(menu2) === JSON.stringify(["메모 수정", "메모 삭제"]), menu2);
|
|
await p.click(".perf-ctx button:first-child");
|
|
const v = await p.inputValue(".perf-memo-input");
|
|
check(label + " 메모 수정 창에 지금 메모", v === "첫 메모\n둘째 줄", v);
|
|
await p.fill(".perf-memo-input", "고친 메모");
|
|
await p.keyboard.press("Control+Enter");
|
|
await p.waitForFunction(function (sel) { return document.querySelector(sel).dataset.memo === "고친 메모"; }, td);
|
|
check(label + " Ctrl+Enter 로 저장", puts[puts.length - 1].memo === "고친 메모");
|
|
p.once("dialog", function (d) { d.accept(); });
|
|
await p.click(td, { button: "right" });
|
|
await p.click(".perf-ctx button.is-danger");
|
|
await p.waitForFunction(function (sel) { return !document.querySelector(sel).classList.contains("has-memo"); }, td);
|
|
check(label + " 메모 삭제 → 빈 메모로 저장, 표시 사라짐", puts[puts.length - 1].memo === "");
|
|
check(label + " 저장한 뒤에도 칸에 풍선 도움말 없음", !(await p.getAttribute(td, "title")));
|
|
// 칸 왼쪽 클릭은 예전처럼 — 입력 칸은 금액 입력, API 쇼핑몰 칸은 입력 칸이 아님(값 있으면 주문 내역)
|
|
await p.click(td);
|
|
if (manual !== false) check(label + " 칸 클릭은 그대로 금액 입력", !!(await p.$(td + " .perf-manual-input")));
|
|
else check(label + " API 쇼핑몰 칸은 입력 칸이 아님(우클릭 메모만)", !(await p.$(td + " .perf-manual-input")) && !(await p.$(td + ".is-manual-cell")));
|
|
await ctx.close();
|
|
}
|
|
|
|
(async function () {
|
|
const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {});
|
|
try {
|
|
await memoFlow(browser, "perf_dash.html", "sales", "coupang", "2026-10-06", ["coupang", "2026-10-05", "행사 매출 포함\n2차 정산 예정"], "[매출]");
|
|
// 2026-10-22 — API 쇼핑몰(카페24, 수동 입력 아님) 칸도 메모
|
|
await memoFlow(browser, "perf_dash.html", "sales", "cafe24", "2026-10-06", ["coupang", "2026-10-05", "행사 매출 포함\n2차 정산 예정"], "[매출·API 쇼핑몰]", false);
|
|
await memoFlow(browser, "perf_ads.html", "ad", "etc", "2026-10-06", ["coupang_wing", "2026-10-05", "쿠폰 광고"], "[광고비]");
|
|
|
|
// 광고비 표 — 기타광고비 열, 열 너비 = 내용, 날짜 열 고정
|
|
const p = await browser.newPage({ viewport: { width: 1400, height: 900 } });
|
|
await p.route("**/*", function (r) {
|
|
if (new URL(r.request().url()).pathname.startsWith("/performance/api/")) { r.fulfill({ status: 200, contentType: "application/json", body: "{}" }); return; }
|
|
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: page("perf_ads.html") });
|
|
});
|
|
await p.goto("http://perf.test/performance/ads");
|
|
const heads = await p.$$eval(".perf-main thead th", function (ths) { return ths.map(function (th) { return th.textContent.replace(/[✎\s]+/g, " ").trim(); }); });
|
|
const ai = heads.findIndex(function (h) { return h.indexOf("애터미아자몰") === 0; });
|
|
check("광고비 표 = 애터미아자몰 오른쪽 기타광고비 열", ai > 0 && heads[ai + 1].indexOf("기타광고비") === 0, heads);
|
|
const fit = await p.evaluate(function () {
|
|
const t = document.querySelector(".perf-main"), wrap = t.closest(".perf-table-wrap");
|
|
return { autofit: t.classList.contains("perf-autofit"), tableW: Math.round(t.getBoundingClientRect().width), wrapW: wrap.clientWidth,
|
|
labelW: Math.round(t.querySelector("thead th.perf-th-label").getBoundingClientRect().width) };
|
|
});
|
|
check("광고비 표 열 너비 = 내용 길이(날짜 열 210px 고정 아님)", fit.autofit && fit.labelW < 200, fit);
|
|
const sticky = await p.evaluate(function () {
|
|
const wrap = document.querySelector(".perf-table-wrap"), lab = document.querySelector(".perf-row-day .perf-td-label");
|
|
wrap.style.width = "420px";
|
|
wrap.scrollLeft = 400;
|
|
const x = lab.getBoundingClientRect().left, wx = wrap.getBoundingClientRect().left;
|
|
const under = document.elementFromPoint(x + 4, lab.getBoundingClientRect().top + 4);
|
|
return { scrolled: wrap.scrollLeft, x: x, wx: wx, top: under === lab || lab.contains(under) };
|
|
});
|
|
check("광고비 표 가로 스크롤해도 날짜 열 고정", sticky.scrolled > 0 && Math.abs(sticky.x - sticky.wx) < 2 && sticky.top, sticky);
|
|
await p.locator(".perf-table-wrap").screenshot({ path: path.join(__dirname, ".out", "perf_ads_sticky.png") });
|
|
await p.evaluate(function () { const w = document.querySelector(".perf-table-wrap"); w.style.width = ""; w.scrollLeft = 0; });
|
|
await p.hover('[data-manual-code="coupang_wing"][data-date="2026-10-05"]');
|
|
await p.screenshot({ path: path.join(__dirname, ".out", "perf_ads_memo.png"), clip: { x: 0, y: 200, width: 1400, height: 500 } });
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
console.log(fails.length ? "\n" + fails.length + " FAIL" : "\nALL PASS");
|
|
process.exit(fails.length ? 1 : 0);
|
|
})();
|