// 목표·회의록 칸 하이퍼링크(2026-10-26) — 실제 브라우저(Chromium). // python tests/js/render_goals.py // NODE_PATH= PJ_TEST_BROWSER= node tests/js/goal_text_link.browser.test.js // 회의록 "주요 업무" 칸과 같은 편집 칸(.pj-goal-text contenteditable + PJGoalText) + 렌더한 회의록 화면의 서식 도구: // 글자 선택 → 🔗 → 주소 Enter = 링크(값 = pj-rich 조각 link), 주소만 붙여 넣기 = 링크, Ctrl+클릭 = 새 탭, [링크 삭제] = 링크만 뺌, // http(s) 아닌 주소는 거절. 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); } } const css = fs.readFileSync(path.join(ROOT, "app", "static", "project.css"), "utf8"); const js = fs.readFileSync(path.join(ROOT, "app", "static", "project-goal-text.js"), "utf8"); const meeting = fs.readFileSync(path.join(__dirname, ".out", "meeting_admin.html"), "utf8"); const toolbar = (function () { const i = meeting.indexOf('
까지 let depth = 0, j = i; const re = //g; re.lastIndex = i; let m; while ((m = re.exec(meeting))) { depth += m[0] === "
" ? -1 : 1; if (!depth) { j = m.index + 6; break; } } return meeting.slice(i, j); })(); const PAGE = "" + "
" + "
네이버 바로가기
" + "
" + toolbar + ""; (async function () { const exe = process.env.PJ_TEST_BROWSER; const browser = await chromium.launch(exe ? { executablePath: exe } : {}); const ctx = await browser.newContext({ viewport: { width: 1000, height: 600 } }); try { const p = await ctx.newPage(); await ctx.route("**/*", function (r) { if (new URL(r.request().url()).host === "goal.test") r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: PAGE }); else r.fulfill({ status: 200, contentType: "text/html", body: "opened" }); }); await p.goto("http://goal.test/"); const select = function (from, to) { return p.evaluate(function (a) { const ed = document.querySelector(".pj-goal-text"); ed.focus(); const t = ed.firstChild, r = document.createRange(); r.setStart(t, a[0]); r.setEnd(t, a[1]); const s = getSelection(); s.removeAllRanges(); s.addRange(r); document.dispatchEvent(new Event("selectionchange")); }, [from, to]); }; const value = function () { return p.evaluate(function () { return document.querySelector(".pj-goal-text").value; }); }; await select(0, 3); await p.waitForTimeout(50); const btn = p.locator('[data-goal-format="link"]'); check("서식 도구에 🔗 링크 버튼(선택하면 켜짐)", await btn.isVisible() && await btn.isEnabled()); await btn.click(); const inp = p.locator(".pj-goal-link-input"); check("🔗 → 주소 칸이 열리고 포커스", await inp.isVisible() && await p.evaluate(function () { return document.activeElement === document.querySelector(".pj-goal-link-input"); })); // http(s) 아닌 주소 거절 await inp.fill("javascript:alert(1)"); await inp.press("Enter"); check("javascript: 주소는 거절(칸 그대로·값 변화 없음)", await inp.isVisible() && (await value()) === "네이버 바로가기", await value()); // 스킴 없는 주소 → https:// 붙여 링크 await inp.fill("naver.com"); await inp.press("Enter"); await p.waitForTimeout(30); const v1 = await value(); let runs = []; try { runs = JSON.parse(v1.slice("pj-rich:v1:".length)); } catch (_) {} check("주소 Enter → 고른 글자만 링크(https:// 붙임), 나머지는 그대로", v1.startsWith("pj-rich:v1:") && runs.length === 2 && runs[0].text === "네이버" && runs[0].link === "https://naver.com" && runs[1].text === " 바로가기" && !runs[1].link, v1); const a = await p.evaluate(function () { const el = document.querySelector(".pj-goal-text a.pj-goal-link"); return el && { href: el.getAttribute("href"), target: el.target, rel: el.rel, text: el.textContent, color: getComputedStyle(el).color }; }); check("칸에 파란 밑줄 링크(새 탭·noopener)", !!a && a.href === "https://naver.com" && a.target === "_blank" && /noopener/.test(a.rel) && a.text === "네이버" && a.color === "rgb(37, 99, 235)", a); // 그냥 클릭 = 열리지 않음, Ctrl+클릭 = 새 탭 let opened = 0; ctx.on("page", function () { opened++; }); await p.click(".pj-goal-text a.pj-goal-link"); await p.waitForTimeout(150); check("편집 칸 링크 그냥 클릭 = 새 탭 안 열림", opened === 0, opened); const [np] = await Promise.all([ctx.waitForEvent("page"), p.click(".pj-goal-text a.pj-goal-link", { modifiers: ["Control"] })]); await np.waitForURL(/naver\.com/, { timeout: 5000 }).catch(function () {}); check("Ctrl+클릭 = 새 탭으로 링크 열기", !!np && /naver\.com/.test(np.url()), np && np.url()); if (np) await np.close(); // 링크 다시 고르면 🔗 눌림·주소 채움 → [링크 삭제] await p.evaluate(function () { const ed = document.querySelector(".pj-goal-text"), a = ed.querySelector("a"); ed.focus(); const r = document.createRange(); r.selectNodeContents(a); const s = getSelection(); s.removeAllRanges(); s.addRange(r); document.dispatchEvent(new Event("selectionchange")); }); await p.waitForTimeout(50); check("링크 글자 선택 → 🔗 눌림 표시", (await btn.getAttribute("aria-pressed")) === "true"); await btn.click(); check("주소 칸에 지금 링크 주소", (await inp.inputValue()) === "https://naver.com", await inp.inputValue()); await p.click('[data-goal-link="remove"]'); await p.waitForTimeout(30); check("[링크 삭제] → 링크만 빠지고 글자는 그대로", (await value()) === "네이버 바로가기" && !(await p.evaluate(function () { return !!document.querySelector(".pj-goal-text a"); })), await value()); // 주소만 붙여 넣으면 링크 await p.evaluate(function () { const ed = document.querySelector(".pj-goal-text"); ed.focus(); const r = document.createRange(); r.selectNodeContents(ed); r.collapse(false); const s = getSelection(); s.removeAllRanges(); s.addRange(r); const dt = new DataTransfer(); dt.setData("text/plain", "https://drive.google.com/x?y=1"); ed.dispatchEvent(new ClipboardEvent("paste", { clipboardData: dt, bubbles: true, cancelable: true })); }); const v2 = await value(); let r2 = []; try { r2 = JSON.parse(v2.slice("pj-rich:v1:".length)); } catch (_) {} check("주소만 붙여 넣기 → 그 주소가 링크", r2.length === 2 && r2[1].text === "https://drive.google.com/x?y=1" && r2[1].link === "https://drive.google.com/x?y=1", v2); // 저장값을 다시 그려도(서버 → 칸) 링크 유지 await p.evaluate(function (v) { const ed = document.querySelector(".pj-goal-text"); ed.value = v; }, v2); check("값을 다시 넣어도 링크 그대로(value 왕복)", (await value()) === v2); } 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); });