@@ -7,17 +7,21 @@ import (
7
7
"context"
8
8
"html/template"
9
9
"os"
10
+ "strings"
10
11
"testing"
11
12
13
+ "code.gitea.io/gitea/models/issues"
12
14
"code.gitea.io/gitea/models/unittest"
13
15
"code.gitea.io/gitea/modules/git"
14
16
"code.gitea.io/gitea/modules/log"
15
17
"code.gitea.io/gitea/modules/markup"
18
+ "code.gitea.io/gitea/modules/translation"
16
19
17
20
"github.com/stretchr/testify/assert"
18
21
)
19
22
20
- const testInput = ` space @mention-user
23
+ func testInput () string {
24
+ s := ` space @mention-user<SPACE><SPACE>
21
25
/just/a/path.bin
22
26
https://example.com/file.bin
23
27
[local link](file.bin)
@@ -36,8 +40,10 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
36
40
37
41
@mention-user test
38
42
#123
39
- space
43
+ space<SPACE><SPACE>
40
44
`
45
+ return strings .ReplaceAll (s , "<SPACE>" , " " )
46
+ }
41
47
42
48
var testMetas = map [string ]string {
43
49
"user" : "user13" ,
@@ -121,23 +127,23 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
121
127
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
122
128
space`
123
129
124
- assert .EqualValues (t , expected , RenderCommitBody (context .Background (), testInput , testMetas ))
130
+ assert .EqualValues (t , expected , RenderCommitBody (context .Background (), testInput () , testMetas ))
125
131
}
126
132
127
133
func TestRenderCommitMessage (t * testing.T ) {
128
134
expected := `space <a href="/mention-user" class="mention">@mention-user</a> `
129
135
130
- assert .EqualValues (t , expected , RenderCommitMessage (context .Background (), testInput , testMetas ))
136
+ assert .EqualValues (t , expected , RenderCommitMessage (context .Background (), testInput () , testMetas ))
131
137
}
132
138
133
139
func TestRenderCommitMessageLinkSubject (t * testing.T ) {
134
140
expected := `<a href="https://example.com/link" class="default-link muted">space </a><a href="/mention-user" class="mention">@mention-user</a>`
135
141
136
- assert .EqualValues (t , expected , RenderCommitMessageLinkSubject (context .Background (), testInput , "https://example.com/link" , testMetas ))
142
+ assert .EqualValues (t , expected , RenderCommitMessageLinkSubject (context .Background (), testInput () , "https://example.com/link" , testMetas ))
137
143
}
138
144
139
145
func TestRenderIssueTitle (t * testing.T ) {
140
- expected := ` space @mention-user
146
+ expected := ` space @mention-user<SPACE><SPACE>
141
147
/just/a/path.bin
142
148
https://example.com/file.bin
143
149
[local link](file.bin)
@@ -156,9 +162,10 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
156
162
157
163
@mention-user test
158
164
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
159
- space
165
+ space<SPACE><SPACE>
160
166
`
161
- assert .EqualValues (t , expected , RenderIssueTitle (context .Background (), testInput , testMetas ))
167
+ expected = strings .ReplaceAll (expected , "<SPACE>" , " " )
168
+ assert .EqualValues (t , expected , RenderIssueTitle (context .Background (), testInput (), testMetas ))
162
169
}
163
170
164
171
func TestRenderMarkdownToHtml (t * testing.T ) {
@@ -183,5 +190,20 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
183
190
#123
184
191
space</p>
185
192
`
186
- assert .EqualValues (t , expected , RenderMarkdownToHtml (context .Background (), testInput ))
193
+ assert .EqualValues (t , expected , RenderMarkdownToHtml (context .Background (), testInput ()))
194
+ }
195
+
196
+ func TestRenderLabels (t * testing.T ) {
197
+ ctx := context .Background ()
198
+ locale := & translation.MockLocale {}
199
+
200
+ label := & issues.Label {ID : 123 , Name : "label-name" , Color : "label-color" }
201
+ issue := & issues.Issue {}
202
+ expected := `/owner/repo/issues?labels=123`
203
+ assert .Contains (t , RenderLabels (ctx , locale , []* issues.Label {label }, "/owner/repo" , issue ), expected )
204
+
205
+ label = & issues.Label {ID : 123 , Name : "label-name" , Color : "label-color" }
206
+ issue = & issues.Issue {IsPull : true }
207
+ expected = `/owner/repo/pulls?labels=123`
208
+ assert .Contains (t , RenderLabels (ctx , locale , []* issues.Label {label }, "/owner/repo" , issue ), expected )
187
209
}
0 commit comments