]*data-row="(\d+)" data-month="(\d+)"[^>]*>)([\s\S]*?)(<\/div>)/g,
function (all, open, row, month, text, close) {
const k = row + ":" + month;
- return open + (k in st.cells ? st.cells[k].replace(/&/g, "&").replace(/\s*)(<\/table>)/, '$1
' +
'| 새 영역 | ' +
' | ' +
- ' | ' +
+ ' | ' +
"
|---|
$2");
}
return { text: html };
@@ -154,6 +155,13 @@ function goalsServer(env, st) {
return st;
}
+function renderGoalBody(env, value) {
+ const div = env.d.createElement("div");
+ const runs = value.startsWith("pj-rich:v1:") ? JSON.parse(value.slice(11)) : [{ text: value }];
+ env.w.PJGoalText.paint(div, runs);
+ return div.innerHTML;
+}
+
// ── 가짜 서버 — 회의록 ────────────────────────────────────────────────
function meetServer(env, st) {
st = Object.assign({ items: {}, head: {}, itemHook: null, headHook: null, getHook: null, syncHook: null, page: PAGE.meeting_admin }, st || {});
@@ -368,14 +376,14 @@ function meetServer(env, st) {
const env = makeEnv(PAGE.goals_admin, GOALS_URL, { promptAnswer: "새 영역" });
const st = goalsServer(env, { cellHook: function () { return { status: 503, body: { detail: "temporary save failure" } }; } });
await boot(env);
- const ta = env.d.querySelector('textarea.pj-goal-text[data-row="10"][data-month="1"]');
+ const ta = env.d.querySelector('.pj-goal-text[data-row="10"][data-month="1"]');
ta.focus(); type(env, ta, "unsaved important plan");
env.d.getElementById("pj-goal-area-add").click();
await settle(); await wait(20); await settle();
check("[3] 글 저장 실패 → 영역 추가 요청 안 보냄", !env.calls.some(function (c) { return c.method === "POST" && /\/areas$/.test(c.url); }),
env.calls.map(function (c) { return c.method + " " + c.url; }));
check("[3] 표를 다시 받지 않음", !st.gets);
- check("[3] 미저장 계획 그대로", env.d.querySelector('textarea.pj-goal-text[data-row="10"][data-month="1"]').value === "unsaved important plan");
+ check("[3] 미저장 계획 그대로", env.d.querySelector('.pj-goal-text[data-row="10"][data-month="1"]').value === "unsaved important plan");
check("[3] 실패 안내", /저장/.test(env.toastText()), env.toastText());
});
await section(async function () { // 진행 중 저장 → 그 저장이 끝난 뒤에 영역 추가, 성공하면 표 교체(새 영역 보임, 저장된 글 유지)
@@ -383,7 +391,7 @@ function meetServer(env, st) {
const gate = deferred();
const st = goalsServer(env, { cellHook: async function () { await gate.promise; } });
await boot(env);
- const ta = env.d.querySelector('textarea.pj-goal-text[data-row="10"][data-month="1"]');
+ const ta = env.d.querySelector('.pj-goal-text[data-row="10"][data-month="1"]');
ta.focus(); type(env, ta, "plan v2"); ta.blur();
await settle();
env.d.getElementById("pj-goal-area-add").click();
@@ -394,7 +402,7 @@ function meetServer(env, st) {
const order = env.calls.filter(function (c) { return c.method !== "GET" || /goals\/2026$/.test(c.url); }).map(function (c) { return c.method + " " + c.url.replace(/^https?:\/\/[^/]+/, ""); });
check("[3b] 순서: 글 PUT → 영역 POST → 표 GET", order.join(" | ") === "PUT /project/api/goals/rows/10/cells/1 | POST /project/api/goals/2026/areas | GET /project/goals/2026", order);
check("[3b] 새 영역이 그 자리에 보임(새로고침 없음)", !!env.d.querySelector('tbody.pj-goal-area[data-area-id="3"]') && env.navigations === 0);
- check("[3b] 저장된 글 유지", env.d.querySelector('textarea.pj-goal-text[data-row="10"][data-month="1"]').value === "plan v2");
+ check("[3b] 저장된 글 유지", env.d.querySelector('.pj-goal-text[data-row="10"][data-month="1"]').value === "plan v2");
});
await section(async function () { // 표를 받는 사이에 새로 입력 → 저장 후 다시 받아 교체(입력 유실 없음)
const env = makeEnv(PAGE.goals_admin, GOALS_URL, { promptAnswer: "새 영역" });
@@ -404,19 +412,19 @@ function meetServer(env, st) {
await boot(env);
env.d.getElementById("pj-goal-area-add").click();
await settle();
- const ta = env.d.querySelector('textarea.pj-goal-text[data-row="11"][data-month="1"]');
+ const ta = env.d.querySelector('.pj-goal-text[data-row="11"][data-month="1"]');
ta.focus(); type(env, ta, "typed during refresh");
gate.resolve();
await settle(); await wait(30); await settle();
check("[3c] 받는 사이 입력한 글 저장됨", st.cells["11:1"] === "typed during refresh", st.cells);
- check("[3c] 교체된 표에도 그 글", env.d.querySelector('textarea.pj-goal-text[data-row="11"][data-month="1"]').value === "typed during refresh");
+ check("[3c] 교체된 표에도 그 글", env.d.querySelector('.pj-goal-text[data-row="11"][data-month="1"]').value === "typed during refresh");
check("[3c] 표를 다시 받음(2회)", st.gets === 2, st.gets);
});
await section(async function () { // 병합 — 저장 실패면 병합 요청 안 보냄
const env = makeEnv(PAGE.goals_admin, GOALS_URL);
const st = goalsServer(env, { cellHook: function () { return { status: 503, body: { detail: "x" } }; } });
await boot(env);
- const ta = env.d.querySelector('textarea.pj-goal-text[data-row="10"][data-month="1"]');
+ const ta = env.d.querySelector('.pj-goal-text[data-row="10"][data-month="1"]');
ta.focus(); type(env, ta, "draft before merge");
const a = env.d.querySelector('td.pj-goal-texttd[data-month="1"]'), b = env.d.querySelector('tr[data-row-id="10"] td.pj-goal-texttd[data-month="2"]');
a.dispatchEvent(new env.w.MouseEvent("mousedown", { bubbles: true, button: 0 }));
@@ -656,6 +664,33 @@ function meetServer(env, st) {
check("[회귀] 참석자 고르기 → 칩 + 저장", !!env.d.querySelector('.pj-meet-chip[data-key="a@test.local"]') && st.head.attendees === "a@test.local", st.head);
});
+ await section(async function () { // 선택한 글자만 서식·서식 초기화·저장·다시 그리기
+ const env = makeEnv(PAGE.goals_admin, "http://localhost/project/goals/2026"); const st = goalsServer(env); await boot(env);
+ const d = env.d, w = env.w, editor = d.querySelector('.pj-goal-text[data-row="10"][data-month="1"]');
+ type(env, editor, "앞 선택 뒤"); editor.focus();
+ const range = d.createRange(); range.setStart(editor.firstChild, 2); range.setEnd(editor.firstChild, 4);
+ w.getSelection().removeAllRanges(); w.getSelection().addRange(range); fire(env, editor, "mouseup");
+ const format = function (name, value, event) { const el = d.querySelector('[data-goal-format="' + name + '"]'); el.value = value; fire(env, el, event || "change"); };
+ format("bold", "700"); format("color", "#ff0000", "input"); format("size", "20");
+ let runs = w.PJGoalText.readRuns(editor);
+ check("[서식] 선택한 두 글자에만 색·굵기·크기", runs.length === 3 && runs[0].text === "앞 " && runs[1].text === "선택" && runs[1].bold === true && runs[1].color === "#ff0000" && runs[1].size === 20 && !runs[2].bold, runs);
+ fire(env, editor, "blur"); await settle();
+ check("[서식] 텍스트 조각을 기존 셀 API에 저장", st.cells["10:1"].startsWith("pj-rich:v1:") && JSON.parse(st.cells["10:1"].slice(11))[1].size === 20);
+ const persisted = st.cells["10:1"];
+ d.querySelector('[data-goal-format="reset"]').click(); fire(env, editor, "blur"); await settle();
+ check("[서식] 선택 서식 초기화는 글을 유지하고 평문 저장", editor.textContent === "앞 선택 뒤" && st.cells["10:1"] === "앞 선택 뒤");
+ editor.value = persisted; fire(env, editor, "input"); fire(env, editor, "blur"); await settle();
+ d.getElementById("pj-goal-area-add").click(); await settle(); await wait(20); await settle();
+ const fresh = d.querySelector('.pj-goal-text[data-row="10"][data-month="1"]');
+ check("[서식] 표 다시 그리기에도 선택 서식 유지", fresh !== editor && w.PJGoalText.readRuns(fresh)[1].size === 20);
+ fresh.focus();
+ const plainRange = d.createRange(); plainRange.setStart(fresh.firstChild, 0); plainRange.setEnd(fresh.firstChild, 1);
+ w.getSelection().removeAllRanges(); w.getSelection().addRange(plainRange); fire(env, fresh, "mouseup");
+ check("[서식] 새 평문 선택은 도구 값을 기본값으로 표시", d.querySelector('[data-goal-format="bold"]').value === "400" && d.querySelector('[data-goal-format="size"]').value === "14");
+ plainRange.collapse(true); w.getSelection().removeAllRanges(); w.getSelection().addRange(plainRange); fire(env, fresh, "keyup");
+ check("[서식] 글자 선택을 해제하면 이전 선택에 적용하지 않음", d.querySelector('[data-goal-format="reset"]').disabled);
+ });
+
clearTimeout(WATCHDOG);
const realUnhandled = unhandled.filter(function (m) { return !/Not implemented/.test(m); });
check("처리 안 된 Promise 거부 없음", realUnhandled.length === 0, realUnhandled);
diff --git a/tests/js/project_ui.test.js b/tests/js/project_ui.test.js
index 3d277cc..a90aa0a 100644
--- a/tests/js/project_ui.test.js
+++ b/tests/js/project_ui.test.js
@@ -33,6 +33,9 @@ function makeEnv() {
const dom = new JSDOM(html, { runScripts: "dangerously", pretendToBeVisual: true, url: "http://localhost/project/p/1" });
const w = dom.window, d = w.document;
w.__PJ_TEST__ = true;
+ w.HTMLDialogElement.prototype.showModal = function () { this.open = true; };
+ w.HTMLDialogElement.prototype.close = function () { this.open = false; this.dispatchEvent(new w.Event("close")); };
+ Object.defineProperty(d, "fonts", { configurable: true, value: { load: async function () { return [{}]; } } });
w.HTMLCanvasElement.prototype.getContext = function () { return null; };
w.URL.createObjectURL = function () { return "blob:x"; };
w.URL.revokeObjectURL = function () {};
@@ -103,6 +106,7 @@ async function boot(env) {
// 문제없음, 기존 코드 그대로). 테스트에서는 버튼 보강을 건너뛰고 원래 입력칸으로 시험한다.
env.d.querySelectorAll("select").forEach(function (s) { s.dataset.pjEnhanced = "1"; });
env.d.querySelectorAll("input[type=date]").forEach(function (i) { i.dataset.pjDate = "1"; });
+ env.w.eval(fs.readFileSync(path.join(ROOT, "app", "static", "project-options.js"), "utf8"));
env.w.eval(JS);
env.d.dispatchEvent(new env.w.Event("DOMContentLoaded"));
await settle();
@@ -421,7 +425,7 @@ function titleVal(d) { return d.getElementById("pj-t-title").value; }
// 보드 빠른 추가 — 세 필드, 조합 입력·중복 저장·실패 복구·취소.
{
- const env = makeEnv(); baseRoutes(env); await boot(env);
+ const env = makeEnv(); baseRoutes(env); const P = await boot(env);
const d = env.d, w = env.w, pending = deferred();
const posts = function () { return env.calls.filter(function (c) { return c.method === "POST" && /projects\/1\/tasks$/.test(c.url); }); };
env.route("POST", /projects\/1\/tasks$/, function () { return pending.promise; });
@@ -450,6 +454,9 @@ function titleVal(d) { return d.getElementById("pj-t-title").value; }
d.body.dispatchEvent(new w.Event("pointerdown", { bubbles: true })); await wait(10); await settle();
check("[board] 빈 카드 바깥 클릭은 빈 작업 생성 없이 닫기", !d.querySelector(".pj-tasknew") && posts().length === 1);
d.querySelector('.pj-col[data-stage-id="11"] .pj-col-add').click(); await wait(10);
+ check("[board] 상단 +는 기존 오른쪽 상세창을 열기", !d.getElementById("pj-modal-task").hidden && !d.querySelector(".pj-tasknew"));
+ await P.attemptClose(); await wait(400);
+ d.querySelector('.pj-col[data-stage-id="11"] .pj-col-addtask').click(); await wait(10);
input = d.querySelector(".pj-tasknew-title"); input.value = "실패해도 유지"; input.dispatchEvent(new w.Event("input"));
env.route("POST", /projects\/1\/tasks$/, function () { return { status: 500, body: { detail: "잠시 오류" } }; });
d.body.dispatchEvent(new w.Event("pointerdown", { bubbles: true })); await wait(10); await settle();
@@ -496,6 +503,28 @@ function titleVal(d) { return d.getElementById("pj-t-title").value; }
check("[board] 기존 다른 부모 카드 이동 유지", env.calls.some(function (c) { return /tasks\/901\/move-parent$/.test(c.url) && c.body.parent_task_id === 102; }) && rows().join(",") === "902,903");
}
+ {
+ const env = makeEnv(); baseRoutes(env); await boot(env); const d = env.d, w = env.w;
+ const button = d.getElementById("pj-options-btn"), dialog = d.getElementById("pj-options-dialog"), select = d.getElementById("pj-options-font");
+ button.click();
+ check("[옵션] 도움말 옆 옵션은 기본 폰트로 대화창 열기", dialog.open && select.value === "system" && select.options.length === 5);
+ select.value = "pretendard"; select.dispatchEvent(new w.Event("change")); d.getElementById("pj-options-cancel").click();
+ check("[옵션] 취소는 선택한 폰트를 적용하지 않음", !dialog.open && !w.localStorage.getItem("pj_font"));
+ button.click(); select.value = "nanum-square-neo"; d.getElementById("pj-options-save").click(); await settle();
+ check("[옵션] 저장은 폰트 적용·기억 후 대화창 닫기", !dialog.open && w.localStorage.getItem("pj_font") === "nanum-square-neo" && d.documentElement.dataset.pjFont === "nanum-square-neo");
+ button.click(); check("[옵션] 다시 열면 저장한 선택 유지", select.value === "nanum-square-neo");
+ const loading = deferred(); d.fonts.load = function () { return loading.promise; };
+ select.value = "pretendard"; d.getElementById("pj-options-save").click(); await settle();
+ const cancel = new w.Event("cancel", { cancelable: true }); dialog.dispatchEvent(cancel);
+ check("[옵션] 저장 중 취소·Esc로 지연 적용이 발생하지 않음", d.getElementById("pj-options-cancel").disabled && cancel.defaultPrevented && dialog.open);
+ loading.resolve([{}]); await settle();
+ check("[옵션] 폰트 로딩 후 저장 완료", !dialog.open && w.localStorage.getItem("pj_font") === "pretendard");
+ button.click();
+ d.fonts.load = async function () { throw new Error("font failed"); };
+ select.value = "nanum-square-round"; d.getElementById("pj-options-save").click(); await settle();
+ check("[옵션] 폰트 로딩 실패는 이전 설정 유지·재시도 가능", dialog.open && !d.getElementById("pj-options-error").hidden && !select.disabled && w.localStorage.getItem("pj_font") === "pretendard");
+ }
+
clearTimeout(WATCHDOG);
console.log(fails.length ? "\nFAILED: " + fails.join(", ") : "\nALL PASS");
process.exit(fails.length ? 1 : 0);
diff --git a/tests/js/render_goals.py b/tests/js/render_goals.py
index c3b581d..f2b0280 100644
--- a/tests/js/render_goals.py
+++ b/tests/js/render_goals.py
@@ -21,7 +21,7 @@ OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
from app.modules.project import store # noqa: E402
from app.modules.project.router import _goal_area_layout, _goal_label_spans # noqa: E402
-BASE_STUB = ("{% block head_extra %}{% endblock %}{% block topbar_actions %}{% endblock %}"
+BASE_STUB = ("{% block head_extra %}{% endblock %}{% block topbar_after_logout %}{% endblock %}{% block topbar_actions %}{% endblock %}"
"
{% block content %}{% endblock %}")
ME = "me@test.local"
diff --git a/tests/js/render_project.py b/tests/js/render_project.py
index b723aa7..471c073 100644
--- a/tests/js/render_project.py
+++ b/tests/js/render_project.py
@@ -13,7 +13,7 @@ import jinja2
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
-BASE_STUB = ("{% block head_extra %}{% endblock %}{% block topbar_actions %}{% endblock %}"
+BASE_STUB = ("{% block head_extra %}{% endblock %}{% block topbar_after_logout %}{% endblock %}{% block topbar_actions %}{% endblock %}"
"
{% block content %}{% endblock %}")
ME = "me@test.local"
diff --git a/tests/test_project_goal_rich_text.py b/tests/test_project_goal_rich_text.py
new file mode 100644
index 0000000..7941204
--- /dev/null
+++ b/tests/test_project_goal_rich_text.py
@@ -0,0 +1,37 @@
+import json
+import unittest
+from app.modules.project import store
+
+
+def rich(runs):
+ return store.GOAL_RICH_PREFIX + json.dumps(runs, ensure_ascii=False)
+
+
+class GoalRichTextTests(unittest.TestCase):
+ def test_selected_styles_are_safe_and_legacy_text_stays_literal(self):
+ body = rich([{"text": "

", "bold": True,
+ "color": "#FF0000", "size": 20, "onclick": "alert(1)"},
+ {"text": " untouched", "color": "url(javascript:x)", "size": 99}])
+ stored = store.validate_goal_text(body)
+ html = store.goal_text_html(stored)
+ assert '<img' in html and '
![]()
legacy') == '<b>legacy</b>'
+
+
+ def test_rich_merge_preserves_styles_and_plain_meeting_plan(self):
+ value = store.merge_goal_texts(['first', rich([{"text": "second", "bold": True, "size": 18}])])
+ assert store.goal_text_plain(value) == 'first\nsecond'
+ assert 'font-size:18px' in store.goal_text_html(value)
+ assert store.merge_goal_texts(['a', 'b']) == 'a\nb'
+ assert store.validate_goal_text(rich([{"text": " "}])) == ''
+
+
+ def test_rich_payload_limits_and_malformed_data(self):
+ with self.assertRaises(ValueError):
+ store.validate_goal_text(rich([{"text": "x" * (store.GOAL_TEXT_MAX + 1)}]))
+ with self.assertRaises(ValueError):
+ store.validate_goal_text(store.GOAL_RICH_PREFIX + '{"unexpected":1}')
+ with self.assertRaises(ValueError):
+ store.validate_goal_text(store.GOAL_RICH_PREFIX + '[broken')