Files
dbx-main/tests/js/perf_sticky.browser.test.js
T

143 lines
10 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);
// 일 합계 열 — 날짜 열 바로 오른쪽에 함께 고정(제목·기간 합계·일 행 모두), 위에 다른 칸이 안 겹침(2026-11-02)
const tg = await p.evaluate(function () {
const box = function (s) { return document.querySelector(s).getBoundingClientRect(); };
const hit = function (s) { const r = box(s), n = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); return !!n.closest(s); };
const label = box(".perf-main thead th.perf-th-label");
const rows = [".perf-main thead th.perf-th-total", ".perf-main tbody tr.perf-row-total:first-child > .perf-td-total", ".perf-main tbody tr.perf-row-day > .perf-td-total"];
return { labelRight: label.right, lefts: rows.map(function (s) { return box(s).left; }), hits: rows.slice(0, 2).map(hit), scrolled: document.querySelector(".perf-main-wrap").scrollLeft };
});
check(label + " 가로 스크롤해도 일 합계 열은 날짜 열 바로 옆 고정", tg.scrolled > 0 && tg.lefts.every(function (x) { return Math.abs(x - tg.labelRight) <= 1.5; }) && tg.hits.every(Boolean), tg);
// 기간 이동 — 날짜 바로 좌우 화살표 SVG(글자 높이), 글자 없음
const nv = await p.evaluate(function () {
const a = document.querySelectorAll(".perf-nav-btn"), lb = document.querySelector(".perf-nav-label").getBoundingClientRect();
const svg = a[0].querySelector("svg");
return { text: a[0].textContent.trim() + a[1].textContent.trim(), h: svg.getBoundingClientRect().height, size: parseFloat(getComputedStyle(document.querySelector(".perf-nav-label")).fontSize),
stroke: getComputedStyle(svg).stroke, gapL: lb.left - a[0].getBoundingClientRect().right, gapR: a[1].getBoundingClientRect().left - lb.right };
});
check(label + " 기간 이동 = 날짜 바로 옆 글자 높이 화살표(진한 회색)", nv.text === "" && Math.abs(nv.h - nv.size) <= 1 && nv.gapL <= 3 && nv.gapR <= 3 && nv.stroke === "rgb(68, 68, 68)", nv);
// 표 끝을 넘어가면 같이 올라간다(표 밖으로 나가지 않음)
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);
// 수기 입력 뒤 새로고침 — 세로·가로 스크롤 위치 그대로, 제목 행도 다시 화면 위(2026-11-02)
const pos = function () {
return p.evaluate(function () {
const wrap = document.querySelector(".perf-main-wrap"), page = document.querySelector(".erp-page");
return { top: page.scrollTop, left: wrap.scrollLeft, headTop: document.querySelector(".perf-main thead th").getBoundingClientRect().top, pageTop: page.getBoundingClientRect().top };
});
};
await p.evaluate(function () { document.querySelector(".erp-page").scrollTop = 500; document.querySelector(".perf-main-wrap").scrollLeft = 120; });
await p.waitForTimeout(80);
const before = await pos();
await Promise.all([p.waitForNavigation(), p.evaluate(function () {
document.querySelector('td.is-manual-cell[data-date="2026-10-20"]').click();
const input = document.querySelector(".perf-manual-input");
input.value = "5000";
input.blur();
})]);
await p.waitForTimeout(150);
const after = await pos();
check(label + " 수기 입력 뒤 새로고침해도 스크롤 위치 그대로", before.top === 500 && before.left > 0 && after.top === before.top && after.left === before.left &&
Math.abs(after.headTop - after.pageTop) <= 1, { before: before, after: after });
// 새로고침이 아닌 이동(같은 주소로 다시 들어옴)은 맨 위부터
await p.goto("http://perf.test/performance/");
await p.waitForTimeout(150);
check(label + " 새로 들어오면 맨 위부터", (await pos()).top === 0);
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); });