// 안내문 발송 설정 화면(2026-10-27) — 실제 브라우저(Chromium). // python tests/js/render_outreach.py // NODE_PATH= PJ_TEST_BROWSER= node tests/js/outreach_settings.browser.test.js // 세로 2단(메일 | DM), 저장해 둔 서식 본문 불러오기, {이름} 빨강 굵게(두 편집기, 글자 칠 때도), 서식 버튼, // DM 글자 수·[메일 본문 글 가져오기], [저장] = body(편집기 HTML, fmt=html)·dm_body(글), [기본 문구로 되돌리기]. 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 exe = process.env.PJ_TEST_BROWSER; const browser = await chromium.launch(exe ? { executablePath: exe } : {}); let posted = null; try { const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 } }); await ctx.route("**/*", function (r) { const req = r.request(), url = new URL(req.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 === "/outreach/settings" && req.method() === "POST") { posted = new URLSearchParams(req.postData() || ""); return r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: "

saved

" }); } r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: fs.readFileSync(path.join(__dirname, ".out", "outreach_settings.html"), "utf8") }); }); const p = await ctx.newPage(); const errors = []; p.on("pageerror", function (e) { errors.push(e.message); }); p.on("dialog", function (d) { d.accept(); }); await p.goto("http://erp.test/outreach/settings"); await p.waitForSelector("#otr-body-editor .ql-editor"); const cols = await p.evaluate(function () { return Array.from(document.querySelectorAll(".otr-split > .otr-col")).map(function (c) { const b = c.getBoundingClientRect(); return { x: Math.round(b.x), w: Math.round(b.width), top: Math.round(b.top), head: c.querySelector(".otr-col-head b").textContent }; }); }); check("세로 2단 — 왼쪽 메일, 오른쪽 DM(나란히)", cols.length === 2 && cols[0].head === "이메일 안내문" && cols[1].head === "인스타 DM 문구" && cols[1].x >= cols[0].x + cols[0].w && cols[0].top === cols[1].top && Math.abs(cols[0].w - cols[1].w) < 4, cols); const loaded = await p.evaluate(function () { const ed = document.querySelector("#otr-body-editor .ql-editor"); const big = Array.from(ed.querySelectorAll("span")).find(function (s) { return s.textContent === "큰 파란 글씨"; }); return { big: big ? big.style.fontSize + "|" + big.style.color : "", list: ed.querySelectorAll("li").length, center: !!ed.querySelector('p[style*="text-align: center"] strong, p.ql-align-center strong'), tools: Array.from(document.querySelectorAll(".ql-toolbar button, .ql-toolbar .ql-picker")).map(function (b) { return b.title; }).filter(Boolean).length, dm: document.querySelector("#otr-dm-editor .ql-editor").innerText.trim(), count: document.getElementById("otr-dm-count").textContent }; }); check("저장해 둔 서식 본문 불러오기(글자 크기·색·목록·가운데 굵게)", loaded.big === "20px|rgb(0, 102, 204)" && loaded.list === 2 && loaded.center, loaded); check("서식 도구 막대(한글 도움말)", loaded.tools >= 14, loaded.tools); check("DM 문구 불러오기 + 글자 수", loaded.dm === "안녕하세요 {이름}님, DM 입니다" && loaded.count === "19 / 1000자", loaded); const tags = function () { return p.evaluate(function () { return Array.from(document.querySelectorAll(".otr-nametag-on")).map(function (n) { const cs = getComputedStyle(n); return { ed: n.closest(".ql-container").id, text: n.textContent, color: cs.color, weight: cs.fontWeight }; }); }); }; const t0 = await tags(); check("{이름} = 빨강 굵게(메일·DM 편집기 모두)", t0.length === 2 && t0.every(function (t) { return t.text === "{이름}" && t.color === "rgb(225, 29, 72)" && t.weight === "700"; }) && t0[0].ed === "otr-body-editor" && t0[1].ed === "otr-dm-editor", t0); // 글자 치면 바로 — 새 {이름} 은 빨강, 바로 뒤에 친 글자는 아님 await p.evaluate(function () { const q = Quill.find(document.getElementById("otr-body-editor")); q.setSelection(q.getLength() - 1, 0); }); await p.keyboard.type(" {이름}님 감사"); await p.waitForTimeout(50); const t1 = await tags(); check("새로 친 {이름}도 빨강, 뒤 글자는 그대로", t1.filter(function (t) { return t.ed === "otr-body-editor"; }).length === 2 && t1.every(function (t) { return t.text === "{이름}"; }), t1); // 서식 — 글자 골라(목록의 굵지 않은 글자) 굵게 + 크기 24px await p.evaluate(function () { const q = Quill.find(document.getElementById("otr-body-editor")); const i = q.getText().indexOf("하나"); q.setSelection(i, 2); }); await p.click(".ql-toolbar .ql-bold"); await p.click(".ql-toolbar .ql-size .ql-picker-label"); await p.click('.ql-toolbar .ql-size .ql-picker-item[data-value="24px"]'); const fmt = await p.evaluate(function () { const q = Quill.find(document.getElementById("otr-body-editor")); return q.getFormat(q.getText().indexOf("하나"), 2); }); check("고른 글자 굵게·글자 크기", fmt.bold === true && fmt.size === "24px", fmt); // DM — 메일 본문 글 가져오기(확인 창) → 글자 수 await p.click("#otr-dm-from-mail"); const dm2 = await p.evaluate(function () { return { text: document.querySelector("#otr-dm-editor .ql-editor").innerText, count: document.getElementById("otr-dm-count").textContent }; }); check("[메일 본문 글 가져오기] = 서식 빼고 글만", /^안녕하세요, \{이름\}님\.\n/.test(dm2.text) && /큰 파란 글씨/.test(dm2.text) && / \/ 1000자$/.test(dm2.count), dm2); await p.evaluate(function () { Quill.find(document.getElementById("otr-dm-editor")).setText("{이름}님 반가워요\n두 줄", "user"); }); // 저장 — 숨은 칸에 편집기 HTML·DM 글 await Promise.all([p.waitForNavigation(), p.click('#otr-set-form button[type="submit"]')]); const body = posted && posted.get("body") || ""; fs.writeFileSync(path.join(__dirname, ".out", "outreach_settings_posted.html"), body); // 서버 정리(sanitize_html) 확인용 check("[저장] → fmt=html, body = 편집기 HTML(서식 그대로)", !!posted && posted.get("fmt") === "html" && /font-size: 20px/.test(body) && /font-size: 24px[^>]*>()?하나|]*>()?하나/.test(body) && /
    /.test(body) && body.indexOf("{이름}") >= 0, body.slice(0, 400)); check("[저장] → 제목·DM 글(서식 없음)", posted.get("subject") === "{이름}님께 제안" && posted.get("dm_body").replace(/\r\n/g, "\n") === "{이름}님 반가워요\n두 줄", { s: posted.get("subject"), d: posted.get("dm_body") }); // 기본 문구로 되돌리기 await p.goto("http://erp.test/outreach/settings"); await p.waitForSelector("#otr-body-editor .ql-editor"); await p.click("#otr-default"); const def = await p.evaluate(function () { return { mail: Quill.find(document.getElementById("otr-body-editor")).getText(), bold: Array.from(document.querySelectorAll("#otr-body-editor strong")).map(function (n) { return n.textContent; }), dm: Quill.find(document.getElementById("otr-dm-editor")).getText().trim(), count: document.getElementById("otr-dm-count").textContent, subject: document.querySelector('input[name="subject"]').value, names: document.querySelectorAll("#otr-body-editor .otr-nametag-on").length }; }); check("[기본 문구로 되돌리기] = 기본 본문(**굵게** → 굵게)·DM 비움·제목", /^안녕하세요, \{이름\}님\.\n주방의 본질/.test(def.mail) && def.bold.indexOf("'미라네주방'") >= 0 && def.dm === "" && /^비어 있음/.test(def.count) && /^누적매출 300억/.test(def.subject) && def.names === 6, def); // 좁은 화면 = 위아래 await p.setViewportSize({ width: 900, height: 900 }); const narrow = await p.evaluate(function () { const c = document.querySelectorAll(".otr-split > .otr-col"); return c[1].getBoundingClientRect().top > c[0].getBoundingClientRect().bottom - 1; }); check("좁은 화면 = 메일 위, DM 아래", narrow); check("화면 스크립트 오류 없음", errors.length === 0, errors); } finally { await browser.close(); } if (fails.length) { console.log("\n" + fails.length + " FAILED"); process.exit(1); } console.log("\nALL PASS"); })().catch(function (e) { console.error(e); process.exit(1); });