From b222c48060e64a209e5f91ff2cda78c158fe0fb8 Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 11 Jul 2024 18:27:48 +0200 Subject: [PATCH 1/9] fix counting of all / done issue tasks, fix #4431 --- models/issues/issue.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/issues/issue.go b/models/issues/issue.go index f04a4ad5c..9a3e0e791 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -153,8 +153,8 @@ type Issue struct { } var ( - issueTasksPat = regexp.MustCompile(`(^\s*[-*]\s\[[\sxX]\]\s.)|(\n\s*[-*]\s\[[\sxX]\]\s.)`) - issueTasksDonePat = regexp.MustCompile(`(^\s*[-*]\s\[[xX]\]\s.)|(\n\s*[-*]\s\[[xX]\]\s.)`) + issueTasksPat = regexp.MustCompile(`(^\s*[-*]\s*\[[\sxX]\].)|(\n\s*[-*]\s*\[[\sxX]\].)`) + issueTasksDonePat = regexp.MustCompile(`(^\s*[-*]\s*\[[xX]\].)|(\n\s*[-*]\s*\[[xX]\].)`) ) // IssueIndex represents the issue index table From a96b86778faa30daeddd76ab75ebe76ea276d0af Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 11 Jul 2024 18:32:52 +0200 Subject: [PATCH 2/9] fix unchecking check boxes like [X] --- web_src/js/markup/tasklist.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/markup/tasklist.js b/web_src/js/markup/tasklist.js index a40b5e4ab..375810dc2 100644 --- a/web_src/js/markup/tasklist.js +++ b/web_src/js/markup/tasklist.js @@ -32,11 +32,11 @@ export function initMarkupTasklist() { const buffer = encoder.encode(oldContent); // Indexes may fall off the ends and return undefined. if (buffer[position - 1] !== '['.codePointAt(0) || - buffer[position] !== ' '.codePointAt(0) && buffer[position] !== 'x'.codePointAt(0) || + buffer[position] !== ' '.codePointAt(0) && buffer[position] !== 'x'.codePointAt(0) && buffer[position] !== 'X'.codePointAt(0) || buffer[position + 1] !== ']'.codePointAt(0)) { // Position is probably wrong. Revert and don't allow change. checkbox.checked = !checkbox.checked; - throw new Error(`Expected position to be space or x and surrounded by brackets, but it's not: position=${position}`); + throw new Error(`Expected position to be space, x or X and surrounded by brackets, but it's not: position=${position}`); } buffer.set(encoder.encode(checkboxCharacter), position); const newContent = new TextDecoder().decode(buffer); From 9f461e180a8ee51bfe17c1bf6a9df03d68b7856d Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 11 Jul 2024 18:54:44 +0200 Subject: [PATCH 3/9] remove requirement on trailing character after check box --- models/issues/issue.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/issues/issue.go b/models/issues/issue.go index 9a3e0e791..34ece540e 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -153,8 +153,8 @@ type Issue struct { } var ( - issueTasksPat = regexp.MustCompile(`(^\s*[-*]\s*\[[\sxX]\].)|(\n\s*[-*]\s*\[[\sxX]\].)`) - issueTasksDonePat = regexp.MustCompile(`(^\s*[-*]\s*\[[xX]\].)|(\n\s*[-*]\s*\[[xX]\].)`) + issueTasksPat = regexp.MustCompile(`(^\s*[-*]\s*\[[\sxX]\])|(\n\s*[-*]\s*\[[\sxX]\])`) + issueTasksDonePat = regexp.MustCompile(`(^\s*[-*]\s*\[[xX]\])|(\n\s*[-*]\s*\[[xX]\])`) ) // IssueIndex represents the issue index table From b2bbf48c18d565d02bc59252a35047b4ec3b9d30 Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 25 Jul 2024 00:42:05 +0200 Subject: [PATCH 4/9] simplify regex for checkbox detection --- models/issues/issue.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/issues/issue.go b/models/issues/issue.go index 34ece540e..f7379b7e0 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -153,8 +153,8 @@ type Issue struct { } var ( - issueTasksPat = regexp.MustCompile(`(^\s*[-*]\s*\[[\sxX]\])|(\n\s*[-*]\s*\[[\sxX]\])`) - issueTasksDonePat = regexp.MustCompile(`(^\s*[-*]\s*\[[xX]\])|(\n\s*[-*]\s*\[[xX]\])`) + issueTasksPat = regexp.MustCompile(`(^|\n)\s*[-*]\s*\[[\sxX]\]`) + issueTasksDonePat = regexp.MustCompile(`(^|\n)\s*[-*]\s*\[[xX]\]`) ) // IssueIndex represents the issue index table From 58c60ec11c7c7e9254901d8392415a1c1b6466c8 Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 25 Jul 2024 11:35:56 +0200 Subject: [PATCH 5/9] add issue checklist integration test --- tests/integration/issue_test.go | 41 ++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index ccae0b00e..dbebe6bfc 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -10,6 +10,7 @@ import ( "net/http" "net/url" "path" + "regexp" "strconv" "strings" "testing" @@ -236,9 +237,13 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content htmlDoc = NewHTMLParser(t, resp.Body) val := htmlDoc.doc.Find("#issue-title-display").Text() assert.Contains(t, val, title) - val = htmlDoc.doc.Find(".comment .render-content p").First().Text() - assert.Equal(t, content, val) - + // test for first line only and if it contains only letters and spaces + contentFirstLine := strings.Split(content, "\n")[0] + patNotLetterOrSpace, _ := regexp.Compile("[^\\p{L}\\s]") + if len(contentFirstLine) != 0 && !patNotLetterOrSpace.MatchString(contentFirstLine) { + val = htmlDoc.doc.Find(".comment .render-content p").First().Text() + assert.Equal(t, contentFirstLine, val) + } return issueURL } @@ -281,6 +286,36 @@ func TestNewIssue(t *testing.T) { testNewIssue(t, session, "user2", "repo1", "Title", "Description") } +func TestIssueCheckboxes(t *testing.T) { + defer tests.PrepareTestEnv(t)() + session := loginUser(t, "user2") + issueURL := testNewIssue(t, session, "user2", "repo1", "Title", `- [x] small x +- [X] capital X +- [ ] empty + - [x]x without gap + - [ ]empty without gap +- [x] +x on new line +- [ ] +empty on new line + - [ ] tabs instead of spaces +Description`) + req := NewRequest(t, "GET", issueURL) + resp := session.MakeRequest(t, req, http.StatusOK) + issueContent := NewHTMLParser(t, resp.Body).doc.Find(".comment .render-content").First() + isCheckBox := func(i int, s *goquery.Selection) bool { + typeVal, typeExists := s.Attr("type") + return typeExists && typeVal == "checkbox" + } + isChecked := func(i int, s *goquery.Selection) bool { + _, checkedExists := s.Attr("checked") + return checkedExists + } + checkBoxes := issueContent.Find("input").FilterFunction(isCheckBox) + assert.Equal(t, 8, checkBoxes.Length()) + assert.Equal(t, 4, checkBoxes.FilterFunction(isChecked).Length()) +} + func TestIssueDependencies(t *testing.T) { defer tests.PrepareTestEnv(t)() From 574265e4a852e920088ef5b6406fb4498f56ee55 Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 25 Jul 2024 11:50:33 +0200 Subject: [PATCH 6/9] fix golangci-lint regexpMust --- tests/integration/issue_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index dbebe6bfc..54485ee2d 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -239,7 +239,7 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content assert.Contains(t, val, title) // test for first line only and if it contains only letters and spaces contentFirstLine := strings.Split(content, "\n")[0] - patNotLetterOrSpace, _ := regexp.Compile("[^\\p{L}\\s]") + patNotLetterOrSpace, _ := regexp.MustCompile("[^\\p{L}\\s]") if len(contentFirstLine) != 0 && !patNotLetterOrSpace.MatchString(contentFirstLine) { val = htmlDoc.doc.Find(".comment .render-content p").First().Text() assert.Equal(t, contentFirstLine, val) From 531a18810bf6c9a130d2f36362259198e143d4ae Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 25 Jul 2024 12:07:14 +0200 Subject: [PATCH 7/9] fix typo in regexp --- tests/integration/issue_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 54485ee2d..470e2a8df 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -239,7 +239,7 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content assert.Contains(t, val, title) // test for first line only and if it contains only letters and spaces contentFirstLine := strings.Split(content, "\n")[0] - patNotLetterOrSpace, _ := regexp.MustCompile("[^\\p{L}\\s]") + patNotLetterOrSpace := regexp.MustCompile(`[^\p{L}\s]`) if len(contentFirstLine) != 0 && !patNotLetterOrSpace.MatchString(contentFirstLine) { val = htmlDoc.doc.Find(".comment .render-content p").First().Text() assert.Equal(t, contentFirstLine, val) From 90fe38ec83875e02875d54159a7d76696fc7d70b Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Sun, 28 Jul 2024 16:16:22 +0200 Subject: [PATCH 8/9] add integration test for check list numbers on issues list page --- tests/integration/issue_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 470e2a8df..e79c2ae55 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -314,6 +314,21 @@ Description`) checkBoxes := issueContent.Find("input").FilterFunction(isCheckBox) assert.Equal(t, 8, checkBoxes.Length()) assert.Equal(t, 4, checkBoxes.FilterFunction(isChecked).Length()) + + // Issues list should show the correct numbers of checked and total checkboxes + repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1") + assert.NoError(t, err) + //repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID}) + req = NewRequestf(t, "GET", "%s/issues", repo.Link()) + resp = MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + issuesSelection := htmlDoc.Find("#issue-list .flex-item") + assert.Equal(t, "4 / 8", strings.TrimSpace(issuesSelection.Find(".checklist").Text())) + value, _ := issuesSelection.Find("progress").Attr("value") + vmax, _ := issuesSelection.Find("progress").Attr("max") + assert.Equal(t, "4", value) + assert.Equal(t, "8", vmax) } func TestIssueDependencies(t *testing.T) { From 5bb191e14d78c6e12923f302e89de2f8b92bc67d Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Sun, 28 Jul 2024 16:27:51 +0200 Subject: [PATCH 9/9] remove commented leftovers --- tests/integration/issue_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index e79c2ae55..bf05c3c0a 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -318,7 +318,6 @@ Description`) // Issues list should show the correct numbers of checked and total checkboxes repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1") assert.NoError(t, err) - //repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID}) req = NewRequestf(t, "GET", "%s/issues", repo.Link()) resp = MakeRequest(t, req, http.StatusOK)