d9dd03ecc8
실적 설정 "보기 설정"에 표 열 너비 [자동(글자 길이)]·[수동 조절] 추가(쿠키 perf_colw). 수동이면 매출 실적·광고비 일자별 표 머리글 오른쪽 경계를 끌어 열 너비를 바꾸고, 바꾼 너비는 localStorage(perf_colw_sales/ads)에 유지. 경계 두 번 클릭 = 그 열만 자동, 설정 [조절한 너비 초기화]로 전부 되돌림. 그룹 접기·펴기 애니메이션과 연동. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
169 lines
11 KiB
JavaScript
169 lines
11 KiB
JavaScript
// 실적 일자별 표 열 너비 자동/수동(2026-10-27) — 실제 브라우저(Chromium).
|
|
// python tests/js/render_performance.py
|
|
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/perf_colw.browser.test.js
|
|
// 자동(기본) = 예전 그대로(글자 길이, 손잡이 없음). 수동(쿠키 perf_colw=manual → 표 perf-colw-manual) = 처음엔 자동 너비 그대로 고정,
|
|
// 머리글 오른쪽 경계를 끌면 그 열만 바뀌고 새로고침해도 유지(localStorage perf_colw_sales / _ads 따로), 두 번 누르면 자동 너비,
|
|
// 그룹 접기·펴기 때 열 너비도 함께, 머리글 고정(스크롤)·날짜 열 고정 그대로. 설정 "보기 설정"에서 고르면 쿠키, [초기화]는 저장 너비 지움.
|
|
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) {
|
|
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/")) 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") });
|
|
});
|
|
}
|
|
function widths(p) {
|
|
return p.evaluate(function () {
|
|
const t = document.querySelector("table.perf-main"), o = {};
|
|
t.tHead.rows[0].querySelectorAll("th").forEach(function (th) { o[th.dataset.col] = Math.round(th.getBoundingClientRect().width); });
|
|
return { cols: o, table: Math.round(t.getBoundingClientRect().width), fixed: t.classList.contains("is-colw-fixed"),
|
|
grips: t.querySelectorAll(".perf-colw-grip").length };
|
|
});
|
|
}
|
|
async function drag(p, col, dx) {
|
|
const box = await p.locator('th[data-col="' + col + '"] > .perf-colw-grip').boundingBox();
|
|
const x = box.x + box.width / 2, y = box.y + box.height / 2;
|
|
await p.mouse.move(x, y);
|
|
await p.mouse.down();
|
|
await p.mouse.move(x + dx / 2, y, { steps: 3 });
|
|
await p.mouse.move(x + dx, y, { steps: 3 });
|
|
await p.mouse.up();
|
|
}
|
|
|
|
(async function () {
|
|
const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {});
|
|
try {
|
|
// ── 자동(기본) — 예전 그대로 ──
|
|
const actx = await browser.newContext({ viewport: { width: 1400, height: 800 } });
|
|
const ap = await actx.newPage();
|
|
await route(ap, "perf_dash_shell.html");
|
|
await ap.goto("http://perf.test/performance/");
|
|
const a0 = await widths(ap);
|
|
check("자동 = 고정 안 함·손잡이 없음", !a0.fixed && a0.grips === 0, a0);
|
|
await actx.close();
|
|
|
|
// ── 수동 — 매출 실적(그룹 있음) ──
|
|
const ctx = await browser.newContext({ viewport: { width: 1400, height: 800 } });
|
|
const p = await ctx.newPage();
|
|
await route(p, "perf_dash_colw_shell.html");
|
|
await p.goto("http://perf.test/performance/");
|
|
await p.waitForTimeout(150);
|
|
const w0 = await widths(p);
|
|
const fits = await p.evaluate(function () {
|
|
return Array.from(document.querySelectorAll("table.perf-main th, table.perf-main td")).filter(function (c) {
|
|
return c.offsetParent && c.scrollWidth > c.clientWidth + 1;
|
|
}).length;
|
|
});
|
|
const sum0 = Object.keys(w0.cols).reduce(function (s, k) { return s + w0.cols[k]; }, 0);
|
|
check("수동 = 고정 표 + 열마다 손잡이, 처음엔 글자가 잘리지 않는 자동 너비", w0.fixed && w0.grips === Object.keys(w0.cols).length && fits === 0, { w0: w0, fits: fits });
|
|
check("표 너비 = 열 너비 합", Math.abs(w0.table - sum0) <= 2, { table: w0.table, sum: sum0 });
|
|
await drag(p, "naver", 70);
|
|
const w1 = await widths(p);
|
|
check("네이버 경계 오른쪽으로 70px 끌기 → 그 열만 +70", Math.abs(w1.cols.naver - w0.cols.naver - 70) <= 2 && w1.cols.cafe24 === w0.cols.cafe24 && Math.abs(w1.table - w0.table - 70) <= 2, { w0: w0.cols, w1: w1.cols });
|
|
await drag(p, "cafe24", -400);
|
|
const w2 = await widths(p);
|
|
check("너무 좁히면 최소 36px", w2.cols.cafe24 >= 35 && w2.cols.cafe24 <= 37, w2.cols.cafe24);
|
|
const clip = await p.evaluate(function () {
|
|
const th = document.querySelector('th[data-col="cafe24"]');
|
|
const td = document.querySelector("tr.perf-row-total").children[th.cellIndex];
|
|
return { ov: getComputedStyle(td).overflow, w: Math.round(td.getBoundingClientRect().width) };
|
|
});
|
|
check("좁힌 열 칸은 넘치는 글자를 자름(너비 그대로)", clip.ov === "hidden" && clip.w <= 37, clip);
|
|
const clicked = await p.evaluate(function () { return location.href; });
|
|
await p.reload();
|
|
await p.waitForTimeout(150);
|
|
const w3 = await widths(p);
|
|
check("새로고침해도 조절한 너비 유지", Math.abs(w3.cols.naver - w1.cols.naver) <= 1 && Math.abs(w3.cols.cafe24 - w2.cols.cafe24) <= 1 && w3.cols.total === w0.cols.total, { w3: w3.cols });
|
|
const stored = await p.evaluate(function () { return JSON.parse(localStorage.getItem("perf_colw_sales") || "{}"); });
|
|
check("localStorage perf_colw_sales 에 열별 너비", stored.naver > 0 && stored.cafe24 === 36 && !("total" in stored), stored);
|
|
await p.dblclick('th[data-col="cafe24"] > .perf-colw-grip');
|
|
const w4 = await widths(p);
|
|
check("경계 두 번 누르면 그 열만 자동 너비로", Math.abs(w4.cols.cafe24 - w0.cols.cafe24) <= 1 && Math.abs(w4.cols.naver - w1.cols.naver) <= 1 && clicked === (await p.evaluate(function () { return location.href; })), w4.cols);
|
|
// 그룹 접기·펴기 — 열 너비도 함께, 끝나면 표 너비 = 보이는 열 합
|
|
const childW = w4.cols.custom_a;
|
|
await p.click('[data-group-toggle="group_off"]');
|
|
await p.waitForTimeout(110);
|
|
const mid = await p.evaluate(function () { return Math.round(document.querySelector('th[data-col="custom_a"]').getBoundingClientRect().width); });
|
|
await p.waitForTimeout(400);
|
|
const w5 = await widths(p);
|
|
const vis5 = Object.keys(w5.cols).reduce(function (s, k) { return s + w5.cols[k]; }, 0);
|
|
check("그룹 접는 중 열이 줄고, 끝나면 숨김·표 너비 = 보이는 열 합", mid > 0 && mid < childW && w5.cols.custom_a === 0 && Math.abs(w5.table - vis5) <= 2, { mid: mid, childW: childW, w5: w5 });
|
|
await p.click('[data-group-toggle="group_off"]');
|
|
await p.waitForTimeout(450);
|
|
const w6 = await widths(p);
|
|
check("다시 펴면 원래 너비로", Math.abs(w6.cols.custom_a - childW) <= 1 && Math.abs(w6.table - w4.table) <= 2, { w6: w6, w4: w4.table });
|
|
// 그룹 단추 클릭은 그대로(손잡이 클릭이 단추를 누르지 않음)
|
|
const exp = await p.getAttribute('[data-group-toggle="group_off"]', "aria-expanded");
|
|
check("그룹 단추 상태 정상(펼침)", exp === "true", exp);
|
|
// 머리글 스크롤 고정 그대로
|
|
const sticky = await p.evaluate(function () {
|
|
const page = document.querySelector(".erp-page"), th = document.querySelector('th[data-col="naver"]');
|
|
page.scrollTop = 400;
|
|
return new Promise(function (res) {
|
|
requestAnimationFrame(function () { requestAnimationFrame(function () {
|
|
res({ top: th.getBoundingClientRect().top, pageTop: page.getBoundingClientRect().top, w: Math.round(th.getBoundingClientRect().width) });
|
|
}); });
|
|
});
|
|
});
|
|
check("페이지 스크롤해도 제목 행 화면 위 고정(너비 그대로)", Math.abs(sticky.top - sticky.pageTop) <= 2 && Math.abs(sticky.w - w1.cols.naver) <= 1, sticky);
|
|
await p.evaluate(function () { document.querySelector(".erp-page").scrollTop = 0; });
|
|
await p.locator(".perf-main-wrap").screenshot({ path: path.join(__dirname, ".out", "perf_colw_dash.png") });
|
|
|
|
// ── 수동 — 광고비(같은 브라우저, 따로 기억) ──
|
|
const q = await ctx.newPage();
|
|
await route(q, "perf_ads_colw_shell.html");
|
|
await q.goto("http://perf.test/performance/ads");
|
|
await q.waitForTimeout(150);
|
|
const b0 = await widths(q);
|
|
const col = Object.keys(b0.cols)[2];
|
|
await drag(q, col, 50);
|
|
await q.reload();
|
|
await q.waitForTimeout(150);
|
|
const b1 = await widths(q);
|
|
const both = await q.evaluate(function () {
|
|
return { ads: JSON.parse(localStorage.getItem("perf_colw_ads") || "{}"), sales: JSON.parse(localStorage.getItem("perf_colw_sales") || "{}") };
|
|
});
|
|
check("광고비 표도 조절·유지(perf_colw_ads 따로)", b0.fixed && Math.abs(b1.cols[col] - b0.cols[col] - 50) <= 2 && both.ads[col] > 0 && !(col in both.sales), { col: col, b0: b0.cols[col], b1: b1.cols[col], both: both });
|
|
await q.locator(".perf-main-wrap").screenshot({ path: path.join(__dirname, ".out", "perf_colw_ads.png") });
|
|
|
|
// ── 설정 — 보기 설정 ──
|
|
const s = await ctx.newPage();
|
|
s.on("dialog", function (d) { d.accept(); });
|
|
await route(s, "perf_settings.html");
|
|
await s.goto("http://perf.test/performance/settings");
|
|
const st0 = await s.evaluate(function () {
|
|
return { active: document.querySelector("#perf-view-opts [data-colw].is-active").dataset.colw, reset: document.getElementById("perf-colw-reset").hidden };
|
|
});
|
|
check("설정 기본 = 자동, [초기화] 숨김", st0.active === "auto" && st0.reset, st0);
|
|
await s.click('#perf-view-opts [data-colw="manual"]');
|
|
const st1 = await s.evaluate(function () {
|
|
return { cookie: document.cookie, reset: document.getElementById("perf-colw-reset").hidden, help: document.getElementById("perf-colw-help").textContent };
|
|
});
|
|
check("수동 고르면 쿠키 perf_colw=manual·[초기화] 보임·안내", /perf_colw=manual/.test(st1.cookie) && !st1.reset && /경계/.test(st1.help), st1);
|
|
await s.click("#perf-colw-reset");
|
|
await s.waitForTimeout(100);
|
|
const st2 = await s.evaluate(function () { return [localStorage.getItem("perf_colw_sales"), localStorage.getItem("perf_colw_ads")]; });
|
|
check("[조절한 너비 초기화] = 매출·광고비 저장 너비 지움", st2[0] === null && st2[1] === null, st2);
|
|
await s.locator("#perf-view-opts").screenshot({ path: path.join(__dirname, ".out", "perf_colw_settings.png") });
|
|
await s.click('#perf-view-opts [data-colw="auto"]');
|
|
check("자동 고르면 쿠키 perf_colw=auto", /perf_colw=auto/.test(await s.evaluate(function () { return document.cookie; })));
|
|
await ctx.close();
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
console.log(fails.length ? "\n" + fails.length + " FAIL" : "\nALL PASS");
|
|
process.exit(fails.length ? 1 : 0);
|
|
})();
|