fix: set explore pages to configurable default sort (#6708)

- Currently, the explore/organizations page always defaults to using "newest" as its sort. Instead, use the pre-existing config option (`setting.UI.ExploreDefaultSort`) so server administrators can change the default sort order.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6708
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: John Moon <john.moon@vts-i.com>
Co-committed-by: John Moon <john.moon@vts-i.com>
This commit is contained in:
John Moon 2025-01-31 10:38:03 +00:00 committed by David Rotermund
parent c5314ee364
commit d423dbac1a
4 changed files with 65 additions and 3 deletions

View file

@ -7,6 +7,8 @@ import (
"net/http"
"testing"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert"
@ -15,8 +17,11 @@ import (
func TestExploreUser(t *testing.T) {
defer tests.PrepareTestEnv(t)()
// Set the default sort order
defer test.MockVariableValue(&setting.UI.ExploreDefaultSort, "reversealphabetically")()
cases := []struct{ sortOrder, expected string }{
{"", "?sort=newest&q="},
{"", "?sort=" + setting.UI.ExploreDefaultSort + "&q="},
{"newest", "?sort=newest&q="},
{"oldest", "?sort=oldest&q="},
{"alphabetically", "?sort=alphabetically&q="},