1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-16 07:18:37 +00:00

Auto expand "New PR" form (#33971)

Follow GitHub's behavior: use `?expand=1` to expand the "New PR" form
This commit is contained in:
wxiaoguang
2025-03-24 22:28:02 +08:00
committed by GitHub
parent 25b6f38865
commit b1e326d09e
9 changed files with 62 additions and 41 deletions

View File

@@ -24,23 +24,38 @@ import (
func TestPullCompare(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
req := NewRequest(t, "GET", "/user2/repo1/pulls")
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
link, exists := htmlDoc.doc.Find(".new-pr-button").Attr("href")
assert.True(t, exists, "The template has changed")
t.Run("PullsNewRedirect", func(t *testing.T) {
req := NewRequest(t, "GET", "/user2/repo1/pulls/new/foo")
resp := MakeRequest(t, req, http.StatusSeeOther)
redirect := test.RedirectURL(resp)
assert.Equal(t, "/user2/repo1/compare/master...foo?expand=1", redirect)
req = NewRequest(t, "GET", link)
resp = session.MakeRequest(t, req, http.StatusOK)
assert.EqualValues(t, http.StatusOK, resp.Code)
req = NewRequest(t, "GET", "/user13/repo11/pulls/new/foo")
resp = MakeRequest(t, req, http.StatusSeeOther)
redirect = test.RedirectURL(resp)
assert.Equal(t, "/user12/repo10/compare/master...user13:foo?expand=1", redirect)
})
// test the edit button in the PR diff view
req = NewRequest(t, "GET", "/user2/repo1/pulls/3/files")
resp = session.MakeRequest(t, req, http.StatusOK)
doc := NewHTMLParser(t, resp.Body)
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
assert.Positive(t, editButtonCount, "Expected to find a button to edit a file in the PR diff view but there were none")
t.Run("ButtonsExist", func(t *testing.T) {
session := loginUser(t, "user2")
// test the "New PR" button
req := NewRequest(t, "GET", "/user2/repo1/pulls")
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
link, exists := htmlDoc.doc.Find(".new-pr-button").Attr("href")
assert.True(t, exists, "The template has changed")
req = NewRequest(t, "GET", link)
resp = session.MakeRequest(t, req, http.StatusOK)
assert.EqualValues(t, http.StatusOK, resp.Code)
// test the edit button in the PR diff view
req = NewRequest(t, "GET", "/user2/repo1/pulls/3/files")
resp = session.MakeRequest(t, req, http.StatusOK)
doc := NewHTMLParser(t, resp.Body)
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
assert.Positive(t, editButtonCount, "Expected to find a button to edit a file in the PR diff view but there were none")
})
onGiteaRun(t, func(t *testing.T, u *url.URL) {
defer tests.PrepareTestEnv(t)()
@@ -54,8 +69,8 @@ func TestPullCompare(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "repo1"})
issueIndex := unittest.AssertExistsAndLoadBean(t, &issues_model.IssueIndex{GroupID: repo1.ID}, unittest.OrderBy("group_id ASC"))
prFilesURL := fmt.Sprintf("/user2/repo1/pulls/%d/files", issueIndex.MaxIndex)
req = NewRequest(t, "GET", prFilesURL)
resp = session.MakeRequest(t, req, http.StatusOK)
req := NewRequest(t, "GET", prFilesURL)
resp := session.MakeRequest(t, req, http.StatusOK)
doc := NewHTMLParser(t, resp.Body)
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
assert.Positive(t, editButtonCount, "Expected to find a button to edit a file in the PR diff view but there were none")