fix(project): retain monthly plan text styles
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
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):
|
||||
@@ -8,6 +10,40 @@ def rich(runs):
|
||||
|
||||
|
||||
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("<계획>\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"], "<b>평문</b>")
|
||||
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)"},
|
||||
|
||||
Reference in New Issue
Block a user