SYNC: test for parseName + fix

This commit is contained in:
SPRINX0\prochazka
2025-03-28 15:42:14 +01:00
committed by Diflow
parent d3d97b5924
commit 0dd0125e9f
5 changed files with 39 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleFileExtensions: ['js'],
};

View File

@@ -17,8 +17,9 @@
"scripts": {
"build": "tsc",
"start": "tsc --watch",
"prepublishOnly": "yarn build",
"test": "jest",
"prepublishOnly": "yarn build"
"test:ci": "jest --json --outputFile=result.json --testLocationInResults"
},
"files": [
"lib"
@@ -26,8 +27,8 @@
"devDependencies": {
"@types/node": "^13.7.0",
"dbgate-types": "^6.0.0-alpha.1",
"jest": "^24.9.0",
"ts-jest": "^25.2.1",
"jest": "^28.1.3",
"ts-jest": "^28.0.7",
"typescript": "^4.4.3"
},
"dependencies": {

View File

@@ -0,0 +1,20 @@
const { tokenizeBySearchFilter } = require('./filterName');
test('tokenize single token', () => {
const tokenized = tokenizeBySearchFilter('Album', 'al');
// console.log(JSON.stringify(tokenized, null, 2));
expect(tokenized).toEqual([
{ text: 'Al', isMatch: true },
{ text: 'bum', isMatch: false },
]);
});
test('tokenize two tokens', () => {
const tokenized = tokenizeBySearchFilter('Album', 'al,um');
// console.log(JSON.stringify(tokenized, null, 2));
expect(tokenized).toEqual([
{ text: 'Al', isMatch: true },
{ text: 'b', isMatch: false },
{ text: 'um', isMatch: true },
]);
});

View File

@@ -118,7 +118,10 @@ export function filterNameCompoud(
export function tokenizeBySearchFilter(text: string, filter: string): { text: string; isMatch: boolean }[] {
const camelTokens = [];
const stdTokens = [];
for (const token of filter.split(/ ,/).map(x => x.trim())) {
for (const token of filter
.split(/[ ,]/)
.map(x => x.trim())
.filter(x => x.length > 0)) {
if (token.replace(/[A-Z]/g, '').length == 0) {
camelTokens.push(token);
} else {

View File

@@ -43,6 +43,12 @@ jobs:
cd packages/datalib
yarn test:ci
- name: Tools tests
if: always()
run: |
cd packages/tools
yarn test:ci
- uses: tanmen/jest-reporter@v1
if: always()
with: