loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'Clarify author label in tooltip' (#4201) from 0ko/forgejo:ui-author-tooltip into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4201
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>

+156 -6
+2 -1
options/locale/locale_en-US.ini
··· 1618 1618 issues.ref_reopened_from = `<a href="%[3]s">reopened this issue %[4]s</a> <a id="%[1]s" href="#%[1]s">%[2]s</a>` 1619 1619 issues.ref_from = `from %[1]s` 1620 1620 issues.author = Author 1621 - issues.author_helper = This user is the author. 1621 + issues.author.tooltip.issue = This user is the author of this issue. 1622 + issues.author.tooltip.pr = This user is the author of this pull request. 1622 1623 issues.role.owner = Owner 1623 1624 issues.role.owner_helper = This user is the owner of this repository. 1624 1625 issues.role.member = Member
+1
release-notes/8.0.0/4201.md
··· 1 + Make tooltip of Author label in comments more clear
+1 -1
templates/repo/issue/view_content.tmpl
··· 44 44 {{end}} 45 45 </div> 46 46 <div class="comment-header-right actions tw-flex tw-items-center"> 47 - {{template "repo/issue/view_content/show_role" dict "ShowRole" .Issue.ShowRole "IgnorePoster" true}} 47 + {{template "repo/issue/view_content/show_role" dict "ShowRole" .Issue.ShowRole "IgnorePoster" true "IsPull" .Issue.IsPull}} 48 48 {{if not $.Repository.IsArchived}} 49 49 {{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index)}} 50 50 {{end}}
+2 -2
templates/repo/issue/view_content/comments.tmpl
··· 51 51 {{end}} 52 52 </div> 53 53 <div class="comment-header-right actions tw-flex tw-items-center"> 54 - {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}} 54 + {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole "IsPull" .Issue.IsPull}} 55 55 {{if not $.Repository.IsArchived}} 56 56 {{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}} 57 57 {{end}} ··· 425 425 </span> 426 426 </div> 427 427 <div class="comment-header-right actions tw-flex tw-items-center"> 428 - {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}} 428 + {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole "IsPull" .Issue.IsPull}} 429 429 {{if not $.Repository.IsArchived}} 430 430 {{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}} 431 431 {{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" false "issue" true "diff" false "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
+1 -1
templates/repo/issue/view_content/conversation.tmpl
··· 77 77 </span> 78 78 </div> 79 79 <div class="comment-header-right actions tw-flex tw-items-center"> 80 - {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole}} 80 + {{template "repo/issue/view_content/show_role" dict "ShowRole" .ShowRole "IsPull" .Issue.IsPull}} 81 81 {{if not $.Repository.IsArchived}} 82 82 {{template "repo/issue/view_content/add_reaction" dict "ctxData" $ "ActionURL" (printf "%s/comments/%d/reactions" $.RepoLink .ID)}} 83 83 {{template "repo/issue/view_content/context_menu" dict "ctxData" $ "item" . "delete" true "issue" true "diff" true "IsCommentPoster" (and $.IsSigned (eq $.SignedUserID .PosterID))}}
+6 -1
templates/repo/issue/view_content/show_role.tmpl
··· 1 1 {{if and .ShowRole.IsPoster (not .IgnorePoster)}} 2 - <div class="ui basic label role-label" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.author_helper"}}"> 2 + <div class="ui basic label role-label" data-tooltip-content=" 3 + {{if .IsPull}} 4 + {{ctx.Locale.Tr "repo.issues.author.tooltip.pr"}} 5 + {{else}} 6 + {{ctx.Locale.Tr "repo.issues.author.tooltip.issue"}} 7 + {{end}}"> 3 8 {{ctx.Locale.Tr "repo.issues.author"}} 4 9 </div> 5 10 {{end}}
+143
tests/integration/issues_comment_labels_test.go
··· 1 + // Copyright 2024 The Forgejo Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package integration 5 + 6 + import ( 7 + "net/http" 8 + "net/url" 9 + "path" 10 + "strings" 11 + "testing" 12 + 13 + "github.com/PuerkitoBio/goquery" 14 + "github.com/stretchr/testify/assert" 15 + ) 16 + 17 + // TestIssuesCommentLabels is a test for user (role) labels in comment headers in PRs and issues. 18 + // It covers a few labels and combinations. 19 + func TestIssuesCommentLabels(t *testing.T) { 20 + onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { 21 + user := "user2" 22 + repo := "repo1" 23 + compareLink := path.Join(user, repo, "compare", "master...comment-labels") 24 + sessionUser1 := loginUser(t, "user1") 25 + sessionUser2 := loginUser(t, "user2") 26 + sessionUser5 := loginUser(t, "user5") 27 + 28 + ownerTooltip := "This user is the owner of this repository." 29 + authorTooltipPR := "This user is the author of this pull request." 30 + authorTooltipIssue := "This user is the author of this issue." 31 + firstTooltip := "This is the first contribution of this user to the repository." 32 + 33 + // Open a new PR as user2 34 + testEditFileToNewBranch(t, sessionUser2, user, repo, "master", "comment-labels", "README.md", "test of comment labels") 35 + sessionUser2.MakeRequest(t, NewRequestWithValues(t, "POST", compareLink, 36 + map[string]string{ 37 + "_csrf": GetCSRF(t, sessionUser2, compareLink), 38 + "title": "Pull used for testing commit labels", 39 + }, 40 + ), http.StatusOK) 41 + 42 + // Pull number, expected to be 6 43 + testID := "6" 44 + // Add a few comments 45 + // (first: Owner) 46 + testEasyLeavePRComment(t, sessionUser2, user, repo, testID, "New comment from user2 on this PR") // Author, Owner 47 + testEasyLeavePRComment(t, sessionUser1, user, repo, testID, "New comment from user1 on this PR") // First-time contributor 48 + testEasyLeavePRComment(t, sessionUser5, user, repo, testID, "New comment from user5 on this PR") // no labels 49 + 50 + // Fetch the PR page 51 + response := sessionUser2.MakeRequest(t, NewRequest(t, "GET", path.Join(user, repo, "pulls", testID)), http.StatusOK) 52 + page := NewHTMLParser(t, response.Body) 53 + commentHeads := page.Find(".timeline .comment .comment-header .comment-header-right") 54 + assert.EqualValues(t, 4, commentHeads.Length()) 55 + 56 + // Test the first comment and it's label "Owner" 57 + labels := commentHeads.Eq(0).Find(".role-label") 58 + assert.EqualValues(t, 1, labels.Length()) 59 + testIssueCommentUserLabel(t, labels.Eq(0), "Owner", ownerTooltip) 60 + 61 + // Test the second comment and it's labels "Author" and "Owner" 62 + labels = commentHeads.Eq(1).Find(".role-label") 63 + assert.EqualValues(t, 2, labels.Length()) 64 + testIssueCommentUserLabel(t, labels.Eq(0), "Author", authorTooltipPR) 65 + testIssueCommentUserLabel(t, labels.Eq(1), "Owner", ownerTooltip) 66 + 67 + // Test the third comment and it's label "First-time contributor" 68 + labels = commentHeads.Eq(3).Find(".role-label") 69 + assert.EqualValues(t, 1, labels.Length()) 70 + testIssueCommentUserLabel(t, labels.Eq(0), "First-time contributor", firstTooltip) 71 + 72 + // Test the fourth comment and it's lack of labels 73 + labels = commentHeads.Eq(4).Find(".role-label") 74 + assert.EqualValues(t, 0, labels.Length()) 75 + 76 + // Open a new issue in the same repo 77 + sessionUser2.MakeRequest(t, NewRequestWithValues(t, "POST", path.Join(user, repo, "issues/new"), 78 + map[string]string{ 79 + "_csrf": GetCSRF(t, sessionUser2, compareLink), 80 + "title": "Issue used for testing commit labels", 81 + }, 82 + ), http.StatusOK) 83 + 84 + // Issue number, expected to be 7 after the PR 85 + testID = "7" 86 + // Add a few comments 87 + // (first: Owner) 88 + testEasyLeaveIssueComment(t, sessionUser2, user, repo, testID, "New comment from user2 on this issue") // Author, Owner 89 + testEasyLeaveIssueComment(t, sessionUser5, user, repo, testID, "New comment from user5 on this issue") // no labels 90 + 91 + // Fetch the issue page 92 + response = sessionUser2.MakeRequest(t, NewRequest(t, "GET", path.Join(user, repo, "issues", testID)), http.StatusOK) 93 + page = NewHTMLParser(t, response.Body) 94 + commentHeads = page.Find(".timeline .comment .comment-header .comment-header-right") 95 + assert.EqualValues(t, 3, commentHeads.Length()) 96 + 97 + // Test the first comment and it's label "Owner" 98 + labels = commentHeads.Eq(0).Find(".role-label") 99 + assert.EqualValues(t, 1, labels.Length()) 100 + testIssueCommentUserLabel(t, labels.Eq(0), "Owner", ownerTooltip) 101 + 102 + // Test the second comment and it's labels "Author" and "Owner" 103 + labels = commentHeads.Eq(1).Find(".role-label") 104 + assert.EqualValues(t, 2, labels.Length()) 105 + testIssueCommentUserLabel(t, labels.Eq(0), "Author", authorTooltipIssue) 106 + testIssueCommentUserLabel(t, labels.Eq(1), "Owner", ownerTooltip) 107 + 108 + // Test the third comment and it's lack of labels 109 + labels = commentHeads.Eq(3).Find(".role-label") 110 + assert.EqualValues(t, 0, labels.Length()) 111 + }) 112 + } 113 + 114 + // testIssueCommentUserLabel is used to verify properties of a user label from a comment 115 + func testIssueCommentUserLabel(t *testing.T, label *goquery.Selection, expectedTitle, expectedTooltip string) { 116 + t.Helper() 117 + title := label.Text() 118 + tooltip, exists := label.Attr("data-tooltip-content") 119 + assert.True(t, exists) 120 + assert.EqualValues(t, expectedTitle, strings.TrimSpace(title)) 121 + assert.EqualValues(t, expectedTooltip, strings.TrimSpace(tooltip)) 122 + } 123 + 124 + // testEasyLeaveIssueComment is used to create a comment on an issue with minimum code and parameters 125 + func testEasyLeaveIssueComment(t *testing.T, session *TestSession, user, repo, id, message string) { 126 + t.Helper() 127 + session.MakeRequest(t, NewRequestWithValues(t, "POST", path.Join(user, repo, "issues", id, "comments"), map[string]string{ 128 + "_csrf": GetCSRF(t, session, path.Join(user, repo, "issues", id)), 129 + "content": message, 130 + "status": "", 131 + }), 200) 132 + } 133 + 134 + // testEasyLeaveIssueComment is used to create a comment on a pull request with minimum code and parameters 135 + // The POST request is supposed to use "issues" in the path. The CSRF is supposed to be generated for the PR page. 136 + func testEasyLeavePRComment(t *testing.T, session *TestSession, user, repo, id, message string) { 137 + t.Helper() 138 + session.MakeRequest(t, NewRequestWithValues(t, "POST", path.Join(user, repo, "issues", id, "comments"), map[string]string{ 139 + "_csrf": GetCSRF(t, session, path.Join(user, repo, "pulls", id)), 140 + "content": message, 141 + "status": "", 142 + }), 200) 143 + }