1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-01 17:38:33 +00:00

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) {

View file

@ -1,5 +1,5 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: GPL-3.0-or-later
package integration
@ -32,6 +32,7 @@ func TestUserProfileFollows(t *testing.T) {
followingLink := "#profile-avatar-card a[href='/user1?tab=following']"
listHeader := ".user-cards h2"
listItems := ".user-cards .list"
listMsg := ".user-cards > div"
// = No follows =
@ -44,7 +45,8 @@ func TestUserProfileFollows(t *testing.T) {
// Verify that user1 has no followers
testSelectorEquals(t, page, followersLink, "0 followers")
testSelectorEquals(t, page, listHeader, "Followers")
testListCount(t, page, listItems, followCount)
page.AssertElement(t, listItems, false)
page.AssertElement(t, listMsg, true)
// Request the profile of user1, the Following tab
response = user1.MakeRequest(t, NewRequest(t, "GET", "/user1?tab=following"), http.StatusOK)
@ -53,7 +55,8 @@ func TestUserProfileFollows(t *testing.T) {
// Verify that user1 does not follow anyone
testSelectorEquals(t, page, followingLink, "0 following")
testSelectorEquals(t, page, listHeader, "Following")
testListCount(t, page, listItems, followCount)
page.AssertElement(t, listItems, false)
page.AssertElement(t, listMsg, true)
// Make user1 and user2 follow each other
testUserFollowUser(t, user1, "user2")
@ -71,6 +74,7 @@ func TestUserProfileFollows(t *testing.T) {
testSelectorEquals(t, page, followersLink, "1 follower")
testSelectorEquals(t, page, listHeader, "Follower")
testListCount(t, page, listItems, followCount)
page.AssertElement(t, listMsg, false)
// Request the profile of user1, the Following tab
response = user1.MakeRequest(t, NewRequest(t, "GET", "/user1?tab=following"), http.StatusOK)
@ -80,6 +84,7 @@ func TestUserProfileFollows(t *testing.T) {
testSelectorEquals(t, page, followingLink, "1 following")
testSelectorEquals(t, page, listHeader, "Following")
testListCount(t, page, listItems, followCount)
page.AssertElement(t, listMsg, false)
// Make user1 and user3 follow each other
testUserFollowUser(t, user1, "user5")
@ -97,6 +102,7 @@ func TestUserProfileFollows(t *testing.T) {
testSelectorEquals(t, page, followersLink, "2 followers")
testSelectorEquals(t, page, listHeader, "Followers")
testListCount(t, page, listItems, followCount)
page.AssertElement(t, listMsg, false)
// Request the profile of user1, the Following tab
response = user1.MakeRequest(t, NewRequest(t, "GET", "/user1?tab=following"), http.StatusOK)
@ -106,6 +112,7 @@ func TestUserProfileFollows(t *testing.T) {
testSelectorEquals(t, page, followingLink, "2 following")
testSelectorEquals(t, page, listHeader, "Following")
testListCount(t, page, listItems, followCount)
page.AssertElement(t, listMsg, false)
}
// testUserFollowUser simply follows a user `following` by session of user `follower`