@@ -24,23 +24,38 @@ import (
2424func TestPullCompare (t * testing.T ) {
2525 defer tests .PrepareTestEnv (t )()
2626
27- session := loginUser (t , "user2" )
28- req := NewRequest (t , "GET" , "/user2/repo1/pulls" )
29- resp := session .MakeRequest (t , req , http .StatusOK )
30- htmlDoc := NewHTMLParser (t , resp .Body )
31- link , exists := htmlDoc .doc .Find (".new-pr-button" ).Attr ("href" )
32- assert .True (t , exists , "The template has changed" )
33-
34- req = NewRequest (t , "GET" , link )
35- resp = session .MakeRequest (t , req , http .StatusOK )
36- assert .EqualValues (t , http .StatusOK , resp .Code )
37-
38- // test the edit button in the PR diff view
39- req = NewRequest (t , "GET" , "/user2/repo1/pulls/3/files" )
40- resp = session .MakeRequest (t , req , http .StatusOK )
41- doc := NewHTMLParser (t , resp .Body )
42- editButtonCount := doc .doc .Find (".diff-file-header-actions a[href*='/_edit/']" ).Length ()
43- assert .Positive (t , editButtonCount , "Expected to find a button to edit a file in the PR diff view but there were none" )
27+ t .Run ("PullsNewRedirect" , func (t * testing.T ) {
28+ req := NewRequest (t , "GET" , "/user2/repo1/pulls/new/foo" )
29+ resp := MakeRequest (t , req , http .StatusSeeOther )
30+ redirect := test .RedirectURL (resp )
31+ assert .Equal (t , "/user2/repo1/compare/master...foo?expand=1" , redirect )
32+
33+ req = NewRequest (t , "GET" , "/user13/repo11/pulls/new/foo" )
34+ resp = MakeRequest (t , req , http .StatusSeeOther )
35+ redirect = test .RedirectURL (resp )
36+ assert .Equal (t , "/user12/repo10/compare/master...user13:foo?expand=1" , redirect )
37+ })
38+
39+ t .Run ("ButtonsExist" , func (t * testing.T ) {
40+ session := loginUser (t , "user2" )
41+
42+ // test the "New PR" button
43+ req := NewRequest (t , "GET" , "/user2/repo1/pulls" )
44+ resp := session .MakeRequest (t , req , http .StatusOK )
45+ htmlDoc := NewHTMLParser (t , resp .Body )
46+ link , exists := htmlDoc .doc .Find (".new-pr-button" ).Attr ("href" )
47+ assert .True (t , exists , "The template has changed" )
48+ req = NewRequest (t , "GET" , link )
49+ resp = session .MakeRequest (t , req , http .StatusOK )
50+ assert .EqualValues (t , http .StatusOK , resp .Code )
51+
52+ // test the edit button in the PR diff view
53+ req = NewRequest (t , "GET" , "/user2/repo1/pulls/3/files" )
54+ resp = session .MakeRequest (t , req , http .StatusOK )
55+ doc := NewHTMLParser (t , resp .Body )
56+ editButtonCount := doc .doc .Find (".diff-file-header-actions a[href*='/_edit/']" ).Length ()
57+ assert .Positive (t , editButtonCount , "Expected to find a button to edit a file in the PR diff view but there were none" )
58+ })
4459
4560 onGiteaRun (t , func (t * testing.T , u * url.URL ) {
4661 defer tests .PrepareTestEnv (t )()
@@ -54,8 +69,8 @@ func TestPullCompare(t *testing.T) {
5469 repo1 := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {OwnerName : "user2" , Name : "repo1" })
5570 issueIndex := unittest .AssertExistsAndLoadBean (t , & issues_model.IssueIndex {GroupID : repo1 .ID }, unittest .OrderBy ("group_id ASC" ))
5671 prFilesURL := fmt .Sprintf ("/user2/repo1/pulls/%d/files" , issueIndex .MaxIndex )
57- req = NewRequest (t , "GET" , prFilesURL )
58- resp = session .MakeRequest (t , req , http .StatusOK )
72+ req : = NewRequest (t , "GET" , prFilesURL )
73+ resp : = session .MakeRequest (t , req , http .StatusOK )
5974 doc := NewHTMLParser (t , resp .Body )
6075 editButtonCount := doc .doc .Find (".diff-file-header-actions a[href*='/_edit/']" ).Length ()
6176 assert .Positive (t , editButtonCount , "Expected to find a button to edit a file in the PR diff view but there were none" )
0 commit comments