mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-13 06:20:24 +00:00
Currently the dropdown component only supports having one `<summary>` and one `<ul>` (with interactive items) in it. This PR refactors it to add a `.content` container so that it is possible for the dropdown to contain things the more complex dropdowns do like `<hr>` and a searchbar. Also adds an `<hr>` to user actions as a little demo. Preview B: https://codeberg.org/attachments/8dfb98d2-52be-4c3c-8fc0-8fe470f34703 A: https://codeberg.org/attachments/53f2acfb-2e61-4420-b616-13d563f5c257 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9951 Reviewed-by: Otto <otto@codeberg.org>
84 lines
2.8 KiB
Go
84 lines
2.8 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"forgejo.org/modules/setting"
|
|
"forgejo.org/modules/test"
|
|
"forgejo.org/tests"
|
|
)
|
|
|
|
func TestUserProfileActions(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
admSel := `details.dropdown a[href^="/admin/users/"]`
|
|
blockSel := `details.dropdown button[hx-post$="?action=block"]`
|
|
reportSel := `details.dropdown a[href^="/report_abuse?type=user"]`
|
|
|
|
t.Run("Guest user", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
defer test.MockVariableValue(&setting.Moderation.Enabled, true)()
|
|
|
|
// Can't do much
|
|
page := NewHTMLParser(t, MakeRequest(t, NewRequest(t, "GET", "/user1"), http.StatusOK).Body)
|
|
page.AssertElement(t, admSel, false)
|
|
page.AssertElement(t, blockSel, false)
|
|
page.AssertElement(t, reportSel, false)
|
|
})
|
|
|
|
t.Run("User blocking", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
defer test.MockVariableValue(&setting.Moderation.Enabled, true)()
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
// Can block others
|
|
page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "/user1"), http.StatusOK).Body)
|
|
page.AssertElement(t, blockSel, true)
|
|
|
|
// Can't block self
|
|
page = NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "/user2"), http.StatusOK).Body)
|
|
page.AssertElement(t, blockSel, false)
|
|
})
|
|
|
|
// To decrease the amount of requests, admin and moderation assertions are squashed together
|
|
|
|
t.Run("Moderation enabled, user is admin", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
defer test.MockVariableValue(&setting.Moderation.Enabled, true)()
|
|
|
|
session := loginUser(t, "user1")
|
|
// The /admin/... link advertized to admins on all profiles
|
|
|
|
// Can report others
|
|
page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "/user2"), http.StatusOK).Body)
|
|
page.AssertElement(t, reportSel, true)
|
|
page.AssertElement(t, admSel, true)
|
|
|
|
// Can't report self
|
|
page = NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "/user1"), http.StatusOK).Body)
|
|
page.AssertElement(t, reportSel, false)
|
|
page.AssertElement(t, admSel, true)
|
|
})
|
|
|
|
t.Run("Moderation disabled, user isn't admin", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
defer test.MockVariableValue(&setting.Moderation.Enabled, false)()
|
|
|
|
session := loginUser(t, "user2")
|
|
// The /admin/... link is not advertized to non-admins
|
|
|
|
// Can report anyone
|
|
page := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "/user1"), http.StatusOK).Body)
|
|
page.AssertElement(t, reportSel, false)
|
|
page.AssertElement(t, admSel, false)
|
|
|
|
page = NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "/user2"), http.StatusOK).Body)
|
|
page.AssertElement(t, reportSel, false)
|
|
page.AssertElement(t, admSel, false)
|
|
})
|
|
}
|