lobe-chat

Форк
0
/
filter.test.ts 
122 строки · 3.2 Кб
1
import { test } from 'vitest';
2

3
test('placeholder', () => {});
4
// describe('filterWithKeywords', () => {
5
//   const data: Record<string, BaseDataModel> = {
6
//     1: {
7
//       id: '1',
8
//       meta: {
9
//         title: 'hello world',
10
//         description: 'test case',
11
//         tag: ['a', 'b'],
12
//       },
13
//     },
14
//     2: {
15
//       id: '2',
16
//       meta: {
17
//         title: 'goodbye',
18
//         description: 'hello world',
19
//         tag: ['c', 'd'],
20
//       },
21
//     },
22
//   };
23
//
24
//   it('should return an empty object if map is empty', () => {
25
//     const result = filterWithKeywords({}, 'hello');
26
//     expect(result).toEqual({});
27
//   });
28
//
29
//   it('should return the original map if keywords is empty', () => {
30
//     const result = filterWithKeywords(data, '');
31
//     expect(result).toEqual(data);
32
//   });
33
//
34
//   it('should return a filtered map if keywords is not empty', () => {
35
//     const result = filterWithKeywords(data, 'world');
36
//     expect(result).toEqual({
37
//       1: {
38
//         id: '1',
39
//         meta: {
40
//           title: 'hello world',
41
//           description: 'test case',
42
//           tag: ['a', 'b'],
43
//         },
44
//       },
45
//       2: {
46
//         id: '2',
47
//         meta: {
48
//           title: 'goodbye',
49
//           description: 'hello world',
50
//           tag: ['c', 'd'],
51
//         },
52
//       },
53
//     });
54
//   });
55
//
56
//   it('should only consider title, description and tag properties if extraSearchStr is not provided', () => {
57
//     const result = filterWithKeywords(data, 'test');
58
//     expect(result).toEqual({
59
//       1: {
60
//         id: '1',
61
//         meta: {
62
//           title: 'hello world',
63
//           description: 'test case',
64
//           tag: ['a', 'b'],
65
//         },
66
//       },
67
//     });
68
//   });
69
//
70
//   it('should consider extraSearchStr in addition to title, description and tag properties if provided', () => {
71
//     const extraSearchStr = (item: BaseDataModel) => {
72
//       return item.meta.avatar || '';
73
//     };
74
//     const data: Record<string, BaseDataModel> = {
75
//       a: {
76
//         id: 'a',
77
//         meta: {
78
//           title: 'hello world',
79
//           description: 'test case',
80
//           tag: ['a', 'b'],
81
//           avatar: 'xxx',
82
//         },
83
//       },
84
//       b: {
85
//         id: 'b',
86
//         meta: {
87
//           title: 'goodbye',
88
//           description: 'hello world',
89
//           tag: ['c', 'd'],
90
//           avatar: 'yyy',
91
//         },
92
//       },
93
//     };
94
//
95
//     const result = filterWithKeywords(data, 'yyy', extraSearchStr);
96
//     expect(result).toEqual({
97
//       b: {
98
//         id: 'b',
99
//         meta: {
100
//           title: 'goodbye',
101
//           description: 'hello world',
102
//           tag: ['c', 'd'],
103
//           avatar: 'yyy',
104
//         },
105
//       },
106
//     });
107
//   });
108
//
109
//   it('should ensure that each filtered object has at least one property that includes the keyword or extraSearchStr', () => {
110
//     const result = filterWithKeywords(data, 't');
111
//     expect(result).toEqual({
112
//       1: {
113
//         id: '1',
114
//         meta: {
115
//           title: 'hello world',
116
//           description: 'test case',
117
//           tag: ['a', 'b'],
118
//         },
119
//       },
120
//     });
121
//   });
122
// });
123

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.