feat(실적): 일자별 표 열 접기 — 사람마다 저장
매출 실적·광고비 일자별 표 머리글 위 버튼으로 열 하나씩 접기/펴기(날짜 열 제외). 접은 열은 26px 띠, 로그인한 사람 본인에게만 적용 — PUT /api/my-col-fold → perf_settings col_fold:<이메일 sha1> (마이그레이션 없음, 011 테이블 재사용). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
// 실적 일자별 표 열 접기(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, """) + '"');
|
||||
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);
|
||||
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);
|
||||
})();
|
||||
Reference in New Issue
Block a user