feat(ui): messages for empty usercards (#7947)

Show a message about list being empty, so the page doesn't look broken-ish empty.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7947
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: 0ko <0ko@noreply.codeberg.org>
Co-committed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
0ko 2025-05-23 23:34:40 +02:00 committed by Otto
parent 2b30c83a0c
commit 765e7bd1b6
6 changed files with 74 additions and 30 deletions

View file

@ -17,7 +17,7 @@ import (
"github.com/stretchr/testify/assert"
)
func testRepoStarringOrWatching(t *testing.T, action, listURI string) {
func testRepoStarringOrWatching(t *testing.T, action, listURI string, expectEmpty bool) {
t.Helper()
defer tests.PrepareTestEnv(t)()
@ -50,6 +50,12 @@ func testRepoStarringOrWatching(t *testing.T, action, listURI string) {
htmlDoc = NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, ".user-cards .list .card > a[href='/user5']", true)
if expectEmpty {
// Verify which user-cards elements are present
htmlDoc.AssertElement(t, ".user-cards > .list", true)
htmlDoc.AssertElement(t, ".user-cards > div", false)
}
// Unstar/unwatch the repo as user5
req = NewRequestWithValues(t, "POST", fmt.Sprintf("/user2/repo1/action/%s", oppositeAction), map[string]string{
"_csrf": GetCSRF(t, session, "/user2/repo1"),
@ -73,15 +79,22 @@ func testRepoStarringOrWatching(t *testing.T, action, listURI string) {
// Verify that "user5" is not among the stargazers/watchers
htmlDoc = NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, ".user-cards .list .item.ui.segment > a[href='/user5']", false)
htmlDoc.AssertElement(t, ".user-cards .list .item.ui.segment > a[href='/user2']", false)
if expectEmpty {
// Verify which user-cards elements are present
htmlDoc.AssertElement(t, ".user-cards > .list", false)
htmlDoc.AssertElement(t, ".user-cards > div", true)
}
}
func TestRepoStarUnstarUI(t *testing.T) {
testRepoStarringOrWatching(t, "star", "stars")
testRepoStarringOrWatching(t, "star", "stars", true)
}
func TestRepoWatchUnwatchUI(t *testing.T) {
testRepoStarringOrWatching(t, "watch", "watchers")
testRepoStarringOrWatching(t, "watch", "watchers", false)
// Empty list state is not checked because repo is watched by many users
}
func TestDisabledStars(t *testing.T) {