Skip to content

Commit e2c76a3

Browse files
committed
Add unit tests for the link converter
1 parent ddcfcfa commit e2c76a3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tbx/core/tests/test_formatting.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from django.test import TestCase
2+
3+
from ..utils.formatting import (
4+
convert_bold_links_to_pink,
5+
convert_italic_links_to_purple,
6+
)
7+
8+
9+
class ConvertBoldLinksToPinkTestCase(TestCase):
10+
def test_doesnt_convert_non_link(self):
11+
html_text = "<b>Hello</b> world <b><i>foo</i></b> bar"
12+
result = convert_bold_links_to_pink(html_text)
13+
self.assertEqual(html_text, result)
14+
15+
def test_convert_link(self):
16+
html_text = '<a href="#"><b>Hello</b> world <b><i>foo</i></b> bar</a>'
17+
result = convert_bold_links_to_pink(html_text)
18+
self.assertEqual(
19+
result,
20+
(
21+
'<a href="#"><span class="text-coral">Hello</span> world '
22+
'<span class="text-coral"><i>foo</i></span> bar</a>'
23+
),
24+
)
25+
26+
27+
class ConvertItalicLinksToPurpleTestCase(TestCase):
28+
def test_doesnt_convert_non_link(self):
29+
html_text = "<i>Hello</i> world <b><i>foo</i></b> bar"
30+
result = convert_italic_links_to_purple(html_text)
31+
self.assertEqual(html_text, result)
32+
33+
def test_convert_link(self):
34+
html_text = '<a href="#"><i>Hello</i> world <b><i>foo</i></b> bar</a>'
35+
result = convert_italic_links_to_purple(html_text)
36+
self.assertEqual(
37+
result,
38+
(
39+
'<a href="#"><span class="text-nebuline">Hello</span> world '
40+
'<b><span class="text-nebuline">foo</span></b> bar</a>'
41+
),
42+
)

0 commit comments

Comments
 (0)