3d14ff4a85
- 매출 실적·광고비 탭 오늘·이번주 버튼 삭제, 매출 실적 기본 기간 = 이번달 - 일자별 표 상자(.perf-main-wrap)를 화면 높이로 묶어 상자 안 세로 스크롤 — 제목 행 + 맨 위 기간 합계 행 sticky (합계 행 top = 제목 행 높이 --perf-head-h, stickyHead 가 ResizeObserver 로 잼), 날짜 열 가로 고정은 그대로 - 테스트: perf_sticky.browser.test.js(실제 브라우저), test_ad_spend 빠른 선택 순서 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
5.2 KiB
JavaScript
87 lines
5.2 KiB
JavaScript
// 실적 — 기간 빠른 선택(이번달·올해만, 기본 이번달) · 일자별 표 스크롤 고정(2026-10-26) — 실제 브라우저(Chromium).
|
|
// python tests/js/render_performance.py
|
|
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/perf_sticky.browser.test.js
|
|
// 매출 실적(이번달)·광고비(이번달): 표 상자 안에서 세로 스크롤하면 제목 행은 상자 맨 위, 기간 합계 행은 제목 행 바로 아래에 붙어 있고
|
|
// 날짜 칸은 가로 스크롤해도 왼쪽 고정(예전 그대로). 오늘·이번주 버튼은 없다.
|
|
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 stickyFlow(browser, file, label) {
|
|
const ctx = await browser.newContext({ viewport: { width: 900, height: 600 } });
|
|
const p = await ctx.newPage();
|
|
await p.route("**/*", function (r) {
|
|
const url = new URL(r.request().url()).pathname;
|
|
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/");
|
|
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 = async function () {
|
|
return p.evaluate(function () {
|
|
const 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 totalCell = total.querySelector("td");
|
|
const label = total.querySelector(".perf-td-label");
|
|
const w = wrap.getBoundingClientRect();
|
|
return { wrapTop: w.top, wrapLeft: w.left, scrollH: wrap.scrollHeight, clientH: wrap.clientHeight,
|
|
headTop: head.getBoundingClientRect().top, headBottom: head.getBoundingClientRect().bottom,
|
|
totalTop: totalCell.getBoundingClientRect().top, labelLeft: label.getBoundingClientRect().left,
|
|
totalText: label.textContent.trim(),
|
|
// 기간 합계 행 위에 다른 줄이 겹쳐 보이지 않는가 — 합계 칸 가운데를 찍으면 합계 행 칸이 나와야 한다
|
|
hit: (function () {
|
|
const r = totalCell.getBoundingClientRect();
|
|
const el = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2);
|
|
return !!el && !!el.closest("tr.perf-row-total");
|
|
})(),
|
|
labelHit: (function () {
|
|
const r = label.getBoundingClientRect();
|
|
const el = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2);
|
|
return !!el && !!el.closest("tr.perf-row-total");
|
|
})() };
|
|
});
|
|
};
|
|
const g0 = await geo();
|
|
check(label + " 표 상자가 세로로 스크롤된다(화면 높이로 묶음)", g0.scrollH > g0.clientH + 100, g0);
|
|
check(label + " 맨 위 행 = 기간 합계", g0.totalText === "기간 합계", g0.totalText);
|
|
await p.evaluate(function () { document.querySelector(".perf-main-wrap").scrollTop = 400; });
|
|
await p.waitForTimeout(50);
|
|
const g1 = await geo();
|
|
check(label + " 세로 스크롤 뒤 제목 행 = 상자 맨 위", Math.abs(g1.headTop - g1.wrapTop) <= 1.5, g1);
|
|
check(label + " 세로 스크롤 뒤 기간 합계 행 = 제목 행 바로 아래", Math.abs(g1.totalTop - g1.headBottom) <= 1.5 && g1.hit, g1);
|
|
await p.evaluate(function () { document.querySelector(".perf-main-wrap").scrollLeft = 300; });
|
|
await p.waitForTimeout(50);
|
|
const g2 = await geo();
|
|
check(label + " 가로 스크롤해도 기간 합계 날짜 칸은 왼쪽 고정", Math.abs(g2.labelLeft - g2.wrapLeft) <= 1.5 && g2.labelHit, g2);
|
|
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_month.html", "[매출 실적]");
|
|
await stickyFlow(browser, "perf_ads.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); });
|