You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.7 KiB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/modules/setting"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestSettingShowUserEmailExplore(t *testing.T) {
  12. prepareTestEnv(t)
  13. showUserEmail := setting.UI.ShowUserEmail
  14. setting.UI.ShowUserEmail = true
  15. session := loginUser(t, "user2")
  16. req := NewRequest(t, "GET", "/explore/users")
  17. resp := session.MakeRequest(t, req, http.StatusOK)
  18. htmlDoc := NewHTMLParser(t, resp.Body)
  19. assert.Contains(t,
  20. htmlDoc.doc.Find(".ui.user.list").Text(),
  21. "user2@example.com",
  22. )
  23. setting.UI.ShowUserEmail = false
  24. req = NewRequest(t, "GET", "/explore/users")
  25. resp = session.MakeRequest(t, req, http.StatusOK)
  26. htmlDoc = NewHTMLParser(t, resp.Body)
  27. assert.NotContains(t,
  28. htmlDoc.doc.Find(".ui.user.list").Text(),
  29. "user2@example.com",
  30. )
  31. setting.UI.ShowUserEmail = showUserEmail
  32. }
  33. func TestSettingShowUserEmailProfile(t *testing.T) {
  34. prepareTestEnv(t)
  35. showUserEmail := setting.UI.ShowUserEmail
  36. setting.UI.ShowUserEmail = true
  37. session := loginUser(t, "user2")
  38. req := NewRequest(t, "GET", "/user2")
  39. resp := session.MakeRequest(t, req, http.StatusOK)
  40. htmlDoc := NewHTMLParser(t, resp.Body)
  41. assert.Contains(t,
  42. htmlDoc.doc.Find(".user.profile").Text(),
  43. "user2@example.com",
  44. )
  45. setting.UI.ShowUserEmail = false
  46. req = NewRequest(t, "GET", "/user2")
  47. resp = session.MakeRequest(t, req, http.StatusOK)
  48. htmlDoc = NewHTMLParser(t, resp.Body)
  49. assert.NotContains(t,
  50. htmlDoc.doc.Find(".user.profile").Text(),
  51. "user2@example.com",
  52. )
  53. setting.UI.ShowUserEmail = showUserEmail
  54. }