mirror of
https://github.com/go-gitea/gitea
synced 2025-02-14 13:47:01 +01:00
Backport #33538 by @lunny Fix #33522 The suggestion backend logic now is - If the keyword is empty, returned the latest 5 issues/prs with index desc order - If the keyword is digital, find all issues/prs which `index` has a prefix with that, with index asc order - If the keyword is non-digital or if the queried records less than 5, searching issues/prs title with a `like`, with index desc order ## Empty keyword <img width="310" alt="image" src="https://github.com/user-attachments/assets/1912c634-0d98-4eeb-8542-d54240901f77" /> ## Digital <img width="479" alt="image" src="https://github.com/user-attachments/assets/0356a936-7110-4a24-b21e-7400201bf9b8" /> ## Digital and title contains the digital <img width="363" alt="image" src="https://github.com/user-attachments/assets/6e12f908-28fe-48de-8ccc-09cbeab024d4" /> ## non-Digital <img width="435" alt="image" src="https://github.com/user-attachments/assets/2722bb53-baa2-4d67-a224-522a65f73856" /> <img width="477" alt="image" src="https://github.com/user-attachments/assets/06708dd9-80d1-4a88-b32b-d29072dd1ba6" /> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issue
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
"code.gitea.io/gitea/modules/optional"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_Suggestion(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
testCases := []struct {
|
|
keyword string
|
|
isPull optional.Option[bool]
|
|
expectedIndexes []int64
|
|
}{
|
|
{
|
|
keyword: "",
|
|
expectedIndexes: []int64{5, 1, 4, 2, 3},
|
|
},
|
|
{
|
|
keyword: "1",
|
|
expectedIndexes: []int64{1},
|
|
},
|
|
{
|
|
keyword: "issue",
|
|
expectedIndexes: []int64{4, 1, 2, 3},
|
|
},
|
|
{
|
|
keyword: "pull",
|
|
expectedIndexes: []int64{5},
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
t.Run(testCase.keyword, func(t *testing.T) {
|
|
issues, err := GetSuggestion(db.DefaultContext, repo1, testCase.isPull, testCase.keyword)
|
|
assert.NoError(t, err)
|
|
|
|
issueIndexes := make([]int64, 0, len(issues))
|
|
for _, issue := range issues {
|
|
issueIndexes = append(issueIndexes, issue.Index)
|
|
}
|
|
assert.EqualValues(t, testCase.expectedIndexes, issueIndexes)
|
|
})
|
|
}
|
|
}
|