1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-22 08:42:32 -05:00

Merge pull request 'Add headers to follower lists' (#4174) from 0ko/forgejo:ui-profile-followers-title into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4174
Reviewed-by: Otto <otto@codeberg.org>
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-06-19 09:54:41 +00:00
commit d03a169dae
5 changed files with 142 additions and 4 deletions

View file

@ -655,6 +655,10 @@ change_avatar = Change your avatar…
joined_on = Joined on %s joined_on = Joined on %s
repositories = Repositories repositories = Repositories
activity = Public activity activity = Public activity
followers.title.one = Follower
followers.title.few = Followers
following.title.one = Following
following.title.few = Following
followers_one = %d follower followers_one = %d follower
followers_few = %d followers followers_few = %d followers
following_one = %d following following_one = %d following

View file

@ -183,9 +183,11 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
case "followers": case "followers":
ctx.Data["Cards"] = followers ctx.Data["Cards"] = followers
total = int(numFollowers) total = int(numFollowers)
ctx.Data["CardsTitle"] = ctx.TrN(total, "user.followers.title.one", "user.followers.title.few")
case "following": case "following":
ctx.Data["Cards"] = following ctx.Data["Cards"] = following
total = int(numFollowing) total = int(numFollowing)
ctx.Data["CardsTitle"] = ctx.TrN(total, "user.following.title.one", "user.following.title.few")
case "activity": case "activity":
date := ctx.FormString("date") date := ctx.FormString("date")
pagingNum = setting.UI.FeedPagingNum pagingNum = setting.UI.FeedPagingNum

View file

@ -1,8 +1,8 @@
<div class="user-cards"> <div class="user-cards">
{{if .CardsTitle}} {{if .CardsTitle}}
<h2 class="ui dividing header"> <h2 class="tw-mb-0">
{{.CardsTitle}} {{.CardsTitle}}
</h2> </h2>
{{end}} {{end}}
<ul class="list"> <ul class="list">
{{range .Cards}} {{range .Cards}}

View file

@ -0,0 +1,132 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"fmt"
"net/http"
"net/url"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
// TestUserProfileFollows is a test for user following counters, pages and titles.
// It tests that:
// - Followers and Following tabs always have titles present and always use correct plurals
// - Followers and Following lists have correct amounts of items
// - %d followers and %following counters are always present and always have correct numbers and use correct plurals
func TestUserProfileFollows(t *testing.T) {
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
// This test needs 3 users to check for all possible states
// The accounts of user3 and user4 are not functioning
user1 := loginUser(t, "user1")
user2 := loginUser(t, "user2")
user5 := loginUser(t, "user5")
followersLink := "#profile-avatar-card a[href='/user1?tab=followers']"
followingLink := "#profile-avatar-card a[href='/user1?tab=following']"
listHeader := ".user-cards h2"
listItems := ".user-cards .list"
// = No follows =
var followCount int
// Request the profile of user1, the Followers tab
response := user1.MakeRequest(t, NewRequest(t, "GET", "/user1?tab=followers"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
// Verify that user1 has no followers
testSelectorEquals(t, page, followersLink, "0 followers")
testSelectorEquals(t, page, listHeader, "Followers")
testListCount(t, page, listItems, followCount)
// Request the profile of user1, the Following tab
response = user1.MakeRequest(t, NewRequest(t, "GET", "/user1?tab=following"), http.StatusOK)
page = NewHTMLParser(t, response.Body)
// Verify that user1 does not follow anyone
testSelectorEquals(t, page, followingLink, "0 following")
testSelectorEquals(t, page, listHeader, "Following")
testListCount(t, page, listItems, followCount)
// Make user1 and user2 follow each other
testUserFollowUser(t, user1, "user2")
testUserFollowUser(t, user2, "user1")
// = 1 follow each =
followCount++
// Request the profile of user1, the Followers tab
response = user1.MakeRequest(t, NewRequest(t, "GET", "/user1?tab=followers"), http.StatusOK)
page = NewHTMLParser(t, response.Body)
// Verify it is now followed by 1 user
testSelectorEquals(t, page, followersLink, "1 follower")
testSelectorEquals(t, page, listHeader, "Follower")
testListCount(t, page, listItems, followCount)
// Request the profile of user1, the Following tab
response = user1.MakeRequest(t, NewRequest(t, "GET", "/user1?tab=following"), http.StatusOK)
page = NewHTMLParser(t, response.Body)
// Verify it now follows follows 1 user
testSelectorEquals(t, page, followingLink, "1 following")
testSelectorEquals(t, page, listHeader, "Following")
testListCount(t, page, listItems, followCount)
// Make user1 and user3 follow each other
testUserFollowUser(t, user1, "user5")
testUserFollowUser(t, user5, "user1")
// = 2 follows =
followCount++
// Request the profile of user1, the Followers tab
response = user1.MakeRequest(t, NewRequest(t, "GET", "/user1?tab=followers"), http.StatusOK)
page = NewHTMLParser(t, response.Body)
// Verify it is now followed by 2 users
testSelectorEquals(t, page, followersLink, "2 followers")
testSelectorEquals(t, page, listHeader, "Followers")
testListCount(t, page, listItems, followCount)
// Request the profile of user1, the Following tab
response = user1.MakeRequest(t, NewRequest(t, "GET", "/user1?tab=following"), http.StatusOK)
page = NewHTMLParser(t, response.Body)
// Verify it now follows follows 2 users
testSelectorEquals(t, page, followingLink, "2 following")
testSelectorEquals(t, page, listHeader, "Following")
testListCount(t, page, listItems, followCount)
})
}
// testUserFollowUser simply follows a user `following` by session of user `follower`
func testUserFollowUser(t *testing.T, follower *TestSession, following string) {
t.Helper()
follower.MakeRequest(t, NewRequestWithValues(t, "POST", fmt.Sprintf("/%s?action=follow", following),
map[string]string{
"_csrf": GetCSRF(t, follower, fmt.Sprintf("/%s", following)),
}), http.StatusOK)
}
// testSelectorEquals prevents duplication of a lot of code for tests with many checks
func testSelectorEquals(t *testing.T, page *HTMLDoc, selector, expectedContent string) {
t.Helper()
element := page.Find(selector)
content := strings.TrimSpace(element.Text())
assert.Equal(t, expectedContent, content)
}
// testListCount checks that the list on the page has the right amount of items
func testListCount(t *testing.T, page *HTMLDoc, selector string, expectedCount int) {
t.Helper()
itemCount := page.Find(selector).Children().Length()
assert.Equal(t, expectedCount, itemCount)
}

View file

@ -2106,7 +2106,7 @@ td .commit-summary {
padding: 0; padding: 0;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
margin-bottom: 10px; margin: 10px 0;
} }
.user-cards .list .item { .user-cards .list .item {