From 58c60ec11c7c7e9254901d8392415a1c1b6466c8 Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 25 Jul 2024 11:35:56 +0200 Subject: [PATCH] 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 ccae0b00ea..dbebe6bfce 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)()