// 실적 쇼핑몰 그룹·드래그 순서(2026-10-22) — 실제 브라우저(Chromium). // python tests/js/render_performance.py // NODE_PATH= PJ_TEST_BROWSER= node tests/js/perf_groups.browser.test.js // 매출 실적: 그룹 열 = 하위 합계, ⊟ 누르면 하위 열이 애니메이션으로 접히고(⊞) 새로고침해도 기억(2026-10-22 단추·애니메이션). // 열 너비 = 내용 길이(표가 100% 로 늘지 않음), 날짜 열은 가로 스크롤해도 고정, 그룹·하위 열 구분 색·묶음 선. // 설정: ⠿ 를 끌어 놓으면 화면 순서 그대로 PUT /api/marketplace-order — 그룹은 하위와 함께, 하위는 그룹 안에서만. 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(//, function () { return ""; }) .replace(/"; }); } (async function () { const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {}); try { // ── 매출 실적 — 그룹 열 접기/펴기 ── const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 } }); const p = await ctx.newPage(); await p.route("**/*", function (r) { r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: page("perf_dash_groups.html") }); }); await p.goto("http://perf.test/performance/"); const heads = function () { return p.evaluate(function () { return Array.from(document.querySelectorAll(".perf-main thead th")).filter(function (th) { return th.offsetParent !== null; }) .map(function (th) { return th.textContent.replace(/\s+/g, " ").trim(); }); }); }; const h0 = await heads(); check("그룹 열이 하위 열 바로 앞", JSON.stringify(h0.slice(1, 9)) === JSON.stringify(["일 합계", "카페24(전체)", "카페24(실적)", "네이버", "오프라인", "매장A ✎", "매장B ✎", "행사 ✎"]), h0); const expanded = function () { return p.getAttribute('[data-group-toggle="group_off"]', "aria-expanded"); }; // 열 너비 = 내용 길이 — 표가 화면보다 좁으면 늘이지 않는다, 각 열은 그 열의 가장 긴 글자 + 여백 정도 const fit = await p.evaluate(function () { const t = document.querySelector(".perf-main"), wrap = t.closest(".perf-table-wrap"); const ths = Array.from(t.querySelectorAll("thead th")).filter(function (th) { return th.offsetParent !== null; }); const slack = ths.map(function (th) { const cells = Array.from(t.querySelectorAll("tbody tr")).map(function (tr) { return tr.children[th.cellIndex]; }).concat([th]); const widest = Math.max.apply(null, cells.map(function (c) { const r = document.createRange(); r.selectNodeContents(c); return r.getBoundingClientRect().width; })); return Math.round(th.getBoundingClientRect().width - widest); }); return { tableW: Math.round(t.getBoundingClientRect().width), wrapW: wrap.clientWidth, maxSlack: Math.max.apply(null, slack), slack: slack }; }); // 날짜 열은 "오늘" 표시(::after — 글자 범위 재기에 안 잡힘)만큼 더 넓다 → 쇼핑몰·합계 열만 엄격히(여유 = 좌우 여백 16px) check("열 너비 = 내용 길이(표가 늘지 않고, 칸 여유는 여백 정도)", fit.tableW < fit.wrapW && Math.max.apply(null, fit.slack.slice(1)) <= 20, fit); const grp = await p.evaluate(function () { const cs = function (sel) { const e = document.querySelector(sel); const c = getComputedStyle(e); return { bg: c.backgroundColor, sh: c.boxShadow, w: c.fontWeight }; }; const btn = document.querySelector('[data-group-toggle="group_off"]').getBoundingClientRect(); return { head: cs('th[data-group-head="group_off"]'), child: cs('th[data-group-child="group_off"]'), last: cs('th.perf-th-child.is-glast'), btn: [Math.round(btn.width), Math.round(btn.height)], cell: cs('td[data-group-cell="group_off"]') }; }); check("그룹 머리(진한 보라·굵게·왼쪽 선) ≠ 하위 머리(옅은 보라·위 띠), 마지막 하위 = 오른쪽 선", grp.head.bg !== grp.child.bg && Number(grp.head.w) >= 700 && /inset/.test(grp.head.sh) && /inset/.test(grp.child.sh) && /-2px/.test(grp.last.sh) && /2px/.test(grp.cell.sh), grp); check("접기 단추 22px(예전 15px 글자)", grp.btn[0] >= 20 && grp.btn[1] >= 20 && (await expanded()) === "true", grp.btn); const g5 = await p.evaluate(function () { const tr = document.querySelector('td[data-manual-code="custom_a"][data-date="2026-10-05"]').closest("tr"); return tr.querySelector('[data-group-cell="group_off"] .v-gross').textContent.trim(); }); check("그룹 칸 = 하위 합계(30,000 + 12,000)", g5 === "42,000", g5); const wBefore = await p.evaluate(function () { return document.querySelector('th[data-group-child="group_off"]').getBoundingClientRect().width; }); await p.click('[data-group-toggle="group_off"]'); await p.waitForTimeout(110); // 애니메이션 중간 — 열이 줄어드는 중(아직 숨지 않음) const mid = await p.evaluate(function () { const th = document.querySelector('th[data-group-child="group_off"]'); return { w: th.getBoundingClientRect().width, anim: th.classList.contains("is-ganim"), shown: th.offsetParent !== null }; }); check("접는 중 = 열이 점점 줄어듦(애니메이션)", mid.anim && mid.shown && mid.w > 0 && mid.w < wBefore, { mid: mid, wBefore: wBefore }); await p.waitForTimeout(400); const h1 = await heads(); const hiddenTd = await p.evaluate(function () { return Array.from(document.querySelectorAll('td[data-group-child="group_off"]')).every(function (td) { return td.offsetParent === null; }); }); check("⊟ 누르면 하위 열(머리글·칸) 숨김, 단추 = 펴기(⊞)", h1.indexOf("매장A ✎") < 0 && (await expanded()) === "false" && hiddenTd && h1.indexOf("행사 ✎") >= 0, h1); const closed = await p.evaluate(function () { return getComputedStyle(document.querySelector('th[data-group-head="group_off"]')).boxShadow; }); check("접히면 그룹 열이 오른쪽 묶음 선도", /-2px/.test(closed), closed); await p.reload(); const h2 = await heads(); check("접은 상태 새로고침 후에도 기억", h2.indexOf("매장A ✎") < 0 && (await expanded()) === "false", h2); await p.click('[data-group-toggle="group_off"]'); await p.waitForTimeout(110); const mid2 = await p.evaluate(function () { const th = document.querySelector('th[data-group-child="group_off"]'); return { w: th.getBoundingClientRect().width, anim: th.classList.contains("is-ganim") }; }); await p.waitForTimeout(400); const wAfter = await p.evaluate(function () { return document.querySelector('th[data-group-child="group_off"]').getBoundingClientRect().width; }); check("다시 누르면 펼침(점점 넓어져 원래 너비로)", (await heads()).indexOf("매장B ✎") >= 0 && mid2.anim && mid2.w < wAfter - 2 && Math.abs(wAfter - wBefore) < 2, { mid2: mid2, wAfter: wAfter, wBefore: wBefore }); // 빠르게 두 번 — 마지막 상태(펼침)로 끝난다 await p.click('[data-group-toggle="group_off"]'); await p.click('[data-group-toggle="group_off"]'); await p.waitForTimeout(450); check("빠르게 두 번 눌러도 마지막 상태(펼침)", (await heads()).indexOf("매장A ✎") >= 0 && (await expanded()) === "true"); // 날짜 열 고정 — 좁은 화면에서 가로 스크롤해도 날짜 칸이 왼쪽에 그대로 const sticky = await p.evaluate(function () { const wrap = document.querySelector(".perf-table-wrap"), lab = document.querySelector(".perf-row-day .perf-td-label"); wrap.style.width = "320px"; // 테스트 표는 열이 적어 넓은 화면에선 스크롤이 안 생긴다 — 좁은 화면 흉내 const x0 = lab.getBoundingClientRect().left; wrap.scrollLeft = 300; const x1 = lab.getBoundingClientRect().left, wrapX = wrap.getBoundingClientRect().left; const under = document.elementFromPoint(x1 + 5, lab.getBoundingClientRect().top + 5); return { scrolled: wrap.scrollLeft, x0: x0, x1: x1, wrapX: wrapX, top: under === lab || lab.contains(under) }; }); check("가로 스크롤해도 날짜 열 고정(위에 그려짐)", sticky.scrolled > 0 && Math.abs(sticky.x1 - sticky.wrapX) < 2 && sticky.top, sticky); await p.locator(".perf-table-wrap").screenshot({ path: path.join(__dirname, ".out", "perf_dash_groups_sticky.png") }); await p.evaluate(function () { const w = document.querySelector(".perf-table-wrap"); w.style.width = ""; w.scrollLeft = 0; }); await p.locator(".perf-main").screenshot({ path: path.join(__dirname, ".out", "perf_dash_groups.png") }); await ctx.close(); // ── 설정 — 드래그 순서 ── const sp = await browser.newPage({ viewport: { width: 1500, height: 1000 } }); const puts = []; let reloads = 0; const pages = []; await sp.route("**/*", async function (r) { const req = r.request(), url = new URL(req.url()).pathname; if (url === "/favicon.ico" || url.startsWith("/static/")) { r.fulfill({ status: 404, body: "" }); return; } if (!url.startsWith("/performance/api/")) { reloads++; pages.push(url); r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: page("perf_settings_groups.html") }); return; } puts.push({ method: req.method(), url: url, body: req.postData() ? JSON.parse(req.postData()) : null }); r.fulfill({ status: 200, contentType: "application/json", body: "{}" }); }); await sp.goto("http://perf.test/performance/settings"); const order = function () { return sp.evaluate(function () { return Array.from(document.querySelectorAll(".perf-set-table tbody.perf-sort-block > tr[data-code]")).map(function (tr) { return tr.dataset.code; }); }); }; check("설정 처음 순서(그룹 뒤에 하위)", JSON.stringify(await order()) === JSON.stringify(["cafe24", "naver", "group_off", "custom_a", "custom_b", "custom_c"]), await order()); async function drag(fromCode, toCode, where) { const h = await sp.locator('tr[data-code="' + fromCode + '"] .perf-drag').boundingBox(); const t = await sp.locator('tr[data-code="' + toCode + '"]').boundingBox(); await sp.mouse.move(h.x + h.width / 2, h.y + h.height / 2); await sp.mouse.down(); const y = where === "above" ? t.y + 3 : t.y + t.height - 3; await sp.mouse.move(h.x + h.width / 2, (h.y + y) / 2, { steps: 4 }); await sp.mouse.move(h.x + h.width / 2, y, { steps: 6 }); await sp.mouse.up(); await sp.waitForTimeout(100); } // 그룹(하위 포함)을 카페24 위로 await drag("group_off", "cafe24", "above"); const o1 = await order(); check("그룹 블록 통째로 이동", JSON.stringify(o1) === JSON.stringify(["group_off", "custom_a", "custom_b", "cafe24", "naver", "custom_c"]), o1); const last = puts[puts.length - 1]; check("놓으면 화면 순서 그대로 저장", last && last.method === "PUT" && last.url === "/performance/api/marketplace-order" && JSON.stringify(last.body.codes) === JSON.stringify(o1), last); // 하위끼리 순서 변경 — 그룹 행 위로는 못 나감 await drag("custom_b", "custom_a", "above"); const o2 = await order(); check("하위 쇼핑몰은 그룹 안에서 순서 변경", JSON.stringify(o2) === JSON.stringify(["group_off", "custom_b", "custom_a", "cafe24", "naver", "custom_c"]), o2); const n = puts.length; await drag("custom_a", "naver", "below"); check("하위 쇼핑몰은 그룹 밖으로 안 나감(저장 없음)", JSON.stringify(await order()) === JSON.stringify(o2) && puts.length === n, await order()); // 그룹 지정 select → PUT parent_code check("순서 저장은 새로고침 없음", reloads === 1, pages); await sp.selectOption('tr[data-code="custom_c"] select[data-act-group]', "group_off"); await sp.waitForTimeout(300); const g = puts[puts.length - 1]; check("그룹 지정 → PUT parent_code 후 새로고침", g && g.url === "/performance/api/marketplaces/custom_c" && g.body.parent_code === "group_off" && reloads === 2, { g: g, reloads: reloads }); const wraps = await sp.evaluate(function () { const t = document.querySelector(".perf-set-table"); return t.scrollWidth <= t.parentElement.clientWidth + 1; }); check("설정 표가 1500px 에서 가로 스크롤 없음", wraps); await sp.screenshot({ path: path.join(__dirname, ".out", "perf_settings_groups.png"), fullPage: true }); } finally { await browser.close(); } console.log(fails.length ? "\n" + fails.length + " FAIL" : "\nALL PASS"); process.exit(fails.length ? 1 : 0); })();