forked from forgejo/forgejo
[GITEA] Only pass selected repository IDs to pagination
- Backport of https://codeberg.org/forgejo/forgejo/pulls/1848
- `ReposParam` is passed to the pagination as value for the `repos`
query. It should paginate to other pages with only the selected
repositories, which was currently not the case, but was already the case
for the links in the selectable items.
- Fix the wrong value being passed for issues/pulls lists.
- Fix the formatting of repository query value for milestones lists.
- Added integration testing.
- Resolves https://codeberg.org/forgejo/forgejo/issues/1836
(cherry picked from commit c648e5ab3a
)
This commit is contained in:
parent
272d0a4c20
commit
2552bb7b6e
2 changed files with 100 additions and 2 deletions
|
@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue