Skip to content

Commit a19d2bb

Browse files
authored
Add test for #30674 (#30679)
1 parent 3f19a63 commit a19d2bb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/integration/pull_compare_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ package integration
55

66
import (
77
"net/http"
8+
"net/url"
89
"testing"
910

11+
"code.gitea.io/gitea/models/db"
12+
repo_model "code.gitea.io/gitea/models/repo"
13+
"code.gitea.io/gitea/models/unittest"
14+
user_model "code.gitea.io/gitea/models/user"
15+
repo_service "code.gitea.io/gitea/services/repository"
1016
"code.gitea.io/gitea/tests"
1117

1218
"github.com/stretchr/testify/assert"
@@ -32,4 +38,33 @@ func TestPullCompare(t *testing.T) {
3238
doc := NewHTMLParser(t, resp.Body)
3339
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
3440
assert.Greater(t, editButtonCount, 0, "Expected to find a button to edit a file in the PR diff view but there were none")
41+
42+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
43+
defer tests.PrepareTestEnv(t)()
44+
45+
session := loginUser(t, "user1")
46+
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
47+
testCreateBranch(t, session, "user1", "repo1", "branch/master", "master1", http.StatusSeeOther)
48+
testEditFile(t, session, "user1", "repo1", "master1", "README.md", "Hello, World (Edited)\n")
49+
resp = testPullCreate(t, session, "user1", "repo1", false, "master", "master1", "This is a pull title")
50+
51+
// the max value on issue_index.yml for repo_id=1 is 5
52+
req = NewRequest(t, "GET", "/user2/repo1/pulls/6/files")
53+
resp = session.MakeRequest(t, req, http.StatusOK)
54+
doc := NewHTMLParser(t, resp.Body)
55+
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
56+
assert.Greater(t, editButtonCount, 0, "Expected to find a button to edit a file in the PR diff view but there were none")
57+
58+
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
59+
repoForked := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: "repo1"})
60+
// delete the head repository and revisit the PR diff view
61+
err := repo_service.DeleteRepositoryDirectly(db.DefaultContext, user2, repoForked.ID)
62+
assert.NoError(t, err)
63+
64+
req = NewRequest(t, "GET", "/user2/repo1/pulls/6/files")
65+
resp = session.MakeRequest(t, req, http.StatusOK)
66+
doc = NewHTMLParser(t, resp.Body)
67+
editButtonCount = doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
68+
assert.EqualValues(t, editButtonCount, 0, "Expected not to find a button to edit a file in the PR diff view because head repository has been deleted")
69+
})
3570
}

0 commit comments

Comments
 (0)