loading up the forgejo repo on tangled to test page performance
1// Copyright 2024 The Gitea Authors. All rights reserved.
2// SPDX-License-Identifier: MIT
3
4package integration
5
6import (
7 "net/http"
8 "testing"
9
10 "forgejo.org/modules/setting"
11 "forgejo.org/modules/test"
12 "forgejo.org/tests"
13
14 "github.com/stretchr/testify/assert"
15)
16
17func TestExploreUser(t *testing.T) {
18 defer tests.PrepareTestEnv(t)()
19
20 // Set the default sort order
21 defer test.MockVariableValue(&setting.UI.ExploreDefaultSort, "reversealphabetically")()
22
23 cases := []struct{ sortOrder, expected string }{
24 {"", "?sort=" + setting.UI.ExploreDefaultSort + "&q="},
25 {"newest", "?sort=newest&q="},
26 {"oldest", "?sort=oldest&q="},
27 {"alphabetically", "?sort=alphabetically&q="},
28 {"reversealphabetically", "?sort=reversealphabetically&q="},
29 }
30 for _, c := range cases {
31 req := NewRequest(t, "GET", "/explore/users?sort="+c.sortOrder)
32 resp := MakeRequest(t, req, http.StatusOK)
33 h := NewHTMLParser(t, resp.Body)
34 href, _ := h.Find(`.ui.dropdown .menu a.active.item[href^="?sort="]`).Attr("href")
35 assert.Equal(t, c.expected, href)
36 }
37
38 // these sort orders shouldn't be supported, to avoid leaking user activity
39 cases404 := []string{
40 "/explore/users?sort=lastlogin",
41 "/explore/users?sort=reverselastlogin",
42 "/explore/users?sort=leastupdate",
43 "/explore/users?sort=reverseleastupdate",
44 }
45 for _, c := range cases404 {
46 req := NewRequest(t, "GET", c).SetHeader("Accept", "text/html")
47 MakeRequest(t, req, http.StatusNotFound)
48 }
49}