-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
fix: fix diacritics and special unicode characters handling
1 parent
310a078
commit e3c45c4
Showing
5 changed files
with
95 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Tree } from '../src/cosmoz-tree'; | ||
|
||
export const treeBaseUrl = '/test/data'; | ||
|
||
export const treeFromJsonUrl = async (url: string, options = {}) => { | ||
const json = await fetch(url).then((r) => r.json()); | ||
|
||
return new Tree(json, options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"1": { | ||
"id": "11111111-1111-1111-1111-111111111111", | ||
"name": "Root", | ||
"pathLocator": "1", | ||
"children": { | ||
"2": { | ||
"id": "167d1485-7d4f-4c7d-86cd-a4fb00f31245", | ||
"name": "Node2", | ||
"pathLocator": "1.2", | ||
"children": { | ||
"3": { | ||
"id": "3a7654f1-e3e6-49c7-b6a8-a4fb00f31245", | ||
"name": "Pétér", | ||
"pathLocator": "1.2.3", | ||
"children": { | ||
"301": { | ||
"id": "3a7654f1-e3e6-49c7-b6a8-a4fb00f31245", | ||
"name": "Péter", | ||
"pathLocator": "1.2.3.301", | ||
"children": {} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"4": { | ||
"id": "2b547550-b874-4228-9395-a4fb00f31245", | ||
"name": "Michaél", | ||
"pathLocator": "1.4", | ||
"children": {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { treeBaseUrl, treeFromJsonUrl } from './base-data'; | ||
import { Tree } from '../src/cosmoz-tree'; | ||
import { assert } from '@open-wc/testing'; | ||
|
||
const diacriticsTreeUrl = `${treeBaseUrl}/diacriticsTree.json`; | ||
|
||
suite('diacritics', () => { | ||
let diacriticsTree: Tree; | ||
|
||
suiteSetup(async () => { | ||
diacriticsTree = await treeFromJsonUrl(diacriticsTreeUrl); | ||
}); | ||
|
||
/** | ||
* A pair of [value, exactMatches, nonExactMatches] | ||
*/ | ||
const valuesToCheck = [ | ||
['Peter', 0, 2], | ||
['Péter', 1, 2], | ||
['Pétér', 1, 2], | ||
['Michael', 0, 1], | ||
['Michaél', 1, 1] | ||
] as const; | ||
|
||
valuesToCheck.forEach(([value, exactMatches, nonExactMatches]) => { | ||
test(`should matter when doing an exact search (${value})`, () => { | ||
const results = diacriticsTree.searchNodes(value, undefined, true, 'name'); | ||
|
||
assert.equal(results.length, exactMatches); | ||
}); | ||
|
||
test(`should NOT matter when doing a non-exact search (${value})`, () => { | ||
const results = diacriticsTree.searchNodes(value, undefined, false, 'name'); | ||
assert.equal(results.length, nonExactMatches); | ||
}); | ||
}) | ||
}); |