@@ -122,17 +122,34 @@ func TestNoLoginViewIssue(t *testing.T) {
122122 MakeRequest (t , req , http .StatusOK )
123123}
124124
125- func testNewIssue (t * testing.T , session * TestSession , user , repo , title , content string ) string {
125+ type newIssueOptions struct {
126+ Title string
127+ Content string
128+ ProjectID int64
129+ LabelIDs []int64
130+ }
131+
132+ func testNewIssue (t * testing.T , session * TestSession , user , repo string , opts newIssueOptions ) string {
126133 req := NewRequest (t , "GET" , path .Join (user , repo , "issues" , "new" ))
127134 resp := session .MakeRequest (t , req , http .StatusOK )
128135
129136 htmlDoc := NewHTMLParser (t , resp .Body )
130137 link , exists := htmlDoc .doc .Find ("form.ui.form" ).Attr ("action" )
131138 assert .True (t , exists , "The template has changed" )
139+ var labelIDs string
140+ for i , id := range opts .LabelIDs {
141+ labelIDs += strconv .FormatInt (id , 10 )
142+ if i < len (opts .LabelIDs )- 1 {
143+ labelIDs += ","
144+ }
145+ }
146+
132147 req = NewRequestWithValues (t , "POST" , link , map [string ]string {
133- "_csrf" : htmlDoc .GetCSRF (),
134- "title" : title ,
135- "content" : content ,
148+ "_csrf" : htmlDoc .GetCSRF (),
149+ "title" : opts .Title ,
150+ "content" : opts .Content ,
151+ "project_id" : strconv .FormatInt (opts .ProjectID , 10 ),
152+ "label_ids" : labelIDs ,
136153 })
137154 resp = session .MakeRequest (t , req , http .StatusOK )
138155
@@ -142,9 +159,9 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content
142159
143160 htmlDoc = NewHTMLParser (t , resp .Body )
144161 val := htmlDoc .doc .Find ("#issue-title-display" ).Text ()
145- assert .Contains (t , val , title )
162+ assert .Contains (t , val , opts . Title )
146163 val = htmlDoc .doc .Find (".comment .render-content p" ).First ().Text ()
147- assert .Equal (t , content , val )
164+ assert .Equal (t , opts . Content , val )
148165
149166 return issueURL
150167}
@@ -210,13 +227,19 @@ func testIssueChangeMilestone(t *testing.T, session *TestSession, repoLink strin
210227func TestNewIssue (t * testing.T ) {
211228 defer tests .PrepareTestEnv (t )()
212229 session := loginUser (t , "user2" )
213- testNewIssue (t , session , "user2" , "repo1" , "Title" , "Description" )
230+ testNewIssue (t , session , "user2" , "repo1" , newIssueOptions {
231+ Title : "Title" ,
232+ Content : "Description" ,
233+ })
214234}
215235
216236func TestEditIssue (t * testing.T ) {
217237 defer tests .PrepareTestEnv (t )()
218238 session := loginUser (t , "user2" )
219- issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title" , "Description" )
239+ issueURL := testNewIssue (t , session , "user2" , "repo1" , newIssueOptions {
240+ Title : "Title" ,
241+ Content : "Description" ,
242+ })
220243
221244 req := NewRequestWithValues (t , "POST" , issueURL + "/content" , map [string ]string {
222245 "_csrf" : GetUserCSRFToken (t , session ),
@@ -244,7 +267,10 @@ func TestEditIssue(t *testing.T) {
244267func TestIssueCommentClose (t * testing.T ) {
245268 defer tests .PrepareTestEnv (t )()
246269 session := loginUser (t , "user2" )
247- issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title" , "Description" )
270+ issueURL := testNewIssue (t , session , "user2" , "repo1" , newIssueOptions {
271+ Title : "Title" ,
272+ Content : "Description" ,
273+ })
248274 testIssueAddComment (t , session , issueURL , "Test comment 1" , "" )
249275 testIssueAddComment (t , session , issueURL , "Test comment 2" , "" )
250276 testIssueAddComment (t , session , issueURL , "Test comment 3" , "close" )
@@ -260,7 +286,10 @@ func TestIssueCommentClose(t *testing.T) {
260286func TestIssueCommentDelete (t * testing.T ) {
261287 defer tests .PrepareTestEnv (t )()
262288 session := loginUser (t , "user2" )
263- issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title" , "Description" )
289+ issueURL := testNewIssue (t , session , "user2" , "repo1" , newIssueOptions {
290+ Title : "Title" ,
291+ Content : "Description" ,
292+ })
264293 comment1 := "Test comment 1"
265294 commentID := testIssueAddComment (t , session , issueURL , comment1 , "" )
266295 comment := unittest .AssertExistsAndLoadBean (t , & issues_model.Comment {ID : commentID })
@@ -281,7 +310,10 @@ func TestIssueCommentDelete(t *testing.T) {
281310func TestIssueCommentUpdate (t * testing.T ) {
282311 defer tests .PrepareTestEnv (t )()
283312 session := loginUser (t , "user2" )
284- issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title" , "Description" )
313+ issueURL := testNewIssue (t , session , "user2" , "repo1" , newIssueOptions {
314+ Title : "Title" ,
315+ Content : "Description" ,
316+ })
285317 comment1 := "Test comment 1"
286318 commentID := testIssueAddComment (t , session , issueURL , comment1 , "" )
287319
@@ -310,7 +342,10 @@ func TestIssueCommentUpdate(t *testing.T) {
310342func TestIssueCommentUpdateSimultaneously (t * testing.T ) {
311343 defer tests .PrepareTestEnv (t )()
312344 session := loginUser (t , "user2" )
313- issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title" , "Description" )
345+ issueURL := testNewIssue (t , session , "user2" , "repo1" , newIssueOptions {
346+ Title : "Title" ,
347+ Content : "Description" ,
348+ })
314349 comment1 := "Test comment 1"
315350 commentID := testIssueAddComment (t , session , issueURL , comment1 , "" )
316351
@@ -348,7 +383,10 @@ func TestIssueCommentUpdateSimultaneously(t *testing.T) {
348383func TestIssueReaction (t * testing.T ) {
349384 defer tests .PrepareTestEnv (t )()
350385 session := loginUser (t , "user2" )
351- issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title" , "Description" )
386+ issueURL := testNewIssue (t , session , "user2" , "repo1" , newIssueOptions {
387+ Title : "Title" ,
388+ Content : "Description" ,
389+ })
352390
353391 req := NewRequest (t , "GET" , issueURL )
354392 resp := session .MakeRequest (t , req , http .StatusOK )
@@ -448,7 +486,10 @@ func TestIssueCrossReference(t *testing.T) {
448486
449487func testIssueWithBean (t * testing.T , user string , repoID int64 , title , content string ) (string , * issues_model.Issue ) {
450488 session := loginUser (t , user )
451- issueURL := testNewIssue (t , session , user , fmt .Sprintf ("repo%d" , repoID ), title , content )
489+ issueURL := testNewIssue (t , session , user , fmt .Sprintf ("repo%d" , repoID ), newIssueOptions {
490+ Title : title ,
491+ Content : content ,
492+ })
452493 indexStr := issueURL [strings .LastIndexByte (issueURL , '/' )+ 1 :]
453494 index , err := strconv .Atoi (indexStr )
454495 assert .NoError (t , err , "Invalid issue href: %s" , issueURL )
0 commit comments