Files
dbx-main/tests/js/perf_sticky.browser.test.js
T
king de5a8a3d0a fix(performance): 일자별 표 제목·기간 합계 행 — 페이지 스크롤에 고정(매출·광고비), 스크롤 막대 배경 투명
- 10-26 판은 표 상자 안 세로 스크롤이라 진짜 ERP 셸에서 상자 아래가 화면 밖에 잘리고 휠이 페이지로 안 넘어갔다
- 표 상자 세로 스크롤 없앰 → stickyHead 가 .erp-page 스크롤마다 제목 행·기간 합계 행 칸을 translateY 로 내림(표 끝에서 멈춤),
  내려온 동안 제목 칸이 아래 1px 선을 직접 그림(border-collapse 선 틈으로 뒤 줄이 비침 방지)
- 스크롤 막대 트랙 투명(scrollbar-color, 표 상자·실적 화면)
- perf_sticky.browser.test.js 를 진짜 erp_base.html 셸 렌더(perf_*_shell.html)로 — 휠 스크롤·가로 고정·표 끝 멈춤

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

102 lines
6.7 KiB
JavaScript

// 실적 — 기간 빠른 선택(이번달·올해만, 기본 이번달) · 일자별 표 제목·기간 합계 행 스크롤 고정(2026-10-26, 10-27 다시) — 실제 브라우저(Chromium).
// python tests/js/render_performance.py
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/perf_sticky.browser.test.js
// 진짜 ERP 셸(erp_base.html — 페이지 스크롤 상자 = .erp-page)로 렌더한 매출 실적·광고비(이번달): 표 위에서 마우스 휠 → 페이지가 스크롤되고
// (표 상자는 세로 스크롤 없음 — 예전엔 상자 안에서만 돌아 상자 아래가 화면 밖에 잘렸다) 제목 행은 화면 위, 기간 합계 행은 그 바로 아래,
// 표 끝을 넘으면 같이 올라감. 날짜 칸 가로 고정 그대로, 스크롤 막대 배경 투명. 오늘·이번주 버튼 없음.
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); }
}
async function stickyFlow(browser, file, label) {
const ctx = await browser.newContext({ viewport: { width: 1300, height: 760 } });
const p = await ctx.newPage();
await 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/")) return r.fulfill({ status: 200, contentType: "application/json", body: "{}" });
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: fs.readFileSync(path.join(__dirname, ".out", file), "utf8") });
});
await p.goto("http://perf.test/performance/");
await p.waitForTimeout(150);
const quick = await p.evaluate(function () {
return Array.from(document.querySelectorAll(".perf-quick .perf-seg")).map(function (n) { return n.textContent.trim(); });
});
check(label + " 빠른 선택 = 이번달·올해·직접선택(오늘·이번주 없음)", JSON.stringify(quick) === '["이번달","올해","직접선택"]', quick);
const geo = function () {
return p.evaluate(function () {
const page = document.querySelector(".erp-page"), wrap = document.querySelector(".perf-main-wrap");
const head = wrap.querySelector("thead th:nth-child(2)");
const total = wrap.querySelector("tbody tr.perf-row-total:first-child");
const cell = total.querySelector("td"), lab = total.querySelector(".perf-td-label");
const hit = function (el) {
const r = el.getBoundingClientRect();
const x = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2);
return !!x && !!x.closest("tr.perf-row-total");
};
const table = wrap.querySelector("table").getBoundingClientRect();
return { pageTop: page.getBoundingClientRect().top, pageScroll: page.scrollTop,
wrapScrollH: wrap.scrollHeight, wrapClientH: wrap.clientHeight, wrapLeft: wrap.getBoundingClientRect().left,
tableTop: table.top, tableBottom: table.bottom,
headTop: head.getBoundingClientRect().top, headBottom: head.getBoundingClientRect().bottom,
totalTop: cell.getBoundingClientRect().top, totalBottom: cell.getBoundingClientRect().bottom,
labelLeft: lab.getBoundingClientRect().left, labelText: lab.textContent.trim(), hitCell: hit(cell), hitLabel: hit(lab),
track: getComputedStyle(wrap).scrollbarColor, pageTrack: getComputedStyle(page).scrollbarColor };
});
};
const g0 = await geo();
check(label + " 맨 위 행 = 기간 합계, 표 상자 세로 스크롤 없음", g0.labelText === "기간 합계" && g0.wrapScrollH <= g0.wrapClientH + 1, g0);
check(label + " 처음엔 제자리(옮기지 않음)", Math.abs(g0.totalTop - g0.headBottom) <= 1 && g0.headTop > g0.pageTop + 50, g0);
check(label + " 스크롤 막대 배경 투명(표 상자·페이지)", / (transparent|rgba\(0, 0, 0, 0\))$/.test(g0.track) && / (transparent|rgba\(0, 0, 0, 0\))$/.test(g0.pageTrack), [g0.track, g0.pageTrack]);
// 표 위에서 휠 → 페이지가 스크롤된다
const box = await p.locator(".perf-main-wrap").boundingBox();
await p.mouse.move(box.x + 300, box.y + 60);
await p.mouse.wheel(0, 500);
await p.waitForTimeout(200);
const g1 = await geo();
check(label + " 표 위 휠 → 페이지 스크롤", g1.pageScroll > 300, g1.pageScroll);
check(label + " 스크롤 뒤 제목 행 = 화면(스크롤 상자) 맨 위", g1.tableTop < g1.pageTop && Math.abs(g1.headTop - g1.pageTop) <= 1, g1);
check(label + " 스크롤 뒤 기간 합계 행 = 제목 행 바로 아래, 다른 줄에 안 가려짐",
Math.abs(g1.totalTop - g1.headBottom) <= 1 && g1.hitCell && g1.hitLabel, g1);
// 가로 스크롤 — 날짜 칸은 왼쪽 고정(내려온 합계 행도)
await p.evaluate(function () { document.querySelector(".perf-main-wrap").scrollLeft = 400; });
await p.waitForTimeout(80);
const g2 = await geo();
check(label + " 가로 스크롤해도 기간 합계 날짜 칸은 왼쪽 고정", Math.abs(g2.labelLeft - g2.wrapLeft) <= 1.5 && g2.hitLabel &&
Math.abs(g2.headTop - g2.pageTop) <= 1, g2);
// 표 끝을 넘어가면 같이 올라간다(표 밖으로 나가지 않음)
await p.evaluate(function () { const pg = document.querySelector(".erp-page"); pg.scrollTop = pg.scrollHeight; });
await p.waitForTimeout(120);
const g3 = await geo();
check(label + " 표 끝을 지나면 제목·합계 행도 표 안(표 끝에서 멈춤)",
g3.totalBottom <= g3.tableBottom + 1 && g3.headTop >= g3.tableTop - 1 && g3.headTop < g3.pageTop, g3);
// 다시 맨 위 — 제자리
await p.evaluate(function () { document.querySelector(".erp-page").scrollTop = 0; });
await p.waitForTimeout(120);
const g4 = await geo();
check(label + " 맨 위로 돌아오면 제자리", Math.abs(g4.headTop - g0.headTop) <= 1 && Math.abs(g4.totalTop - g4.headBottom) <= 1, g4);
await ctx.close();
}
(async function () {
const exe = process.env.PJ_TEST_BROWSER;
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
try {
await stickyFlow(browser, "perf_dash_shell.html", "[매출 실적]");
await stickyFlow(browser, "perf_ads_shell.html", "[광고비]");
} finally {
await browser.close();
}
if (fails.length) { console.log("\n" + fails.length + " FAILED"); process.exit(1); }
console.log("\nALL PASS");
})().catch(function (e) { console.error(e); process.exit(1); });