Fix the Fork button in repo headers
In #2445, I lifted out the fork button into its own template, but did not update it properly. This resulted in the fork button's counter not displaying, and pointing to the wrong place too. This patch updates the template to account for it moving to a separate file, and also adds test cases to verify the button is display as it should be. Fixes #2494. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
parent
e6f1863476
commit
aef0b024b7
|
@ -1,3 +1,4 @@
|
||||||
|
{{with .Repository}}
|
||||||
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
|
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
|
||||||
<div class="ui labeled button
|
<div class="ui labeled button
|
||||||
{{if or (not $.IsSigned) (and (not $.CanSignedUserFork) (not $.UserAndOrgForks))}}
|
{{if or (not $.IsSigned) (and (not $.CanSignedUserFork) (not $.UserAndOrgForks))}}
|
||||||
|
@ -48,3 +49,4 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -124,6 +125,44 @@ func TestRepoFork(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("fork button", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", "/user2/repo1/issues")
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
|
forkButton := htmlDoc.Find("a[href*='/forks']")
|
||||||
|
assert.EqualValues(t, 1, forkButton.Length())
|
||||||
|
|
||||||
|
href, _ := forkButton.Attr("href")
|
||||||
|
assert.Equal(t, "/user2/repo1/forks", href)
|
||||||
|
assert.Equal(t, "0", strings.TrimSpace(forkButton.Text()))
|
||||||
|
|
||||||
|
t.Run("no fork button on empty repo", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
// Create an empty repository
|
||||||
|
repo, err := repo_service.CreateRepository(db.DefaultContext, user5, user5, repo_service.CreateRepoOptions{
|
||||||
|
Name: "empty-repo",
|
||||||
|
AutoInit: false,
|
||||||
|
})
|
||||||
|
defer func() {
|
||||||
|
repo_service.DeleteRepository(db.DefaultContext, user5, repo, false)
|
||||||
|
}()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotEmpty(t, repo)
|
||||||
|
|
||||||
|
// Load the repository home view
|
||||||
|
req := NewRequest(t, "GET", repo.HTMLURL())
|
||||||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
|
// On an empty repo, the fork button is not present
|
||||||
|
htmlDoc.AssertElement(t, ".basic.button[href*='/fork']", false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("DISABLE_FORKS", func(t *testing.T) {
|
t.Run("DISABLE_FORKS", func(t *testing.T) {
|
||||||
defer test.MockVariableValue(&setting.Repository.DisableForks, true)()
|
defer test.MockVariableValue(&setting.Repository.DisableForks, true)()
|
||||||
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
defer test.MockVariableValue(&testWebRoutes, routers.NormalRoutes())()
|
||||||
|
|
Loading…
Reference in a new issue