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 'fix(UI): issue task list numbers, fix #4431' (#4452) from mahlzahn/forgejo:fix_issue_task_list_numbers_issue_4431 into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4452
Reviewed-by: Beowulf <beowulf@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>

+56 -7
+2 -2
models/issues/issue.go
··· 153 153 } 154 154 155 155 var ( 156 - issueTasksPat = regexp.MustCompile(`(^\s*[-*]\s\[[\sxX]\]\s.)|(\n\s*[-*]\s\[[\sxX]\]\s.)`) 157 - issueTasksDonePat = regexp.MustCompile(`(^\s*[-*]\s\[[xX]\]\s.)|(\n\s*[-*]\s\[[xX]\]\s.)`) 156 + issueTasksPat = regexp.MustCompile(`(^|\n)\s*[-*]\s*\[[\sxX]\]`) 157 + issueTasksDonePat = regexp.MustCompile(`(^|\n)\s*[-*]\s*\[[xX]\]`) 158 158 ) 159 159 160 160 // IssueIndex represents the issue index table
+52 -3
tests/integration/issue_test.go
··· 10 10 "net/http" 11 11 "net/url" 12 12 "path" 13 + "regexp" 13 14 "strconv" 14 15 "strings" 15 16 "testing" ··· 236 237 htmlDoc = NewHTMLParser(t, resp.Body) 237 238 val := htmlDoc.doc.Find("#issue-title-display").Text() 238 239 assert.Contains(t, val, title) 239 - val = htmlDoc.doc.Find(".comment .render-content p").First().Text() 240 - assert.Equal(t, content, val) 241 - 240 + // test for first line only and if it contains only letters and spaces 241 + contentFirstLine := strings.Split(content, "\n")[0] 242 + patNotLetterOrSpace := regexp.MustCompile(`[^\p{L}\s]`) 243 + if len(contentFirstLine) != 0 && !patNotLetterOrSpace.MatchString(contentFirstLine) { 244 + val = htmlDoc.doc.Find(".comment .render-content p").First().Text() 245 + assert.Equal(t, contentFirstLine, val) 246 + } 242 247 return issueURL 243 248 } 244 249 ··· 279 284 defer tests.PrepareTestEnv(t)() 280 285 session := loginUser(t, "user2") 281 286 testNewIssue(t, session, "user2", "repo1", "Title", "Description") 287 + } 288 + 289 + func TestIssueCheckboxes(t *testing.T) { 290 + defer tests.PrepareTestEnv(t)() 291 + session := loginUser(t, "user2") 292 + issueURL := testNewIssue(t, session, "user2", "repo1", "Title", `- [x] small x 293 + - [X] capital X 294 + - [ ] empty 295 + - [x]x without gap 296 + - [ ]empty without gap 297 + - [x] 298 + x on new line 299 + - [ ] 300 + empty on new line 301 + - [ ] tabs instead of spaces 302 + Description`) 303 + req := NewRequest(t, "GET", issueURL) 304 + resp := session.MakeRequest(t, req, http.StatusOK) 305 + issueContent := NewHTMLParser(t, resp.Body).doc.Find(".comment .render-content").First() 306 + isCheckBox := func(i int, s *goquery.Selection) bool { 307 + typeVal, typeExists := s.Attr("type") 308 + return typeExists && typeVal == "checkbox" 309 + } 310 + isChecked := func(i int, s *goquery.Selection) bool { 311 + _, checkedExists := s.Attr("checked") 312 + return checkedExists 313 + } 314 + checkBoxes := issueContent.Find("input").FilterFunction(isCheckBox) 315 + assert.Equal(t, 8, checkBoxes.Length()) 316 + assert.Equal(t, 4, checkBoxes.FilterFunction(isChecked).Length()) 317 + 318 + // Issues list should show the correct numbers of checked and total checkboxes 319 + repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1") 320 + assert.NoError(t, err) 321 + req = NewRequestf(t, "GET", "%s/issues", repo.Link()) 322 + resp = MakeRequest(t, req, http.StatusOK) 323 + 324 + htmlDoc := NewHTMLParser(t, resp.Body) 325 + issuesSelection := htmlDoc.Find("#issue-list .flex-item") 326 + assert.Equal(t, "4 / 8", strings.TrimSpace(issuesSelection.Find(".checklist").Text())) 327 + value, _ := issuesSelection.Find("progress").Attr("value") 328 + vmax, _ := issuesSelection.Find("progress").Attr("max") 329 + assert.Equal(t, "4", value) 330 + assert.Equal(t, "8", vmax) 282 331 } 283 332 284 333 func TestIssueDependencies(t *testing.T) {
+2 -2
web_src/js/markup/tasklist.js
··· 32 32 const buffer = encoder.encode(oldContent); 33 33 // Indexes may fall off the ends and return undefined. 34 34 if (buffer[position - 1] !== '['.codePointAt(0) || 35 - buffer[position] !== ' '.codePointAt(0) && buffer[position] !== 'x'.codePointAt(0) || 35 + buffer[position] !== ' '.codePointAt(0) && buffer[position] !== 'x'.codePointAt(0) && buffer[position] !== 'X'.codePointAt(0) || 36 36 buffer[position + 1] !== ']'.codePointAt(0)) { 37 37 // Position is probably wrong. Revert and don't allow change. 38 38 checkbox.checked = !checkbox.checked; 39 - throw new Error(`Expected position to be space or x and surrounded by brackets, but it's not: position=${position}`); 39 + throw new Error(`Expected position to be space, x or X and surrounded by brackets, but it's not: position=${position}`); 40 40 } 41 41 buffer.set(encoder.encode(checkboxCharacter), position); 42 42 const newContent = new TextDecoder().decode(buffer);