Skip to content

Commit 646d3cd

Browse files
committed
Add a test for repo commits list
1 parent ab62f4e commit 646d3cd

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/integration/repo_commits_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import (
1212
"testing"
1313

1414
auth_model "code.gitea.io/gitea/models/auth"
15+
"code.gitea.io/gitea/models/unittest"
16+
user_model "code.gitea.io/gitea/models/user"
1517
"code.gitea.io/gitea/modules/json"
1618
"code.gitea.io/gitea/modules/setting"
1719
api "code.gitea.io/gitea/modules/structs"
1820
"code.gitea.io/gitea/tests"
1921

22+
"github.com/PuerkitoBio/goquery"
2023
"github.com/stretchr/testify/assert"
2124
)
2225

@@ -35,6 +38,44 @@ func TestRepoCommits(t *testing.T) {
3538
assert.NotEmpty(t, commitURL)
3639
}
3740

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+
3879
func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
3980
defer tests.PrepareTestEnv(t)()
4081

0 commit comments

Comments
 (0)