Merge pull request '[GITEA] Only pass selected repository IDs to pagination' (#1865) from Gusted/forgejo:forgejo-bp-1848 into v1.21/forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1865
This commit is contained in:
Gusted 2023-12-01 22:30:27 +00:00
commit 4de2148ae4
2 changed files with 100 additions and 2 deletions

View file

@ -315,9 +315,18 @@ func Milestones(ctx *context.Context) {
ctx.Data["RepoIDs"] = repoIDs
ctx.Data["IsShowClosed"] = isShowClosed
// Convert []int64 to string
reposParam, err := json.Marshal(repoIDs)
if err != nil {
ctx.ServerError("json.Marshal", err)
return
}
ctx.Data["ReposParam"] = string(reposParam)
pager := context.NewPagination(pagerCount, setting.UI.IssuePagingNum, page, 5)
pager.AddParam(ctx, "q", "Keyword")
pager.AddParam(ctx, "repos", "RepoIDs")
pager.AddParam(ctx, "repos", "ReposParam")
pager.AddParam(ctx, "sort", "SortType")
pager.AddParam(ctx, "state", "State")
ctx.Data["Page"] = pager
@ -690,7 +699,11 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
}
// Convert []int64 to string
reposParam, _ := json.Marshal(opts.RepoIDs)
reposParam, err := json.Marshal(selectedRepoIDs)
if err != nil {
ctx.ServerError("json.Marshal", err)
return
}
ctx.Data["ReposParam"] = string(reposParam)

View file

@ -4,7 +4,9 @@
package integration
import (
"fmt"
"net/http"
"net/url"
"testing"
auth_model "code.gitea.io/gitea/models/auth"
@ -297,3 +299,86 @@ func TestUserLocationMapLink(t *testing.T) {
htmlDoc := NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, `a[href="https://example/foo/A%2Fb"]`, true)
}
func TestPagination(t *testing.T) {
defer tests.PrepareTestEnv(t)()
// Force pagination to almost always happen.
defer test.MockVariableValue(&setting.UI.IssuePagingNum, 1)()
session := loginUser(t, "user2")
// Pagination links can be seen multiple times, due to 'last' or 'next' having
// the same link, so take that into consideration when writing asserts.
t.Run("Issues", func(t *testing.T) {
t.Run("No selected repositories", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
req := NewRequest(t, "GET", "/issues")
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
sel := htmlDoc.Find(`.pagination a.navigation[href="/issues?page=2&q=&type=your_repositories&repos=%5B%5D&sort=recentupdate&state=open&labels="]`)
assert.GreaterOrEqual(t, sel.Length(), 1)
})
t.Run("Selected repositories", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
escapedQuery := url.QueryEscape("[3,5]")
req := NewRequest(t, "GET", "/issues?repos="+escapedQuery)
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
sel := htmlDoc.Find(fmt.Sprintf(`.pagination a.navigation[href="/issues?page=2&q=&type=your_repositories&repos=%s&sort=recentupdate&state=open&labels="]`, escapedQuery))
assert.GreaterOrEqual(t, sel.Length(), 1)
})
})
t.Run("Pulls", func(t *testing.T) {
t.Run("No selected repositories", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
req := NewRequest(t, "GET", "/pulls")
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
sel := htmlDoc.Find(`.pagination a.navigation[href="/pulls?page=2&q=&type=your_repositories&repos=%5B%5D&sort=recentupdate&state=open&labels="]`)
assert.GreaterOrEqual(t, sel.Length(), 1)
})
t.Run("Selected repositories", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
escapedQuery := url.QueryEscape("[1,3]")
req := NewRequest(t, "GET", "/pulls?repos="+escapedQuery)
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
sel := htmlDoc.Find(fmt.Sprintf(`.pagination a.navigation[href="/pulls?page=2&q=&type=your_repositories&repos=%s&sort=recentupdate&state=open&labels="]`, escapedQuery))
assert.GreaterOrEqual(t, sel.Length(), 1)
})
})
t.Run("Milestones", func(t *testing.T) {
t.Run("No selected repositories", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
escapedQuery := url.QueryEscape("[42,1]")
req := NewRequest(t, "GET", "/milestones")
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
sel := htmlDoc.Find(fmt.Sprintf(`.pagination a.navigation[href="/milestones?page=2&q=&repos=%s&sort=&state=open"]`, escapedQuery))
assert.GreaterOrEqual(t, sel.Length(), 1)
})
t.Run("Selected repositories", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
escapedQuery := url.QueryEscape("[1]")
req := NewRequest(t, "GET", "/milestones?repos="+escapedQuery)
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
sel := htmlDoc.Find(fmt.Sprintf(`.pagination a.navigation[href="/milestones?page=2&q=&repos=%s&sort=&state=open"]`, escapedQuery))
assert.GreaterOrEqual(t, sel.Length(), 1)
})
})
}