@@ -5,8 +5,14 @@ package integration
5
5
6
6
import (
7
7
"net/http"
8
+ "net/url"
8
9
"testing"
9
10
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"
10
16
"code.gitea.io/gitea/tests"
11
17
12
18
"github.com/stretchr/testify/assert"
@@ -32,4 +38,33 @@ func TestPullCompare(t *testing.T) {
32
38
doc := NewHTMLParser (t , resp .Body )
33
39
editButtonCount := doc .doc .Find (".diff-file-header-actions a[href*='/_edit/']" ).Length ()
34
40
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
+ })
35
70
}
0 commit comments