Files
dbx-main/tests/js/perf_malaysia_en.browser.test.js
T
king f9b087157b feat(말레이시아 실적): 한글·영문 전환 + OS 언어 기본값
- 말레이시아 실적 탭 줄에 [한글|EN] 토글(쿠키 mperf_lang), 고른 적 없으면
  브라우저·OS 첫 언어(Accept-Language) ko → 한글, 그 밖 → 영어(app/lang.py)
- 영문이면 performance-en.js(사전·패턴·낱말 치환, 창·알림까지) — 한국 실적 화면은 그대로
- 말레이시아 실적 공휴일 = 말레이시아 공휴일(live/holidays.py, 화면 언어로)
- 라이브 커머스·말레이시아 재고도 같은 기본 언어 규칙

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 16:48:37 +09:00

116 lines
6.9 KiB
JavaScript

// 말레이시아 실적 영문 화면(2026-11-20) — 실제 브라우저. performance-en.js 번역 뒤 화면·창·메뉴·알림에 한글이 하나도 없는지.
// python tests/js/render_performance.py
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/perf_malaysia_en.browser.test.js
// 한글이 남으면 그 글을 모두 찍는다 — performance-en.js EN·RULES·PHRASES 에 넣으면 된다.
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, null, 1) : "")); fails.push(name); }
}
const S = function (f) { return fs.readFileSync(path.join(ROOT, "app", "static", f), "utf8"); };
function load(file) {
return fs.readFileSync(path.join(__dirname, ".out", file), "utf8")
.replace(/<link rel="stylesheet" href="\/static\/performance\.css[^"]*" \/>/, function () { return "<style>" + S("performance.css") + "</style>"; })
.replace(/<script src="\/static\/performance-en\.js[^"]*" defer><\/script>/, function () { return "<script>" + S("performance-en.js") + "</script>"; })
.replace(/<script src="\/static\/performance\.js[^"]*" defer><\/script>/, function () { return "<script>" + S("performance.js") + "</script>"; });
}
// 화면에 남은 한글 — .perf 안 + 실적 창·메뉴·말풍선 + 알림 창(글자·title·aria-label·placeholder), 한영 토글(translate=no) 빼고
function leftovers() {
const H = /[가-힣]/, out = [];
const roots = Array.from(document.querySelectorAll('.perf, [class*="perf-"], .erp-dialog-backdrop')).filter(function (r) {
return !r.parentElement || !r.parentElement.closest('.perf, [class*="perf-"], .erp-dialog-backdrop');
});
roots.forEach(function (r) {
const tw = document.createTreeWalker(r, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT);
for (let n = r; n; n = tw.nextNode()) {
const el = n.nodeType === 1 ? n : n.parentElement;
if (!el || el.closest("[translate='no'], script, style")) continue;
if (n.nodeType === 3 && H.test(n.nodeValue)) out.push(n.nodeValue.trim());
if (n.nodeType === 1) ["title", "aria-label", "placeholder"].forEach(function (a) { const v = n.getAttribute(a); if (v && H.test(v)) out.push("@" + a + ": " + v); });
}
});
return Array.from(new Set(out.concat(window.__perfI18nMissing || [])));
}
(async function () {
const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {});
const dialogs = [];
async function open(file, url, api) {
const p = await browser.newPage({ viewport: { width: 1400, height: 900 } });
p.on("dialog", function (d) { dialogs.push(d.message()); d.accept().catch(function () {}); });
await p.route("**/*", function (r) {
if (!/\/api\//.test(r.request().url())) return r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: load(file) });
const res = api ? api(r.request()) : { status: 200, body: {} };
r.fulfill({ status: res.status || 200, contentType: "application/json", body: JSON.stringify(res.body) });
});
await p.goto("http://perf.test" + url);
return p;
}
try {
// 매출 실적 — 표·그래프·업로드 창·메모 메뉴·메모 창·잘못된 입력 알림
let p = await open("perf_my_dash_en.html", "/malaysia/performance/");
check("번역 끝나면 화면 보임(is-i18n)", await p.$eval(".perf", function (r) { return r.classList.contains("is-i18n") && getComputedStyle(r).visibility === "visible"; }));
check("탭·KPI 영문", /Sales/.test(await p.textContent(".perf-tabs")) && /last week/.test(await p.textContent(".perf-kpi-line")));
await p.click("#perf-manual-upload");
await p.waitForTimeout(150);
let left = await p.evaluate(leftovers);
check("매출 실적 + 업로드 창 — 한글 없음", left.length === 0, left);
await p.keyboard.press("Escape");
await p.click('td.is-manual-cell[data-manual-code="custom_tiktok_live"][data-date="2026-10-05"]', { button: "right" });
await p.waitForTimeout(100);
const ctx = await p.$$eval(".perf-ctx button", function (bs) { return bs.map(function (b) { return b.textContent.trim(); }); });
check("메모 메뉴 영문", ctx.length > 0 && ctx.every(function (t) { return !/[가-힣]/.test(t); }), ctx);
await p.click(".perf-ctx button");
await p.waitForTimeout(150);
left = await p.evaluate(leftovers);
check("메모 창 — 한글 없음", left.length === 0, left);
await p.keyboard.press("Escape");
await p.click('td.is-manual-cell[data-manual-code="custom_shopee_live"][data-date="2026-10-06"]');
await p.keyboard.type("12a");
await p.keyboard.press("Enter");
await p.waitForTimeout(300);
await p.close();
p = await open("perf_my_dash_year_en.html", "/malaysia/performance/?period=year");
left = await p.evaluate(leftovers);
check("연간 보기 — 한글 없음", left.length === 0, left);
await p.close();
// 광고비
p = await open("perf_my_ads_en.html", "/malaysia/performance/ads");
left = await p.evaluate(leftovers);
check("광고비 — 한글 없음", left.length === 0, left);
await p.close();
// 설정 — 수수료율 창·쇼핑몰 추가 창·삭제 확인
p = await open("perf_my_settings_en.html", "/malaysia/performance/settings", function (req) {
if (/manual-days/.test(req.url())) return { body: { days: 3 } };
if (/rates/.test(req.url())) return { body: { rates: [{ id: 1, effective_from: "2026-10-01", rate: "5" }] } };
return { status: 400, body: { detail: "기본 쇼핑몰은 삭제할 수 없습니다(사용을 끄세요)." } };
});
left = await p.evaluate(leftovers);
check("설정 — 한글 없음", left.length === 0, left);
await p.click('tr[data-code="custom_tiktok_shop"] [data-act="rate"]');
await p.waitForTimeout(250);
left = await p.evaluate(leftovers);
check("수수료율 창 — 한글 없음", left.length === 0, left);
await p.keyboard.press("Escape");
await p.click("#perf-add-shop");
await p.waitForTimeout(150);
left = await p.evaluate(leftovers);
check("쇼핑몰 추가 창 — 한글 없음", left.length === 0, left);
await p.keyboard.press("Escape");
await p.click('tr[data-code="custom_tiktok_shop"] [data-act="delete"]');
await p.waitForTimeout(300);
await p.close();
const bad = dialogs.filter(function (m) { return /[가-힣]/.test(m); });
check("알림·확인 창 문구 영문(" + dialogs.length + "개)", dialogs.length >= 2 && bad.length === 0, { bad: bad, all: dialogs });
} finally { await browser.close(); }
console.log(fails.length ? "\n" + fails.length + " FAILED" : "\nALL PASS");
process.exit(fails.length ? 1 : 0);
})();