mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 06:32:49 +01:00
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>
This commit is contained in:
commit
7b798a88ee
3 changed files with 56 additions and 7 deletions
|
@ -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(`(^|\n)\s*[-*]\s*\[[\sxX]\]`)
|
||||
issueTasksDonePat = regexp.MustCompile(`(^|\n)\s*[-*]\s*\[[xX]\]`)
|
||||
)
|
||||
|
||||
// IssueIndex represents the issue index table
|
||||
|
|
|
@ -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.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)
|
||||
}
|
||||
return issueURL
|
||||
}
|
||||
|
||||
|
@ -281,6 +286,50 @@ 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())
|
||||
|
||||
// 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)
|
||||
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) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue