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:
parent
009a1bcf86
commit
3b0b5d0513
4 changed files with 30 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {matchEmoji, matchMention} from './match.js';
|
||||
import {matchEmoji, matchMention, matchIssue} from './match.js';
|
||||
|
||||
test('matchEmoji', () => {
|
||||
expect(matchEmoji('')).toEqual([
|
||||
|
@ -48,3 +48,15 @@ test('matchMention', () => {
|
|||
expect(matchMention('')).toEqual(window.config.mentionValues.slice(0, 6));
|
||||
expect(matchMention('user4')).toEqual([window.config.mentionValues[3]]);
|
||||
});
|
||||
|
||||
test('matchIssue', () => {
|
||||
expect(matchIssue('')).toEqual(window.config.issueValues.slice(0, 6));
|
||||
expect(matchIssue('1')).toEqual([window.config.issueValues[9], window.config.issueValues[0]]);
|
||||
expect(matchIssue('issue')).toEqual([
|
||||
window.config.issueValues[0],
|
||||
window.config.issueValues[1],
|
||||
window.config.issueValues[2],
|
||||
window.config.issueValues[7],
|
||||
window.config.issueValues[9],
|
||||
]);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue