diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-06-14 23:09:03 -0400 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-06-15 05:09:03 +0200 |
commit | 8fcda0442e60209d7e6783c95d96f20ff04dbdd6 (patch) | |
tree | 8b47fcaab6003453ec319fc4960d959a2d06e6e9 /integrations | |
parent | bf48c8ebdd3975d1090115a9106069796c67a6da (diff) | |
download | gitea-8fcda0442e60209d7e6783c95d96f20ff04dbdd6.tar.gz gitea-8fcda0442e60209d7e6783c95d96f20ff04dbdd6.zip |
Fix search by issue type (#1914)
* Fix search by issue type
Diffstat (limited to 'integrations')
-rw-r--r-- | integrations/issue_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/integrations/issue_test.go b/integrations/issue_test.go index 3b486dc505..f94f11a863 100644 --- a/integrations/issue_test.go +++ b/integrations/issue_test.go @@ -6,11 +6,30 @@ package integrations import ( "net/http" + "strconv" + "strings" "testing" + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/setting" + + "github.com/PuerkitoBio/goquery" "github.com/stretchr/testify/assert" ) +func getIssuesSelection(htmlDoc *HtmlDoc) *goquery.Selection { + return htmlDoc.doc.Find(".issue.list").Find("li").Find(".title") +} + +func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *models.Issue { + href, exists := issueSelection.Attr("href") + assert.True(t, exists) + indexStr := href[strings.LastIndexByte(href, '/')+1:] + index, err := strconv.Atoi(indexStr) + assert.NoError(t, err, "Invalid issue href: %s", href) + return models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repoID, Index: int64(index)}).(*models.Issue) +} + func TestNoLoginViewIssues(t *testing.T) { prepareTestEnv(t) @@ -19,6 +38,37 @@ func TestNoLoginViewIssues(t *testing.T) { assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } +func TestNoLoginViewIssuesSortByType(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, "password") + req := NewRequest(t, "GET", repo.RelLink()+"/issues?type=created_by") + resp := session.MakeRequest(t, req) + assert.EqualValues(t, http.StatusOK, resp.HeaderCode) + + htmlDoc, err := NewHtmlParser(resp.Body) + assert.NoError(t, err) + issuesSelection := getIssuesSelection(htmlDoc) + expectedNumIssues := models.GetCount(t, + &models.Issue{RepoID: repo.ID, PosterID: user.ID}, + models.Cond("is_closed=?", false), + models.Cond("is_pull=?", false), + ) + if expectedNumIssues > setting.UI.IssuePagingNum { + expectedNumIssues = setting.UI.IssuePagingNum + } + assert.EqualValues(t, expectedNumIssues, issuesSelection.Length()) + + issuesSelection.Each(func(_ int, selection *goquery.Selection) { + issue := getIssue(t, repo.ID, selection) + assert.EqualValues(t, user.ID, issue.PosterID) + }) +} + func TestNoLoginViewIssue(t *testing.T) { prepareTestEnv(t) |