gitea源码

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