Merge pull request 'Fix the Fork button in repo headers' (#2495) from algernon/forgejo:b/fork-button-fix into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2495 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
b678123de8
2 changed files with 41 additions and 0 deletions
|
@ -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