Files
gitea/tests/integration/setting_test.go
T
silverwind 055105d42f fix(web): match settings page titles to the UI (#40336)
Many settings pages had a generic or missing title, so browser tabs and
history named the wrong page. Titles now use the active sidebar label,
or the page header on sub-pages, and are set once where several handlers
render the same page. The user and org webhook list headers print the
title, so they now read "Webhooks" instead of "Settings".

| Page | Before | After |
| --- | --- | --- |
| Runners, secrets, Actions general, admin job queue | Actions |
Runners, Secrets, General, Job queue |
| User and org webhooks, org options, 2FA enroll, account and keys after
a form error | Settings | Webhooks, Organization, Enroll in Two-Factor
Authentication, Account, SSH / GPG Keys |
| Admin self check, OAuth2 app edit, repo public access, repo LFS
pointer files | (none), owner/repo | Self Check, Edit OAuth2
Application, Public Access, Find pointer files |
| Admin trace, new branch protection rule, package cleanup rules |
Monitoring, Branch Protection -, Packages | Trace, Add New Rule,
Add/Edit Cleanup Rule, Cleanup Rule Preview |
| Admin webhook add and edit | Add/Update Webhook | Add/Update System
Webhook, Add/Update Default Webhook |
| Sidebar on admin queue, admin webhook edit, user OAuth2 app edit | no
highlight | Queues, Webhooks, Applications |

Assisted-by: Claude Code:claude-opus-5-5
2026-11-17 02:41:49 +00:00

124 lines
3.9 KiB
Go

// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"net/http"
"strings"
"testing"
"gitea.dev/modules/setting"
"gitea.dev/modules/test"
"gitea.dev/tests"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
)
func TestSettingShowUserEmailExplore(t *testing.T) {
defer tests.PrepareTestEnv(t)()
defer test.MockVariableValue(&setting.UI.ShowUserEmail, true)()
session := loginUser(t, "user2")
req := NewRequest(t, "GET", "/explore/users?sort=alphabetically")
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
assert.Contains(t,
htmlDoc.doc.Find(".explore.users").Text(),
"user34@example.com",
)
setting.UI.ShowUserEmail = false
req = NewRequest(t, "GET", "/explore/users?sort=alphabetically")
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body)
assert.NotContains(t,
htmlDoc.doc.Find(".explore.users").Text(),
"user34@example.com",
)
}
func TestSettingShowUserEmailProfile(t *testing.T) {
defer tests.PrepareTestEnv(t)()
showUserEmail := setting.UI.ShowUserEmail
// user1: keep_email_private = false, user2: keep_email_private = true
var session *TestSession
for _, profile := range []struct {
login, name string
showEmail bool
visible bool
}{
// user1 can see own visible email
{"user1", "user1", true, true},
// user1 can not see user2's hidden email
// Should only contain if the user visits their own profile page
{"", "user2", true, false},
// user2 can see user1's visible email
{"user2", "user1", true, true},
// user2 can see own hidden email
{"user2", "user2", true, true},
// user1 can see own (now hidden) email
{"user1", "user1", false, true},
} {
setting.UI.ShowUserEmail = profile.showEmail
if profile.login != "" {
session = loginUser(t, profile.login)
}
req := NewRequest(t, "GET", "/"+profile.name)
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
if profile.visible {
assert.Contains(t, htmlDoc.doc.Find(".user.profile").Text(), profile.name+"@example.com")
} else {
assert.NotContains(t, htmlDoc.doc.Find(".user.profile").Text(), profile.name+"@example.com")
}
}
setting.UI.ShowUserEmail = showUserEmail
}
func TestSettingPageTitlesMatchNavbar(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user1")
for _, root := range []string{"/-/admin", "/user/settings", "/org/org3/settings", "/user2/repo2/settings"} {
resp := session.MakeRequest(t, NewRequest(t, "GET", root), http.StatusOK)
NewHTMLParser(t, resp.Body).Find(".flex-container-nav a.item").Each(func(_ int, link *goquery.Selection) {
href := link.AttrOr("href", "")
resp := session.MakeRequest(t, NewRequest(t, "GET", href), http.StatusOK)
page := NewHTMLParser(t, resp.Body)
pageTitle, _, _ := strings.Cut(page.Find("title").Text(), " - ")
assert.Equal(t, strings.TrimSpace(page.Find(".flex-container-nav a.active.item").Text()), pageTitle, href)
})
}
}
func TestSettingLandingPage(t *testing.T) {
defer tests.PrepareTestEnv(t)()
defer test.MockVariableValue(&setting.LandingPageURL)()
setting.LandingPageURL = setting.LandingPageHome
req := NewRequest(t, "GET", "/")
MakeRequest(t, req, http.StatusOK)
setting.LandingPageURL = setting.LandingPageExplore
req = NewRequest(t, "GET", "/")
resp := MakeRequest(t, req, http.StatusSeeOther)
assert.Equal(t, "/explore", resp.Header().Get("Location"))
setting.LandingPageURL = setting.LandingPageOrganizations
req = NewRequest(t, "GET", "/")
resp = MakeRequest(t, req, http.StatusSeeOther)
assert.Equal(t, "/explore/organizations", resp.Header().Get("Location"))
setting.LandingPageURL = setting.LandingPageLogin
req = NewRequest(t, "GET", "/")
resp = MakeRequest(t, req, http.StatusSeeOther)
assert.Equal(t, "/user/login", resp.Header().Get("Location"))
}