mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-03-14 07:42:44 +00:00
feat(ui themes): better place for theme list ctx, testing (#7163)
`AllThemes` is only used by `user/settings/appearance.tmpl`, not by all settings pages. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7163 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
parent
30982b9e7b
commit
9cef129f6b
3 changed files with 50 additions and 1 deletions
|
@ -329,6 +329,7 @@ func Repos(ctx *context.Context) {
|
|||
func Appearance(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings.appearance")
|
||||
ctx.Data["PageIsSettingsAppearance"] = true
|
||||
ctx.Data["AllThemes"] = setting.UI.Themes
|
||||
|
||||
var hiddenCommentTypes *big.Int
|
||||
val, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes)
|
||||
|
|
|
@ -640,7 +640,7 @@ func registerRoutes(m *web.Route) {
|
|||
m.Post("/unblock", user_setting.UnblockUser)
|
||||
})
|
||||
m.Get("/storage_overview", user_setting.StorageOverview)
|
||||
}, reqSignIn, ctxDataSet("PageIsUserSettings", true, "AllThemes", setting.UI.Themes, "EnablePackages", setting.Packages.Enabled, "EnableQuota", setting.Quota.Enabled))
|
||||
}, reqSignIn, ctxDataSet("PageIsUserSettings", true, "EnablePackages", setting.Packages.Enabled, "EnableQuota", setting.Quota.Enabled))
|
||||
|
||||
m.Group("/user", func() {
|
||||
m.Get("/activate", auth.Activate)
|
||||
|
|
48
tests/integration/appearance_settings_test.go
Normal file
48
tests/integration/appearance_settings_test.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestThemeChange(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
user := loginUser(t, "user2")
|
||||
|
||||
testSelectedTheme(t, user, "forgejo-auto")
|
||||
|
||||
testChangeTheme(t, user, "forgejo-dark")
|
||||
testSelectedTheme(t, user, "forgejo-dark")
|
||||
}
|
||||
|
||||
// testSelectedTheme checks that the expected theme is used in html[data-theme]
|
||||
// and is default on appearance page
|
||||
func testSelectedTheme(t *testing.T, session *TestSession, expectedTheme string) {
|
||||
t.Helper()
|
||||
response := session.MakeRequest(t, NewRequest(t, "GET", "/user/settings/appearance"), http.StatusOK)
|
||||
page := NewHTMLParser(t, response.Body)
|
||||
|
||||
dataTheme, dataThemeExists := page.Find("html").Attr("data-theme")
|
||||
assert.True(t, dataThemeExists)
|
||||
assert.EqualValues(t, expectedTheme, dataTheme)
|
||||
|
||||
selectorTheme, selectorThemeExists := page.Find("form[action='/user/settings/appearance/theme'] input[name='theme']").Attr("value")
|
||||
assert.True(t, selectorThemeExists)
|
||||
assert.EqualValues(t, expectedTheme, selectorTheme)
|
||||
}
|
||||
|
||||
// testSelectedTheme changes user's theme
|
||||
func testChangeTheme(t *testing.T, session *TestSession, newTheme string) {
|
||||
t.Helper()
|
||||
session.MakeRequest(t, NewRequestWithValues(t, "POST", "/user/settings/appearance/theme", map[string]string{
|
||||
"_csrf": GetCSRF(t, session, "/user/settings/appearance"),
|
||||
"theme": newTheme,
|
||||
}), http.StatusSeeOther)
|
||||
}
|
Loading…
Reference in a new issue