1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-10-10 19:32:02 +00:00

add unit tests for js

This commit is contained in:
Maxim Slipenko 2025-06-07 19:02:13 +03:00
parent 009a1bcf86
commit 3b0b5d0513
4 changed files with 30 additions and 6 deletions

View file

@ -49,10 +49,9 @@ export function matchIssue(queryText) {
const query = queryText.toLowerCase().trim();
if (!query) {
// Return latest 5 issues/prs sorted by number descending
return [...issues]
.sort((a, b) => b.number - a.number)
.slice(0, 5);
.slice(0, maxMatches);
}
const isDigital = /^\d+$/.test(query);
@ -67,7 +66,7 @@ export function matchIssue(queryText) {
results.push(...prefixMatches);
}
if (!isDigital || results.length < 5) {
if (!isDigital || results.length < maxMatches) {
// Fallback: find by title match, sorted by number descending
const titleMatches = issues
.filter(issue =>
@ -79,10 +78,10 @@ export function matchIssue(queryText) {
for (const match of titleMatches) {
if (!results.includes(match)) {
results.push(match);
if (results.length >= 5) break;
if (results.length >= maxMatches) break;
}
}
}
return results.slice(0, 5);
return results.slice(0, maxMatches);
}