Files
dbx-main/tests/test_project_goal_rich_text.py
king 96f54db0b1 feat(project): 섹션째 다른 프로젝트로 · 회의록 글 칸 하이퍼링크 · 업무 등록 표 하위 업무·줄 클릭 업무 창
- 보드 섹션 머리를 왼쪽 프로젝트 목록에 놓으면 확인 창 → POST /api/stages/{id}/move-project
  (db.move_stage_to_project 한 트랜잭션: 섹션 + 업무 + 세부 업무, 대상 맨 끝, 원·대상 멤버만, 남의 연결은 원 프로젝트에 섹션 없음)
- 목표·회의록 글 칸 서식 도구 🔗 — pj-rich 조각 link(http(s)만, 서버 store.goal_link), 주소 붙여넣기 = 링크, Ctrl+클릭 = 새 탭
- 회의록 업무 등록 표: 등록된 줄 [+] = 바로 아래 세부 업무 초안, 세부 업무 줄은 상위 줄 아래 들여쓰기,
  등록된 줄 어디든 클릭 = 오른쪽 업무 창, ↳ 상위 = 상위 업무 창
- 도움말·CLAUDE.md·PROJECT_MODULE.md 6-26, 정적 파일 버전 20261026a
- 테스트: test_move_stage_to_other_project(실제 PG), 링크 서버 검증, project_ui [섹션 이동], goals_meeting_ui [2g5],
  goal_text_link.browser.test.js

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 12:29:14 +09:00

112 lines
6.7 KiB
Python

import json
import unittest
from types import SimpleNamespace
from app.modules.project import store
from app.modules.project.router import _month_plan
def rich(runs):
return store.GOAL_RICH_PREFIX + json.dumps(runs, ensure_ascii=False)
class GoalRichTextTests(unittest.TestCase):
def test_summary_keeps_all_styles_except_font_size(self):
body = rich([{"text": "<계획>\n 다음 줄", "bold": True, "italic": True,
"underline": True, "color": "#DC2626", "size": 32},
{"text": " 해제", "bold": False, "italic": False,
"underline": False, "size": 10}])
html = store.goal_text_html(body, include_size=False)
for style in ("font-weight:700", "font-style:italic", "text-decoration:underline",
"color:#dc2626", "font-weight:400", "font-style:normal", "text-decoration:none"):
self.assertIn(style, html)
self.assertIn("&lt;계획&gt;\n 다음 줄", html)
self.assertNotIn("font-size", html)
self.assertIn("font-size:32px", store.goal_text_html(body))
self.assertIn("font-size:10px", store.goal_text_html(body))
def test_month_plan_preserves_formatted_merged_cells_and_literal_legacy_text(self):
body = rich([{"text": "<img src=x onerror=alert(1)>\n 계획", "bold": True,
"italic": True, "underline": True, "color": "#2563EB", "size": 24}])
rows = [{"label": "인플", "cells": {7: body}, "merges": {7: (3, 2)}},
{"label": "숨긴 줄", "cells": {}, "merges": {}},
{"label": "쿠팡", "cells": {9: "<b>평문</b>"}, "merges": {}},
{"label": "빈 칸", "cells": {9: rich([{"text": " ", "bold": True}])}, "merges": {}}]
fake = SimpleNamespace(goals_enabled=lambda: True,
get_goal_board=lambda **kw: {"areas": [{"name": "유통", "color": "#cdebf8", "rows": rows}]})
plans = _month_plan(fake, 2026, 9)
lines = plans[0]["lines"]
self.assertEqual(len(lines), 2)
self.assertEqual(lines[0]["range"], "7~9월")
self.assertEqual(lines[0]["text"], store.goal_text_plain(body))
self.assertEqual(lines[0]["text_html"], store.goal_text_html(body, include_size=False))
self.assertNotIn("<img", lines[0]["text_html"])
self.assertNotIn("font-size", lines[0]["text_html"])
self.assertEqual(lines[1]["text_html"], "&lt;b&gt;평문&lt;/b&gt;")
self.assertEqual(rows[0]["cells"][7], body)
def test_selected_styles_are_safe_and_legacy_text_stays_literal(self):
body = rich([{"text": "<img src=x onerror=alert(1)>", "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 '&lt;img' in html and '<img' not in html
assert 'font-weight:700' in html and 'color:#ff0000' in html and 'font-size:20px' in html
assert 'javascript' not in html and 'onclick' not in stored and '99px' not in html
assert store.goal_text_html('<b>legacy</b>') == '&lt;b&gt;legacy&lt;/b&gt;'
def test_link_runs_are_http_only_and_render_as_safe_anchor(self):
"""하이퍼링크(2026-10-26) — http(s) 주소만 남기고 나머지(javascript:·따옴표 섞인 주소)는 버림, HTML 은 새 탭 a."""
body = rich([{"text": "네이버", "link": "https://naver.com/a?b=1&c=2", "bold": True},
{"text": " 나쁜", "link": "javascript:alert(1)"},
{"text": " 따옴표", "link": 'https://x.test/"onmouseover="alert(1)'},
{"text": " 끝"}])
stored = store.validate_goal_text(body)
runs = store.goal_text_runs(stored)
self.assertEqual(runs[0]["link"], "https://naver.com/a?b=1&c=2")
self.assertTrue(all("link" not in r for r in runs[1:]))
html = store.goal_text_html(stored)
self.assertIn('<a class="pj-goal-link" href="https://naver.com/a?b=1&amp;c=2" target="_blank" rel="noopener noreferrer">'
'<span style="font-weight:700">네이버</span></a>', html)
self.assertNotIn("javascript", html)
self.assertNotIn("onmouseover", html)
self.assertEqual(html.count("<a "), 1)
# 회의록 칸 옮기기 비교도 링크를 서식으로 본다(같은 링크끼리만 합침)
moved = store.validate_meeting_content(rich([{"text": "a", "link": "https://a.test"}, {"text": "b", "link": "https://a.test"},
{"text": "c"}]))
self.assertEqual(store.goal_text_runs(moved), [{"text": "ab", "link": "https://a.test"}, {"text": "c"}])
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_italic_and_underline_survive_save_render_and_merge(self):
body = rich([{"text": "<선택>", "italic": True, "underline": True, "size": 16},
{"text": "해제", "italic": False, "underline": False},
{"text": "invalid", "italic": "url(javascript:x)", "underline": 1}])
stored = store.validate_goal_text(body)
runs = store.goal_text_runs(stored)
assert runs[0]["italic"] is True and runs[0]["underline"] is True
assert runs[1]["italic"] is False and runs[1]["underline"] is False
assert runs[2] == {"text": "invalid"}
html = store.goal_text_html(stored)
assert '&lt;선택&gt;' in html and 'font-style:italic' in html and 'text-decoration:underline' in html
assert 'font-style:normal' in html and 'text-decoration:none' in html
assert 'javascript' not in stored
merged = store.merge_goal_texts([stored, 'plain'])
assert store.goal_text_runs(merged)[0]["underline"] is True
assert store.goal_text_plain(merged) == '<선택>해제invalid\nplain'
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')