// 실적 수동 입력 칸 — 실제 브라우저(Chromium). 칸을 눌러 입력칸이 떠도 열 너비·행 높이가 그대로인지. // python tests/js/render_performance.py // NODE_PATH= PJ_TEST_BROWSER= node tests/js/perf_manual.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); } } (async function () { // 바꿔 넣는 글에 $ 가 있어도 그대로 들어가게 함수로 치환 const css = fs.readFileSync(process.env.PERF_CSS || path.join(ROOT, "app", "static", "performance.css"), "utf8"); const js = fs.readFileSync(path.join(ROOT, "app", "static", "performance.js"), "utf8"); const html = fs.readFileSync(path.join(__dirname, ".out", "perf_dash.html"), "utf8") .replace(//, function () { return ""; }) .replace(/"; }); const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {}); try { for (const width of [1400, 900]) { const page = await browser.newPage({ viewport: { width: width, height: 900 } }); await page.route("**/performance/api/**", function (r) { r.fulfill({ status: 200, contentType: "application/json", body: "{}" }); }); await page.setContent(html, { waitUntil: "load" }); const measure = function () { return page.evaluate(function () { const ths = Array.from(document.querySelectorAll(".perf-main thead th")).map(function (th) { return Math.round(th.getBoundingClientRect().width); }); const row = document.querySelector('td.is-manual-cell[data-manual-code="kakao"][data-date="2026-10-05"]').closest("tr"); return { ths: ths, h: Math.round(row.getBoundingClientRect().height) }; }); }; const before = await measure(); for (const sel of ['td.is-manual-cell[data-manual-code="kakao"][data-date="2026-10-05"]', 'td.is-manual-cell[data-manual-code="coupang"][data-date="2026-10-05"]']) { await page.click(sel); const during = await measure(); const inp = await page.evaluate(function (s) { const td = document.querySelector(s), i = td.querySelector(".perf-manual-input"); if (!i) return null; const a = td.getBoundingClientRect(), b = i.getBoundingClientRect(); return { inside: b.left >= a.left - 0.5 && b.right <= a.right + 0.5 && b.top >= a.top - 0.5 && b.bottom <= a.bottom + 0.5, focused: document.activeElement === i, w: Math.round(b.width) }; }, sel); check("[" + width + "px] " + sel.match(/code="(\w+)"/)[1] + " 칸 입력 — 열 너비 그대로", JSON.stringify(during.ths) === JSON.stringify(before.ths), { before: before.ths, during: during.ths }); check("[" + width + "px] " + sel.match(/code="(\w+)"/)[1] + " 칸 입력 — 행 높이 그대로·입력칸이 칸 안·포커스", during.h === before.h && inp && inp.inside && inp.focused && inp.w > 20, { h: [before.h, during.h], inp: inp }); await page.keyboard.press("Escape"); } await page.close(); } } finally { await browser.close(); } console.log(fails.length ? "\n" + fails.length + " FAILED" : "\nALL PASS"); process.exit(fails.length ? 1 : 0); })();