@@ -342,11 +342,12 @@ index 0000000000..bbbbbbbbbb
342342}
343343
344344func 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
346346 req := NewRequest (t , "GET" , path .Join (owner , repo , operation , branch , filePath ))
347347 resp := session .MakeRequest (t , req , http .StatusOK )
348+ assert .Contains (t , resp .Body .String (), "Fork Repository to Propose Changes" )
348349
349- // Fork
350+ // fork the repository
350351 req = NewRequestWithValues (t , "POST" , path .Join (owner , repo , "_fork" , branch ), map [string ]string {"_csrf" : GetUserCSRFToken (t , session )})
351352 resp = session .MakeRequest (t , req , http .StatusOK )
352353 assert .Equal (t , `{"redirect":""}` , strings .TrimSpace (resp .Body .String ()))
@@ -387,6 +388,37 @@ func testForkToEditFile(t *testing.T, session *TestSession, user, owner, repo, b
387388 // Check the existence of the forked repo with unique name
388389 req = NewRequestf (t , "GET" , "/%s/%s-1" , user , repo )
389390 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 , fmt .Sprintf ("%s-patch-1" , user ), 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 ))
390422}
391423
392424func TestForkToEditFile (t * testing.T ) {
0 commit comments