1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import { describe, it, expect } from 'vitest';
import { filterByName } from './filter-items';
const routines = [
{ id: 1, name: 'Cuisine/Repas' },
{ id: 2, name: 'Cuisine/Vaisselle' },
{ id: 3, name: 'Salle de bain/Douche' },
{ id: 4, name: 'Étirements' },
{ id: 5, name: 'Course' },
];
describe('filterByName', () => {
it('filters by a namespace query like "Cuisine/"', () => {
const res = filterByName(routines, 'Cuisine/');
expect(res.map((r) => r.name)).toEqual([
'Cuisine/Repas',
'Cuisine/Vaisselle',
]);
});
it('matches a substring anywhere in the name', () => {
const res = filterByName(routines, 'epas');
expect(res.map((r) => r.name)).toEqual(['Cuisine/Repas']);
});
it('is case-insensitive', () => {
expect(filterByName(routines, 'cUiSiNe/')).toHaveLength(2);
});
it('folds accents on both sides', () => {
expect(filterByName(routines, 'etirements').map((r) => r.name)).toEqual([
'Étirements',
]);
expect(filterByName(routines, 'Étirements')).toHaveLength(1);
});
it('returns everything for an empty or whitespace query, order preserved', () => {
expect(filterByName(routines, '')).toEqual(routines);
expect(filterByName(routines, ' ')).toEqual(routines);
});
it('returns nothing when no name matches', () => {
expect(filterByName(routines, 'garage')).toEqual([]);
});
it('has no result cap', () => {
const many = Array.from({ length: 40 }, (_, i) => ({
id: i,
name: `Cuisine/Tâche ${i}`,
}));
expect(filterByName(many, 'Cuisine/')).toHaveLength(40);
});
});
|