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