// 말레이시아 실적(2026-11-20) — 실제 브라우저. 같은 performance.js 가 data-base(/malaysia/performance)로 저장하고 // 금액을 RM 소수 2자리로 보이는지(저장 단위 = 센). // python tests/js/render_performance.py // NODE_PATH= PJ_TEST_BROWSER= node tests/js/perf_malaysia.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 load(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 { // 매출 실적 — 틱톡 라이브커머스 10/5 칸(RM 100.05)을 12.34 로 const page = await browser.newPage({ viewport: { width: 1400, height: 900 } }); const calls = []; await page.route("**/*", function (r) { if (!/\/api\//.test(r.request().url())) return r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: load("perf_my_dash.html") }); calls.push({ url: r.request().url(), body: r.request().postData() }); r.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ ok: true, manual: 1234, amount: 1234, commission: 0, net: 1234, formula: null }) }); }); await page.goto("http://perf.test/malaysia/performance/"); const sel = 'td.is-manual-cell[data-manual-code="custom_tiktok_live"][data-date="2026-10-05"]'; await page.click(sel); const prefill = await page.$eval(sel + " .perf-manual-input", function (i) { return i.value; }); check("편집창 = RM 값(100.05)", prefill === "100.05", prefill); await page.keyboard.press("Control+A"); await page.keyboard.type("RM 12.34"); await page.keyboard.press("Escape"); // 저장 뒤 새로고침(합계 다시 계산) 전에 칸 값을 본다 — Enter 는 다음 칸 편집으로 넘어감 await page.click(sel); await page.keyboard.press("Control+A"); await page.keyboard.type("RM 12.34"); await page.keyboard.press("Enter"); await page.waitForTimeout(300); const put = calls.find(function (c) { return /manual-sales/.test(c.url); }); check("저장 주소 = /malaysia/performance/api/manual-sales/…", put && /\/malaysia\/performance\/api\/manual-sales\/custom_tiktok_live\/2026-10-05$/.test(put.url), put); check("보낸 값 = 12.34(RM 글자 지움)", put && JSON.parse(put.body).amount === "12.34", put); const cell = await page.$eval(sel, function (td) { return { gross: td.querySelector(".v-gross").textContent, v: td.dataset.manualValue }; }); check("저장 뒤 칸 = 12.34, 편집값 12.34", cell.gross === "12.34" && cell.v === "12.34", cell); const head = await page.$eval("#perf-chart-daily svg", function (s) { return s.querySelector("title").textContent; }); check("그래프 말풍선 = RM", / RM$/.test(head) && /\d\.\d\d RM$/.test(head), head); await page.close(); // 광고비 — 쇼피 10/5 칸에 계산식 const ap = await browser.newPage({ viewport: { width: 1400, height: 900 } }); const acalls = []; await ap.route("**/*", function (r) { if (!/\/api\//.test(r.request().url())) return r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: load("perf_my_ads.html") }); acalls.push({ url: r.request().url(), body: r.request().postData() }); r.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ ok: true, manual: 300, amount: 300, formula: "1.5*2" }) }); }); await ap.goto("http://perf.test/malaysia/performance/ads"); const heads = await ap.$$eval(".perf-main thead th", function (ths) { return ths.map(function (t) { return t.textContent.trim(); }); }); check("광고비 열 = 틱톡·쇼피·라자다", /틱톡/.test(heads[2]) && /쇼피/.test(heads[3]) && /라자다/.test(heads[4]) && heads.length === 5, heads); const asel = 'td.is-manual-cell[data-manual-code="shopee"][data-date="2026-10-05"]'; await ap.click(asel); await ap.keyboard.type("1.5*2"); await ap.keyboard.press("Enter"); await ap.waitForTimeout(300); const aput = acalls.find(function (c) { return /ad-spend/.test(c.url); }); check("광고비 저장 주소 = /malaysia/performance/api/ad-spend/shopee/…", aput && /\/malaysia\/performance\/api\/ad-spend\/shopee\/2026-10-05$/.test(aput.url), aput); const av = await ap.$eval(asel + " .v-gross", function (s) { return s.textContent; }); check("광고비 칸 = 3.00", av === "3.00", av); await ap.close(); } finally { await browser.close(); } console.log(fails.length ? "\n" + fails.length + " FAILED" : "\nALL PASS"); process.exit(fails.length ? 1 : 0); })();