-
Notifications
You must be signed in to change notification settings - Fork 0
/
blocknote_test.go
140 lines (132 loc) · 2.92 KB
/
blocknote_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package malak
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestGetSimpleContent(t *testing.T) {
tests := []struct {
name string
content interface{}
expected string
}{
{
name: "Single StyledText",
content: []interface{}{
map[string]interface{}{
"type": "text",
"text": "Hello, World!",
"styles": map[string]interface{}{
"bold": true,
},
},
},
expected: "<span style='font-weight: bold;'>Hello, World!</span>",
},
{
name: "Multiple StyledText",
content: []interface{}{
map[string]interface{}{
"type": "text",
"text": "Hello, ",
"styles": map[string]interface{}{
"bold": true,
},
},
map[string]interface{}{
"type": "text",
"text": "World!",
"styles": map[string]interface{}{
"italic": true,
},
},
},
expected: "<span style='font-weight: bold;'>Hello, </span><span style='font-style: italic;'>World!</span>",
},
{
name: "String Content",
content: "Plain Text",
expected: "Plain Text",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := getSimpleContent(tt.content)
require.Equal(t, tt.expected, result)
})
}
}
func TestApplyInlineStyles(t *testing.T) {
tests := []struct {
name string
text string
styles map[string]interface{}
expected string
}{
{
name: "No Styles",
text: "Plain Text",
styles: map[string]interface{}{},
expected: "Plain Text",
},
{
name: "Bold",
text: "Bold Text",
styles: map[string]interface{}{
"bold": true,
},
expected: "<span style='font-weight: bold;'>Bold Text</span>",
},
{
name: "Multiple Styles",
text: "Styled Text",
styles: map[string]interface{}{
"bold": true,
"italic": true,
"textColor": "blue",
"backgroundColor": "lightgray",
},
expected: "<span style='font-weight: bold; font-style: italic; color: blue; background-color: lightgray;'>Styled Text</span>",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := applyInlineStyles(tt.text, tt.styles)
require.Equal(t, tt.expected, result)
})
}
}
func TestGetStyleString(t *testing.T) {
tests := []struct {
name string
props map[string]interface{}
expected string
}{
{
name: "Empty Props",
props: map[string]interface{}{},
expected: "",
},
{
name: "Text Color",
props: map[string]interface{}{
"textColor": "red",
},
expected: "color:red;",
},
{
name: "Multiple Properties",
props: map[string]interface{}{
"textColor": "blue",
"backgroundColor": "lightgray",
"textAlignment": "right",
},
expected: "color:blue; background-color:lightgray; text-align:right;",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := getStyleString(tt.props)
require.Equal(t, tt.expected, result)
})
}
}