mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-03 17:04:35 -04:00
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
This commit is contained in:
parent
52e11b24bf
commit
b0f7457d9e
122 changed files with 15280 additions and 1458 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue