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) + }) +}