diff options
Diffstat (limited to 'integrations/issue_test.go')
-rw-r--r-- | integrations/issue_test.go | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/integrations/issue_test.go b/integrations/issue_test.go index e728e4a154..e962ef2e93 100644 --- a/integrations/issue_test.go +++ b/integrations/issue_test.go @@ -18,8 +18,10 @@ import ( "github.com/stretchr/testify/assert" ) -func getIssuesSelection(htmlDoc *HTMLDoc) *goquery.Selection { - return htmlDoc.doc.Find(".issue.list").Find("li").Find(".title") +func getIssuesSelection(t testing.TB, htmlDoc *HTMLDoc) *goquery.Selection { + issueList := htmlDoc.doc.Find(".issue.list") + assert.EqualValues(t, 1, issueList.Length()) + return issueList.Find("li").Find(".title") } func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *models.Issue { @@ -31,6 +33,18 @@ func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *mo return models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repoID, Index: int64(index)}).(*models.Issue) } +func assertMatch(t testing.TB, issue *models.Issue, keyword string) { + matches := strings.Contains(strings.ToLower(issue.Title), keyword) || + strings.Contains(strings.ToLower(issue.Content), keyword) + for _, comment := range issue.Comments { + matches = matches || strings.Contains( + strings.ToLower(comment.Content), + keyword, + ) + } + assert.True(t, matches) +} + func TestNoLoginViewIssues(t *testing.T) { prepareTestEnv(t) @@ -38,19 +52,18 @@ func TestNoLoginViewIssues(t *testing.T) { MakeRequest(t, req, http.StatusOK) } -func TestNoLoginViewIssuesSortByType(t *testing.T) { +func TestViewIssuesSortByType(t *testing.T) { prepareTestEnv(t) user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) - repo.Owner = models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User) session := loginUser(t, user.Name) req := NewRequest(t, "GET", repo.RelLink()+"/issues?type=created_by") resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - issuesSelection := getIssuesSelection(htmlDoc) + issuesSelection := getIssuesSelection(t, htmlDoc) expectedNumIssues := models.GetCount(t, &models.Issue{RepoID: repo.ID, PosterID: user.ID}, models.Cond("is_closed=?", false), @@ -67,6 +80,26 @@ func TestNoLoginViewIssuesSortByType(t *testing.T) { }) } +func TestViewIssuesKeyword(t *testing.T) { + prepareTestEnv(t) + + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + + const keyword = "first" + req := NewRequestf(t, "GET", "%s/issues?q=%s", repo.RelLink(), keyword) + resp := MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + issuesSelection := getIssuesSelection(t, htmlDoc) + assert.EqualValues(t, 1, issuesSelection.Length()) + issuesSelection.Each(func(_ int, selection *goquery.Selection) { + issue := getIssue(t, repo.ID, selection) + assert.False(t, issue.IsClosed) + assert.False(t, issue.IsPull) + assertMatch(t, issue, keyword) + }) +} + func TestNoLoginViewIssue(t *testing.T) { prepareTestEnv(t) |