From f6599099eebb44c4e90d262f00ffa478f42a8f66 Mon Sep 17 00:00:00 2001 From: Kenneth Bruen Date: Tue, 29 Apr 2025 13:31:07 +0000 Subject: [PATCH] feat: add label for avatar settings (#7678) By redirecting the user to the settings when clicking on the avatar, it is not immediately obvious that the user has to scroll down the page to change their avatar. By adding an id to reference in the fragment, we fix this. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7678 Reviewed-by: Gusted Co-authored-by: Kenneth Bruen Co-committed-by: Kenneth Bruen --- templates/shared/user/profile_big_avatar.tmpl | 2 +- templates/user/settings/profile.tmpl | 2 +- tests/integration/user_avatar_test.go | 37 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/templates/shared/user/profile_big_avatar.tmpl b/templates/shared/user/profile_big_avatar.tmpl index d718fa390f..e14bd56a70 100644 --- a/templates/shared/user/profile_big_avatar.tmpl +++ b/templates/shared/user/profile_big_avatar.tmpl @@ -4,7 +4,7 @@
{{if eq .SignedUserID .ContextUser.ID}} - + {{/* the size doesn't take affect (and no need to take affect), image size(width) should be controlled by the parent container since this is not a flex layout*/}} {{ctx.AvatarUtils.Avatar .ContextUser 256}} diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 3bc8800a76..f0cbe12049 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -108,7 +108,7 @@
-

+

{{ctx.Locale.Tr "settings.avatar"}}

diff --git a/tests/integration/user_avatar_test.go b/tests/integration/user_avatar_test.go index c1b3a19a36..2d3fd0a7a9 100644 --- a/tests/integration/user_avatar_test.go +++ b/tests/integration/user_avatar_test.go @@ -10,6 +10,7 @@ import ( "io" "mime/multipart" "net/http" + "net/url" "testing" "forgejo.org/models/db" @@ -85,3 +86,39 @@ func TestUserAvatar(t *testing.T) { // Can't test if the response matches because the image is re-generated on upload but checking that this at least doesn't give a 404 should be enough. } + +func TestAvatarAnchorDestination(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + // If the user is logged in, and looking at their own profile, + // the avatar becomes a link towards the user settings page. + // Test that the link does not show up when not viewing one's own profile, + // and that, if the link does show up, there is a corresponding element + // on the user settings page matching the fragment of the anchor. + + t.Run("viewing other's profile", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + profilePage := NewHTMLParser(t, MakeRequest(t, NewRequest(t, "GET", "/user2"), http.StatusOK).Body) + profilePage.AssertElement(t, "#profile-avatar", true) + // When viewing another user's profile, there shouldn't be a link to user settings + profilePage.AssertElement(t, "#profile-avatar a", false) + }) + + t.Run("viewing own profile", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + session := loginUser(t, "user2") + + profilePage := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", "/user2"), http.StatusOK).Body) + profilePage.AssertElement(t, "#profile-avatar a", true) + href, has := profilePage.Find("#profile-avatar a").Attr("href") + assert.True(t, has) + + settingsURL, err := url.Parse(href) + require.NoError(t, err, "Change avatar link can't be parsed to URL") + + settingsPage := NewHTMLParser(t, session.MakeRequest(t, NewRequest(t, "GET", href), http.StatusOK).Body) + settingsPage.AssertElement(t, fmt.Sprintf("#%s", settingsURL.Fragment), true) + }) +}