@@ -342,14 +342,15 @@ index 0000000000..bbbbbbbbbb
342
342
}
343
343
344
344
func forkToEdit (t * testing.T , session * TestSession , owner , repo , operation , branch , filePath string ) {
345
- // Attempt to edit file
345
+ // attempt to edit a file, see the guideline page
346
346
req := NewRequest (t , "GET" , path .Join (owner , repo , operation , branch , filePath ))
347
347
resp := session .MakeRequest (t , req , http .StatusOK )
348
+ assert .Contains (t , resp .Body .String (), "Fork Repository to Propose Changes" )
348
349
349
- // Fork
350
+ // fork the repository
350
351
req = NewRequestWithValues (t , "POST" , path .Join (owner , repo , "_fork" , branch ), map [string ]string {"_csrf" : GetUserCSRFToken (t , session )})
351
352
resp = session .MakeRequest (t , req , http .StatusOK )
352
- assert .Equal (t , `{"redirect":""}` , strings . TrimSpace ( resp .Body .String () ))
353
+ assert .JSONEq (t , `{"redirect":""}` , resp .Body .String ())
353
354
}
354
355
355
356
func testForkToEditFile (t * testing.T , session * TestSession , user , owner , repo , branch , filePath string ) {
@@ -387,6 +388,37 @@ func testForkToEditFile(t *testing.T, session *TestSession, user, owner, repo, b
387
388
// Check the existence of the forked repo with unique name
388
389
req = NewRequestf (t , "GET" , "/%s/%s-1" , user , repo )
389
390
session .MakeRequest (t , req , http .StatusOK )
391
+
392
+ // the base repo's edit form should have the correct action and upload links (pointing to the forked repo)
393
+ req = NewRequest (t , "GET" , path .Join (owner , repo , "_upload" , branch , filePath ))
394
+ resp = session .MakeRequest (t , req , http .StatusOK )
395
+ htmlDoc := NewHTMLParser (t , resp .Body )
396
+
397
+ form := htmlDoc .doc .Find (".form-fetch-action" )
398
+ formAction := form .AttrOr ("action" , "" )
399
+ assert .Equal (t , fmt .Sprintf ("/%s/%s-1/_upload/%s/%s?from_base_branch=%s" , user , repo , branch , filePath , branch ), formAction )
400
+ uploadLink := form .Find (".dropzone" ).AttrOr ("data-link-url" , "" )
401
+ assert .Equal (t , fmt .Sprintf ("/%s/%s-1/upload-file" , user , repo ), uploadLink )
402
+ newBranchName := form .Find ("input[name=new_branch_name]" ).AttrOr ("value" , "" )
403
+ assert .Equal (t , user + "-patch-1" , newBranchName )
404
+ commitChoice := form .Find ("input[name=commit_choice][checked]" ).AttrOr ("value" , "" )
405
+ assert .Equal (t , "commit-to-new-branch" , commitChoice )
406
+ lastCommit := form .Find ("input[name=last_commit]" ).AttrOr ("value" , "" )
407
+ assert .NotEmpty (t , lastCommit )
408
+
409
+ // change a file in the forked repo
410
+ req = NewRequestWithValues (t , "POST" , formAction ,
411
+ map [string ]string {
412
+ "_csrf" : GetUserCSRFToken (t , session ),
413
+ "last_commit" : lastCommit ,
414
+ "tree_path" : filePath ,
415
+ "content" : "new content in fork" ,
416
+ "commit_choice" : commitChoice ,
417
+ "new_branch_name" : newBranchName ,
418
+ },
419
+ )
420
+ resp = session .MakeRequest (t , req , http .StatusOK )
421
+ assert .Equal (t , fmt .Sprintf ("/%s/%s/compare/%s...%s/%s-1:%s-patch-1" , owner , repo , branch , user , repo , user ), test .RedirectURL (resp ))
390
422
}
391
423
392
424
func TestForkToEditFile (t * testing.T ) {
0 commit comments