@@ -12,11 +12,14 @@ import (
12
12
"testing"
13
13
14
14
auth_model "code.gitea.io/gitea/models/auth"
15
+ "code.gitea.io/gitea/models/unittest"
16
+ user_model "code.gitea.io/gitea/models/user"
15
17
"code.gitea.io/gitea/modules/json"
16
18
"code.gitea.io/gitea/modules/setting"
17
19
api "code.gitea.io/gitea/modules/structs"
18
20
"code.gitea.io/gitea/tests"
19
21
22
+ "github.com/PuerkitoBio/goquery"
20
23
"github.com/stretchr/testify/assert"
21
24
)
22
25
@@ -35,6 +38,44 @@ func TestRepoCommits(t *testing.T) {
35
38
assert .NotEmpty (t , commitURL )
36
39
}
37
40
41
+ func Test_ReposGitCommitListNotMaster (t * testing.T ) {
42
+ defer tests .PrepareTestEnv (t )()
43
+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
44
+ // Login as User2.
45
+ session := loginUser (t , user .Name )
46
+
47
+ // Test getting commits (Page 1)
48
+ req := NewRequestf (t , "GET" , "/%s/repo16/commits/branch/master" , user .Name )
49
+ resp := session .MakeRequest (t , req , http .StatusOK )
50
+
51
+ doc := NewHTMLParser (t , resp .Body )
52
+ commits := []string {}
53
+ doc .doc .Find ("#commits-table .commit-id-short" ).Each (func (i int , s * goquery.Selection ) {
54
+ commitURL , exists := s .Attr ("href" )
55
+ assert .True (t , exists )
56
+ assert .NotEmpty (t , commitURL )
57
+ commits = append (commits , path .Base (commitURL ))
58
+ })
59
+
60
+ assert .Len (t , commits , 3 )
61
+ assert .EqualValues (t , "69554a64c1e6030f051e5c3f94bfbd773cd6a324" , commits [0 ])
62
+ assert .EqualValues (t , "27566bd5738fc8b4e3fef3c5e72cce608537bd95" , commits [1 ])
63
+ assert .EqualValues (t , "5099b81332712fe655e34e8dd63574f503f61811" , commits [2 ])
64
+
65
+ userNames := []string {}
66
+ doc .doc .Find ("#commits-table .author-wrapper" ).Each (func (i int , s * goquery.Selection ) {
67
+ userPath , exists := s .Attr ("href" )
68
+ assert .True (t , exists )
69
+ assert .NotEmpty (t , userPath )
70
+ userNames = append (userNames , path .Base (userPath ))
71
+ })
72
+
73
+ assert .Len (t , userNames , 3 )
74
+ assert .EqualValues (t , "User2" , userNames [0 ])
75
+ assert .EqualValues (t , "user21" , userNames [1 ])
76
+ assert .EqualValues (t , "User2" , userNames [2 ])
77
+ }
78
+
38
79
func doTestRepoCommitWithStatus (t * testing.T , state string , classes ... string ) {
39
80
defer tests .PrepareTestEnv (t )()
40
81
0 commit comments