Files
dbx-main/tests/js/perf_colfold.browser.test.js
T
king 359ff29e95 feat(실적): 열 접기 버튼에 커서 따라다니는 이름 말풍선
버튼 위에 올리면 커서 바로 위에 쇼핑몰(열) 이름 — 글자 크기는 열 제목과 같은 12px 굵게.
머리글 th 의 기본 title 말풍선은 버튼 title="" 로 막음.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 19:58:18 +09:00

106 lines
6.9 KiB
JavaScript

// 실적 일자별 표 열 접기(2026-11-06) — 실제 브라우저(Chromium).
// python tests/js/render_performance.py
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/perf_colfold.browser.test.js
// 머리글 위 버튼(.perf-cfold)으로 열 하나 접기/펴기(날짜 열 빼고) → 26px 띠, 칸 내용 숨김, PUT /api/my-col-fold {kind, cols}.
// 서버가 그린 data-col-fold(그 사람 저장값)로 처음부터 접힘. 수동 열 너비 표에서도 같은 26px. 매출 실적·광고비 둘 다.
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 route(p, file, folded, puts) {
return p.route("**/*", function (r) {
const url = new URL(r.request().url()).pathname;
if (url.startsWith("/static/")) {
const f = path.join(ROOT, "app", url);
if (!fs.existsSync(f)) return r.fulfill({ status: 404, body: "" });
return r.fulfill({ status: 200, contentType: f.endsWith(".css") ? "text/css" : "application/javascript", body: fs.readFileSync(f) });
}
if (url.includes("/api/")) {
if (url.endsWith("/api/my-col-fold")) puts.push(JSON.parse(r.request().postData()));
return r.fulfill({ status: 200, contentType: "application/json", body: "{}" });
}
const html = fs.readFileSync(path.join(__dirname, ".out", file), "utf8")
.replace('data-col-fold="[]"', 'data-col-fold="' + JSON.stringify(folded).replace(/"/g, "&#34;") + '"');
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: html });
});
}
function state(p, col) {
return p.evaluate(function (col) {
const t = document.querySelector("table.perf-main"), th = t.querySelector('thead th[data-col="' + col + '"]');
const i = th.cellIndex, cells = Array.from(t.tBodies[0].rows).map(function (r) { return r.cells[i]; });
const btn = th.querySelector(".perf-cfold");
return { w: Math.round(th.getBoundingClientRect().width), folded: th.classList.contains("is-cfold"),
allCells: cells.every(function (c) { return c.classList.contains("is-cfold"); }),
cellW: Math.round(cells[1].getBoundingClientRect().width), text: cells[1].innerText.trim(),
expanded: btn && btn.getAttribute("aria-expanded"), buttons: t.querySelectorAll(".perf-cfold").length,
labelBtn: !!t.querySelector('th[data-col="label"] .perf-cfold'), heads: t.tHead.rows[0].cells.length };
}, col);
}
(async function () {
const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {});
try {
for (const [file, kind] of [["perf_dash_shell.html", "sales"], ["perf_ads_shell.html", "ads"], ["perf_dash_colw_shell.html", "sales"]]) {
const tag = "[" + file + "] ";
const puts = [];
const ctx = await browser.newContext({ viewport: { width: 1400, height: 800 } });
const p = await ctx.newPage();
await route(p, file, [], puts);
await p.goto("http://perf.test/performance/");
await p.waitForTimeout(150);
const col = await p.evaluate(function () { // 접어 볼 열 = 일 합계 다음 첫 열
return document.querySelector("table.perf-main").tHead.rows[0].cells[2].dataset.col;
});
const s0 = await state(p, col);
check(tag + "날짜 열 빼고 열마다 버튼, 처음엔 펼침", s0.buttons === s0.heads - 1 && !s0.labelBtn && !s0.folded && s0.expanded === "true", s0);
// 말풍선 — 버튼 위에 올리면 커서 바로 위에 열 이름(제목 글자 크기 12px), 커서 따라 움직임, 머리글 기본 말풍선(title) 없음
const bb = await p.locator('thead th[data-col="' + col + '"] .perf-cfold').boundingBox();
await p.mouse.move(bb.x + 4, bb.y + bb.height / 2);
await p.mouse.move(bb.x + bb.width - 4, bb.y + bb.height / 2);
const tip = await p.evaluate(function (col) {
const t = document.querySelector(".perf-cfold-tip"), b = document.querySelector('thead th[data-col="' + col + '"] .perf-cfold');
const head = document.querySelector('thead th[data-col="' + col + '"]');
if (!t) return null;
const r = t.getBoundingClientRect();
return { text: t.textContent, name: head.textContent.replace(/[✎\s]+/g, " ").trim(), size: getComputedStyle(t).fontSize,
headSize: getComputedStyle(head).fontSize, cx: Math.round(r.left + r.width / 2), bottom: Math.round(r.bottom), title: b.getAttribute("title") };
}, col);
const cursorX = Math.round(bb.x + bb.width - 4), cursorY = bb.y + bb.height / 2;
check(tag + "말풍선 = 열 이름, 제목 글자 크기, 커서 위를 따라감", tip && tip.text === tip.name && tip.text !== "" && tip.size === tip.headSize &&
Math.abs(tip.cx - cursorX) <= 1 && tip.bottom < cursorY && tip.title === "", tip);
await p.mouse.move(5, 5);
check(tag + "벗어나면 말풍선 닫힘", (await p.locator(".perf-cfold-tip").count()) === 0);
await p.click('thead th[data-col="' + col + '"] .perf-cfold');
await p.waitForTimeout(100);
const s1 = await state(p, col);
check(tag + "누르면 26px 띠로 접힘(칸 내용 숨김)", s1.folded && s1.allCells && s1.w === 26 && s1.cellW === 26 && s1.text === "" && s1.expanded === "false", s1);
check(tag + "PUT /api/my-col-fold {kind, cols}", puts.length === 1 && puts[0].kind === kind && JSON.stringify(puts[0].cols) === JSON.stringify([col]), puts);
await p.click('thead th[data-col="' + col + '"] .perf-cfold');
await p.waitForTimeout(100);
const s2 = await state(p, col);
check(tag + "다시 누르면 원래 너비로", !s2.folded && Math.abs(s2.w - s0.w) <= 1 && s2.text !== "", { s0: s0, s2: s2 });
check(tag + "펼친 것도 저장(빈 목록)", puts.length === 2 && puts[1].cols.length === 0, puts);
await ctx.close();
// 서버가 그린 저장값(data-col-fold)으로 처음부터 접힘
const ctx2 = await browser.newContext({ viewport: { width: 1400, height: 800 } });
const q = await ctx2.newPage();
await route(q, file, [col, "total"], []);
await q.goto("http://perf.test/performance/");
await q.waitForTimeout(150);
const s3 = await state(q, col), t3 = await state(q, "total");
check(tag + "저장값대로 처음부터 접힘(일 합계 포함)", s3.folded && s3.w === 26 && t3.folded && t3.w === 26, { s3: s3, t3: t3 });
if (file === "perf_dash_shell.html") await q.screenshot({ path: path.join(__dirname, ".out", "perf_colfold.png") });
await ctx2.close();
}
} finally {
await browser.close();
}
console.log(fails.length ? "\n" + fails.length + " FAIL" : "\nALL PASS");
process.exit(fails.length ? 1 : 0);
})();