2024-02-09 04:12:23 +08:00
|
|
|
import { FilterOption } from "../type/web.ts";
|
2024-02-09 04:00:45 +08:00
|
|
|
import { assertEquals } from "$lib/test_deps.ts";
|
2023-07-25 23:33:07 +08:00
|
|
|
import { fuzzySearchAndSort } from "./fuse_search.ts";
|
|
|
|
|
|
|
|
Deno.test("testFuzzyFilter", () => {
|
|
|
|
const array: FilterOption[] = [
|
|
|
|
{ name: "My Company/Hank", orderId: 2 },
|
|
|
|
{ name: "My Company/Hane", orderId: 1 },
|
|
|
|
{ name: "My Company/Steve Co" },
|
|
|
|
{ name: "Other/Steve" },
|
|
|
|
{ name: "Steve" },
|
|
|
|
];
|
|
|
|
|
|
|
|
// Prioritize match in last path part
|
|
|
|
let results = fuzzySearchAndSort(array, "");
|
|
|
|
assertEquals(results.length, array.length);
|
|
|
|
results = fuzzySearchAndSort(array, "Steve");
|
|
|
|
assertEquals(results.length, 3);
|
|
|
|
results = fuzzySearchAndSort(array, "Co");
|
|
|
|
// Match in last path part
|
|
|
|
assertEquals(results[0].name, "My Company/Steve Co");
|
|
|
|
// Due to orderId
|
|
|
|
assertEquals(results[1].name, "My Company/Hane");
|
|
|
|
assertEquals(results[2].name, "My Company/Hank");
|
|
|
|
});
|