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')