diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-09-16 13:16:21 -0700 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-09-16 23:16:21 +0300 |
commit | b0f7457d9ef6e16d4a3197f7544035d5d387e201 (patch) | |
tree | dbe6a9b3b74f9a4a6eaa0c0cfe59fa08509edccc /integrations/issue_test.go | |
parent | 52e11b24bf5e395d83ea58c1b0fd6922efe16add (diff) | |
download | gitea-b0f7457d9ef6e16d4a3197f7544035d5d387e201.tar.gz gitea-b0f7457d9ef6e16d4a3197f7544035d5d387e201.zip |
Improve issue search (#2387)
* Improve issue indexer
* Fix new issue sqlite bug
* Different test indexer paths for each db
* Add integration indexer paths to make clean
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) |