box-ui-elements 24.0.0-beta.5 → 24.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/explorer.css +1 -1
- package/dist/explorer.js +1 -1
- package/dist/picker.js +1 -1
- package/es/elements/content-explorer/Content.js +3 -1
- package/es/elements/content-explorer/Content.js.map +1 -1
- package/es/elements/content-explorer/ContentExplorer.js +17 -6
- package/es/elements/content-explorer/ContentExplorer.js.map +1 -1
- package/es/elements/content-explorer/MetadataQueryAPIHelper.js +104 -7
- package/es/elements/content-explorer/MetadataQueryAPIHelper.js.map +1 -1
- package/es/elements/content-explorer/MetadataQueryBuilder.js +154 -0
- package/es/elements/content-explorer/MetadataQueryBuilder.js.map +1 -0
- package/es/elements/content-explorer/MetadataViewContainer.js +92 -46
- package/es/elements/content-explorer/MetadataViewContainer.js.map +1 -1
- package/es/elements/content-explorer/constants.js +4 -2
- package/es/elements/content-explorer/constants.js.map +1 -1
- package/es/elements/content-explorer/stories/MetadataView.stories.js +3 -25
- package/es/elements/content-explorer/stories/MetadataView.stories.js.map +1 -1
- package/es/elements/content-explorer/stories/tests/MetadataView-visual.stories.js +4 -16
- package/es/elements/content-explorer/stories/tests/MetadataView-visual.stories.js.map +1 -1
- package/es/elements/content-explorer/utils.js +12 -0
- package/es/elements/content-explorer/utils.js.map +1 -1
- package/es/src/elements/common/__mocks__/mockMetadata.d.ts +8 -24
- package/es/src/elements/content-explorer/Content.d.ts +4 -3
- package/es/src/elements/content-explorer/ContentExplorer.d.ts +8 -3
- package/es/src/elements/content-explorer/MetadataQueryAPIHelper.d.ts +11 -2
- package/es/src/elements/content-explorer/MetadataQueryBuilder.d.ts +27 -0
- package/es/src/elements/content-explorer/MetadataViewContainer.d.ts +8 -4
- package/es/src/elements/content-explorer/__tests__/MetadataQueryBuilder.test.d.ts +1 -0
- package/es/src/elements/content-explorer/constants.d.ts +4 -2
- package/es/src/elements/content-explorer/utils.d.ts +2 -0
- package/i18n/bn-IN.js +1 -1
- package/i18n/bn-IN.properties +8 -0
- package/i18n/da-DK.js +1 -1
- package/i18n/da-DK.properties +8 -0
- package/i18n/de-DE.js +1 -1
- package/i18n/de-DE.properties +8 -0
- package/i18n/en-AU.js +1 -1
- package/i18n/en-AU.properties +8 -0
- package/i18n/en-CA.js +1 -1
- package/i18n/en-CA.properties +8 -0
- package/i18n/en-GB.js +1 -1
- package/i18n/en-GB.properties +8 -0
- package/i18n/es-419.js +1 -1
- package/i18n/es-419.properties +8 -0
- package/i18n/es-ES.js +1 -1
- package/i18n/es-ES.properties +8 -0
- package/i18n/fi-FI.js +1 -1
- package/i18n/fi-FI.properties +8 -0
- package/i18n/fr-CA.js +1 -1
- package/i18n/fr-CA.properties +8 -0
- package/i18n/fr-FR.js +1 -1
- package/i18n/fr-FR.properties +8 -0
- package/i18n/hi-IN.js +1 -1
- package/i18n/hi-IN.properties +8 -0
- package/i18n/it-IT.js +1 -1
- package/i18n/it-IT.properties +8 -0
- package/i18n/ja-JP.js +1 -1
- package/i18n/ja-JP.properties +8 -0
- package/i18n/ko-KR.js +1 -1
- package/i18n/ko-KR.properties +8 -0
- package/i18n/nb-NO.js +1 -1
- package/i18n/nb-NO.properties +8 -0
- package/i18n/nl-NL.js +1 -1
- package/i18n/nl-NL.properties +8 -0
- package/i18n/pl-PL.js +1 -1
- package/i18n/pl-PL.properties +8 -0
- package/i18n/pt-BR.js +1 -1
- package/i18n/pt-BR.properties +8 -0
- package/i18n/ru-RU.js +1 -1
- package/i18n/ru-RU.properties +8 -0
- package/i18n/sv-SE.js +1 -1
- package/i18n/sv-SE.properties +8 -0
- package/i18n/tr-TR.js +1 -1
- package/i18n/tr-TR.properties +8 -0
- package/i18n/zh-CN.js +1 -1
- package/i18n/zh-CN.properties +8 -0
- package/i18n/zh-TW.js +1 -1
- package/i18n/zh-TW.properties +8 -0
- package/package.json +3 -3
- package/src/elements/common/__mocks__/mockMetadata.ts +7 -11
- package/src/elements/content-explorer/Content.tsx +8 -2
- package/src/elements/content-explorer/ContentExplorer.tsx +209 -194
- package/src/elements/content-explorer/MetadataQueryAPIHelper.ts +111 -5
- package/src/elements/content-explorer/MetadataQueryBuilder.ts +194 -0
- package/src/elements/content-explorer/MetadataViewContainer.tsx +112 -37
- package/src/elements/content-explorer/__tests__/Content.test.tsx +1 -0
- package/src/elements/content-explorer/__tests__/ContentExplorer.test.tsx +2 -5
- package/src/elements/content-explorer/__tests__/MetadataQueryAPIHelper.test.ts +427 -8
- package/src/elements/content-explorer/__tests__/MetadataQueryBuilder.test.ts +535 -0
- package/src/elements/content-explorer/__tests__/MetadataViewContainer.test.tsx +413 -9
- package/src/elements/content-explorer/constants.ts +39 -2
- package/src/elements/content-explorer/stories/MetadataView.stories.tsx +3 -21
- package/src/elements/content-explorer/stories/tests/MetadataView-visual.stories.tsx +2 -13
- package/src/elements/content-explorer/utils.ts +17 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mergeQueryParams,
|
|
3
|
+
mergeQueries,
|
|
4
|
+
getStringFilter,
|
|
5
|
+
getRangeFilter,
|
|
6
|
+
getSelectFilter,
|
|
7
|
+
getMimeTypeFilter,
|
|
8
|
+
} from '../MetadataQueryBuilder';
|
|
9
|
+
|
|
10
|
+
describe('elements/content-explorer/MetadataQueryBuilder', () => {
|
|
11
|
+
describe('mergeQueryParams', () => {
|
|
12
|
+
test('should merge two objects', () => {
|
|
13
|
+
const target = { key1: 'value1' };
|
|
14
|
+
const source = { key2: 'value2' };
|
|
15
|
+
const result = mergeQueryParams(target, source);
|
|
16
|
+
expect(result).toEqual({ key1: 'value1', key2: 'value2' });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('should override target values with source values', () => {
|
|
20
|
+
const target = { key1: 'value1', key2: 'old' };
|
|
21
|
+
const source = { key2: 'new', key3: 'value3' };
|
|
22
|
+
const result = mergeQueryParams(target, source);
|
|
23
|
+
expect(result).toEqual({ key1: 'value1', key2: 'new', key3: 'value3' });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('should return source when target is empty', () => {
|
|
27
|
+
const target = {};
|
|
28
|
+
const source = { key1: 'value1' };
|
|
29
|
+
const result = mergeQueryParams(target, source);
|
|
30
|
+
expect(result).toEqual({ key1: 'value1' });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('should return target when source is empty', () => {
|
|
34
|
+
const target = { key1: 'value1' };
|
|
35
|
+
const source = {};
|
|
36
|
+
const result = mergeQueryParams(target, source);
|
|
37
|
+
expect(result).toEqual({ key1: 'value1' });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('should return empty object when both are empty', () => {
|
|
41
|
+
const result = mergeQueryParams({}, {});
|
|
42
|
+
expect(result).toEqual({});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('mergeQueries', () => {
|
|
47
|
+
test('should merge two arrays', () => {
|
|
48
|
+
const target = ['query1'];
|
|
49
|
+
const source = ['query2'];
|
|
50
|
+
const result = mergeQueries(target, source);
|
|
51
|
+
expect(result).toEqual(['query1', 'query2']);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('should handle empty target array', () => {
|
|
55
|
+
const target: string[] = [];
|
|
56
|
+
const source = ['query1', 'query2'];
|
|
57
|
+
const result = mergeQueries(target, source);
|
|
58
|
+
expect(result).toEqual(['query1', 'query2']);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('should handle empty source array', () => {
|
|
62
|
+
const target = ['query1', 'query2'];
|
|
63
|
+
const source: string[] = [];
|
|
64
|
+
const result = mergeQueries(target, source);
|
|
65
|
+
expect(result).toEqual(['query1', 'query2']);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('should handle both empty arrays', () => {
|
|
69
|
+
const result = mergeQueries([], []);
|
|
70
|
+
expect(result).toEqual([]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('getStringFilter', () => {
|
|
75
|
+
test('should generate string filter with ILIKE query', () => {
|
|
76
|
+
const result = getStringFilter('test', 'field_name', 0);
|
|
77
|
+
expect(result).toEqual({
|
|
78
|
+
queryParams: { arg_field_name_1: '%test%' },
|
|
79
|
+
queries: ['(field_name ILIKE :arg_field_name_1)'],
|
|
80
|
+
keysGenerated: 1,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('should escape special characters in value', () => {
|
|
85
|
+
const result = getStringFilter('test_value%123', 'field_name', 0);
|
|
86
|
+
expect(result).toEqual({
|
|
87
|
+
queryParams: { arg_field_name_1: '%test\\_value\\%123%' },
|
|
88
|
+
queries: ['(field_name ILIKE :arg_field_name_1)'],
|
|
89
|
+
keysGenerated: 1,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('should use correct arg index', () => {
|
|
94
|
+
const result = getStringFilter('test', 'field_name', 5);
|
|
95
|
+
expect(result).toEqual({
|
|
96
|
+
queryParams: { arg_field_name_6: '%test%' },
|
|
97
|
+
queries: ['(field_name ILIKE :arg_field_name_6)'],
|
|
98
|
+
keysGenerated: 1,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('getRangeFilter', () => {
|
|
104
|
+
test('should generate range filter with both gt and lt', () => {
|
|
105
|
+
const filterValue = { range: { gt: 10, lt: 20 } };
|
|
106
|
+
const result = getRangeFilter(filterValue, 'field_name', 0);
|
|
107
|
+
expect(result).toEqual({
|
|
108
|
+
queryParams: { arg_field_name_1: 10, arg_field_name_2: 20 },
|
|
109
|
+
queries: ['(field_name >= :arg_field_name_1 AND field_name <= :arg_field_name_2)'],
|
|
110
|
+
keysGenerated: 2,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('should generate range filter with only gt', () => {
|
|
115
|
+
const filterValue = { range: { gt: 10, lt: '' } };
|
|
116
|
+
const result = getRangeFilter(filterValue, 'field_name', 0);
|
|
117
|
+
expect(result).toEqual({
|
|
118
|
+
queryParams: { arg_field_name_1: 10 },
|
|
119
|
+
queries: ['(field_name >= :arg_field_name_1)'],
|
|
120
|
+
keysGenerated: 1,
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('should generate range filter with only lt', () => {
|
|
125
|
+
const filterValue = { range: { gt: '', lt: 20 } };
|
|
126
|
+
const result = getRangeFilter(filterValue, 'field_name', 0);
|
|
127
|
+
expect(result).toEqual({
|
|
128
|
+
queryParams: { arg_field_name_1: 20 },
|
|
129
|
+
queries: ['(field_name <= :arg_field_name_1)'],
|
|
130
|
+
keysGenerated: 1,
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('should handle null values in range', () => {
|
|
135
|
+
const filterValue = { range: { gt: null, lt: 20 } };
|
|
136
|
+
const result = getRangeFilter(filterValue, 'field_name', 0);
|
|
137
|
+
expect(result).toEqual({
|
|
138
|
+
queryParams: { arg_field_name_1: 20 },
|
|
139
|
+
queries: ['(field_name <= :arg_field_name_1)'],
|
|
140
|
+
keysGenerated: 1,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('should handle undefined values in range', () => {
|
|
145
|
+
const filterValue = { range: { gt: undefined, lt: 20 } };
|
|
146
|
+
const result = getRangeFilter(filterValue, 'field_name', 0);
|
|
147
|
+
expect(result).toEqual({
|
|
148
|
+
queryParams: { arg_field_name_1: 20 },
|
|
149
|
+
queries: ['(field_name <= :arg_field_name_1)'],
|
|
150
|
+
keysGenerated: 1,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('should handle zero values in range', () => {
|
|
155
|
+
const filterValue = { range: { gt: 0, lt: 100 } };
|
|
156
|
+
const result = getRangeFilter(filterValue, 'field_name', 0);
|
|
157
|
+
expect(result).toEqual({
|
|
158
|
+
queryParams: { arg_field_name_1: 0, arg_field_name_2: 100 },
|
|
159
|
+
queries: ['(field_name >= :arg_field_name_1 AND field_name <= :arg_field_name_2)'],
|
|
160
|
+
keysGenerated: 2,
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('should return empty result for invalid filter value', () => {
|
|
165
|
+
const result = getRangeFilter(null, 'field_name', 0);
|
|
166
|
+
expect(result).toEqual({
|
|
167
|
+
queryParams: {},
|
|
168
|
+
queries: [],
|
|
169
|
+
keysGenerated: 0,
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('should return empty result for filter value without range', () => {
|
|
174
|
+
const filterValue = { someOtherProperty: 'value' } as unknown as
|
|
175
|
+
| string[]
|
|
176
|
+
| { range: { gt: number | string; lt: number | string } };
|
|
177
|
+
const result = getRangeFilter(filterValue, 'field_name', 0);
|
|
178
|
+
expect(result).toEqual({
|
|
179
|
+
queryParams: {},
|
|
180
|
+
queries: [],
|
|
181
|
+
keysGenerated: 0,
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('should return empty result for empty range', () => {
|
|
186
|
+
const filterValue = { range: { gt: '', lt: '' } };
|
|
187
|
+
const result = getRangeFilter(filterValue, 'field_name', 0);
|
|
188
|
+
expect(result).toEqual({
|
|
189
|
+
queryParams: {},
|
|
190
|
+
queries: [],
|
|
191
|
+
keysGenerated: 0,
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('should return empty result for null range', () => {
|
|
196
|
+
const filterValue = { range: null };
|
|
197
|
+
const result = getRangeFilter(filterValue, 'field_name', 0);
|
|
198
|
+
expect(result).toEqual({
|
|
199
|
+
queryParams: {},
|
|
200
|
+
queries: [],
|
|
201
|
+
keysGenerated: 0,
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('should use correct arg index', () => {
|
|
206
|
+
const filterValue = { range: { gt: 10, lt: 20 } };
|
|
207
|
+
const result = getRangeFilter(filterValue, 'field_name', 5);
|
|
208
|
+
expect(result).toEqual({
|
|
209
|
+
queryParams: { arg_field_name_6: 10, arg_field_name_7: 20 },
|
|
210
|
+
queries: ['(field_name >= :arg_field_name_6 AND field_name <= :arg_field_name_7)'],
|
|
211
|
+
keysGenerated: 2,
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe('getSelectFilter', () => {
|
|
217
|
+
test('should generate select filter for multiple values', () => {
|
|
218
|
+
const filterValue = ['value1', 'value2', 'value3'];
|
|
219
|
+
const result = getSelectFilter(filterValue, 'field_name', 0);
|
|
220
|
+
expect(result).toEqual({
|
|
221
|
+
queryParams: {
|
|
222
|
+
arg_field_name_1: 'value1',
|
|
223
|
+
arg_field_name_2: 'value2',
|
|
224
|
+
arg_field_name_3: 'value3',
|
|
225
|
+
},
|
|
226
|
+
queries: ['(field_name HASANY (:arg_field_name_1, :arg_field_name_2, :arg_field_name_3))'],
|
|
227
|
+
keysGenerated: 3,
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('should handle single value array', () => {
|
|
232
|
+
const filterValue = ['single_value'];
|
|
233
|
+
const result = getSelectFilter(filterValue, 'field_name', 0);
|
|
234
|
+
expect(result).toEqual({
|
|
235
|
+
queryParams: { arg_field_name_1: 'single_value' },
|
|
236
|
+
queries: ['(field_name HASANY (:arg_field_name_1))'],
|
|
237
|
+
keysGenerated: 1,
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('should handle numeric values converted to strings', () => {
|
|
242
|
+
const filterValue = ['123', '456'];
|
|
243
|
+
const result = getSelectFilter(filterValue, 'field_name', 0);
|
|
244
|
+
expect(result).toEqual({
|
|
245
|
+
queryParams: {
|
|
246
|
+
arg_field_name_1: '123',
|
|
247
|
+
arg_field_name_2: '456',
|
|
248
|
+
},
|
|
249
|
+
queries: ['(field_name HASANY (:arg_field_name_1, :arg_field_name_2))'],
|
|
250
|
+
keysGenerated: 2,
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('should return empty result for empty array', () => {
|
|
255
|
+
const result = getSelectFilter([], 'field_name', 0);
|
|
256
|
+
expect(result).toEqual({
|
|
257
|
+
queryParams: {},
|
|
258
|
+
queries: [],
|
|
259
|
+
keysGenerated: 0,
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('should return empty result for null/undefined', () => {
|
|
264
|
+
const result = getSelectFilter(null, 'field_name', 0);
|
|
265
|
+
expect(result).toEqual({
|
|
266
|
+
queryParams: {},
|
|
267
|
+
queries: [],
|
|
268
|
+
keysGenerated: 0,
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('should use correct arg index', () => {
|
|
273
|
+
const filterValue = ['value1'];
|
|
274
|
+
const result = getSelectFilter(filterValue, 'field_name', 5);
|
|
275
|
+
expect(result).toEqual({
|
|
276
|
+
queryParams: { arg_field_name_6: 'value1' },
|
|
277
|
+
queries: ['(field_name HASANY (:arg_field_name_6))'],
|
|
278
|
+
keysGenerated: 1,
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test('should handle field names with special characters', () => {
|
|
283
|
+
const filterValue = ['value1', 'value2'];
|
|
284
|
+
const result = getSelectFilter(filterValue, 'field-name.with/special_chars', 0);
|
|
285
|
+
expect(result).toEqual({
|
|
286
|
+
queryParams: {
|
|
287
|
+
arg_field_name_with_special_chars_1: 'value1',
|
|
288
|
+
arg_field_name_with_special_chars_2: 'value2',
|
|
289
|
+
},
|
|
290
|
+
queries: [
|
|
291
|
+
'(field-name.with/special_chars HASANY (:arg_field_name_with_special_chars_1, :arg_field_name_with_special_chars_2))',
|
|
292
|
+
],
|
|
293
|
+
keysGenerated: 2,
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe('getMimeTypeFilter', () => {
|
|
299
|
+
test('should generate mime type filter using mapFileTypes', () => {
|
|
300
|
+
const filterValue = ['pdfType', 'documentType'];
|
|
301
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
302
|
+
expect(result).toEqual({
|
|
303
|
+
queryParams: {
|
|
304
|
+
arg_mimetype_1: 'pdf',
|
|
305
|
+
arg_mimetype_2: 'doc',
|
|
306
|
+
arg_mimetype_3: 'docx',
|
|
307
|
+
arg_mimetype_4: 'gdoc',
|
|
308
|
+
arg_mimetype_5: 'rtf',
|
|
309
|
+
arg_mimetype_6: 'txt',
|
|
310
|
+
},
|
|
311
|
+
queries: [
|
|
312
|
+
'(item.extension IN (:arg_mimetype_1, :arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6))',
|
|
313
|
+
],
|
|
314
|
+
keysGenerated: 6,
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test('should handle values that are not in FILE_FOLDER_TYPES_MAP', () => {
|
|
319
|
+
const filterValue = ['pdf', 'doc'];
|
|
320
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
321
|
+
expect(result).toEqual({
|
|
322
|
+
queryParams: {},
|
|
323
|
+
queries: [],
|
|
324
|
+
keysGenerated: 0,
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test('should handle mixed valid and invalid values', () => {
|
|
329
|
+
const filterValue = ['pdfType', 'doc', 'documentType'];
|
|
330
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
331
|
+
expect(result).toEqual({
|
|
332
|
+
queryParams: {
|
|
333
|
+
arg_mimetype_1: 'pdf',
|
|
334
|
+
arg_mimetype_2: 'doc',
|
|
335
|
+
arg_mimetype_3: 'docx',
|
|
336
|
+
arg_mimetype_4: 'gdoc',
|
|
337
|
+
arg_mimetype_5: 'rtf',
|
|
338
|
+
arg_mimetype_6: 'txt',
|
|
339
|
+
},
|
|
340
|
+
queries: [
|
|
341
|
+
'(item.extension IN (:arg_mimetype_1, :arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6))',
|
|
342
|
+
],
|
|
343
|
+
keysGenerated: 6,
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test('should handle single value array', () => {
|
|
348
|
+
const filterValue = ['pdfType'];
|
|
349
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
350
|
+
expect(result).toEqual({
|
|
351
|
+
queryParams: { arg_mimetype_1: 'pdf' },
|
|
352
|
+
queries: ['(item.extension IN (:arg_mimetype_1))'],
|
|
353
|
+
keysGenerated: 1,
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test('should handle numeric values that are not in FILE_FOLDER_TYPES_MAP', () => {
|
|
358
|
+
const filterValue = ['123', '456'];
|
|
359
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
360
|
+
expect(result).toEqual({
|
|
361
|
+
queryParams: {},
|
|
362
|
+
queries: [],
|
|
363
|
+
keysGenerated: 0,
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test('should return empty result for empty array', () => {
|
|
368
|
+
const result = getMimeTypeFilter([], 'mimetype', 0);
|
|
369
|
+
expect(result).toEqual({
|
|
370
|
+
queryParams: {},
|
|
371
|
+
queries: [],
|
|
372
|
+
keysGenerated: 0,
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
test('should return empty result for null/undefined', () => {
|
|
377
|
+
const result = getMimeTypeFilter(null, 'mimetype', 0);
|
|
378
|
+
expect(result).toEqual({
|
|
379
|
+
queryParams: {},
|
|
380
|
+
queries: [],
|
|
381
|
+
keysGenerated: 0,
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
test('should use correct arg index', () => {
|
|
386
|
+
const filterValue = ['pdfType'];
|
|
387
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 5);
|
|
388
|
+
expect(result).toEqual({
|
|
389
|
+
queryParams: { arg_mimetype_6: 'pdf' },
|
|
390
|
+
queries: ['(item.extension IN (:arg_mimetype_6))'],
|
|
391
|
+
keysGenerated: 1,
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
test('should handle field names with special characters', () => {
|
|
396
|
+
const filterValue = ['pdfType', 'documentType'];
|
|
397
|
+
const result = getMimeTypeFilter(filterValue, 'mime-type.with/special_chars', 0);
|
|
398
|
+
expect(result).toEqual({
|
|
399
|
+
queryParams: {
|
|
400
|
+
arg_mime_type_with_special_chars_1: 'pdf',
|
|
401
|
+
arg_mime_type_with_special_chars_2: 'doc',
|
|
402
|
+
arg_mime_type_with_special_chars_3: 'docx',
|
|
403
|
+
arg_mime_type_with_special_chars_4: 'gdoc',
|
|
404
|
+
arg_mime_type_with_special_chars_5: 'rtf',
|
|
405
|
+
arg_mime_type_with_special_chars_6: 'txt',
|
|
406
|
+
},
|
|
407
|
+
queries: [
|
|
408
|
+
'(item.extension IN (:arg_mime_type_with_special_chars_1, :arg_mime_type_with_special_chars_2, :arg_mime_type_with_special_chars_3, :arg_mime_type_with_special_chars_4, :arg_mime_type_with_special_chars_5, :arg_mime_type_with_special_chars_6))',
|
|
409
|
+
],
|
|
410
|
+
keysGenerated: 6,
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// New tests for folderType functionality
|
|
415
|
+
test('should handle folderType only', () => {
|
|
416
|
+
const filterValue = ['folderType'];
|
|
417
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
418
|
+
expect(result).toEqual({
|
|
419
|
+
queryParams: {
|
|
420
|
+
arg_mime_folderType_1: 'folder',
|
|
421
|
+
},
|
|
422
|
+
queries: ['(item.type = :arg_mime_folderType_1)'],
|
|
423
|
+
keysGenerated: 1,
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test('should handle folderType with file types', () => {
|
|
428
|
+
const filterValue = ['folderType', 'pdfType', 'documentType'];
|
|
429
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
430
|
+
expect(result).toEqual({
|
|
431
|
+
queryParams: {
|
|
432
|
+
arg_mime_folderType_1: 'folder',
|
|
433
|
+
arg_mimetype_2: 'pdf',
|
|
434
|
+
arg_mimetype_3: 'doc',
|
|
435
|
+
arg_mimetype_4: 'docx',
|
|
436
|
+
arg_mimetype_5: 'gdoc',
|
|
437
|
+
arg_mimetype_6: 'rtf',
|
|
438
|
+
arg_mimetype_7: 'txt',
|
|
439
|
+
},
|
|
440
|
+
queries: [
|
|
441
|
+
'((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6, :arg_mimetype_7)))',
|
|
442
|
+
],
|
|
443
|
+
keysGenerated: 7,
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
test('should handle folderType with mixed valid and invalid file types', () => {
|
|
448
|
+
const filterValue = ['folderType', 'pdfType', 'doc', 'documentType'];
|
|
449
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
450
|
+
expect(result).toEqual({
|
|
451
|
+
queryParams: {
|
|
452
|
+
arg_mime_folderType_1: 'folder',
|
|
453
|
+
arg_mimetype_2: 'pdf',
|
|
454
|
+
arg_mimetype_3: 'doc',
|
|
455
|
+
arg_mimetype_4: 'docx',
|
|
456
|
+
arg_mimetype_5: 'gdoc',
|
|
457
|
+
arg_mimetype_6: 'rtf',
|
|
458
|
+
arg_mimetype_7: 'txt',
|
|
459
|
+
},
|
|
460
|
+
queries: [
|
|
461
|
+
'((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6, :arg_mimetype_7)))',
|
|
462
|
+
],
|
|
463
|
+
keysGenerated: 7,
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
test('should handle folderType with single file type', () => {
|
|
468
|
+
const filterValue = ['folderType', 'pdfType'];
|
|
469
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
470
|
+
expect(result).toEqual({
|
|
471
|
+
queryParams: {
|
|
472
|
+
arg_mime_folderType_1: 'folder',
|
|
473
|
+
arg_mimetype_2: 'pdf',
|
|
474
|
+
},
|
|
475
|
+
queries: ['((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mimetype_2)))'],
|
|
476
|
+
keysGenerated: 2,
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
test('should handle folderType with file types using correct arg index', () => {
|
|
481
|
+
const filterValue = ['folderType', 'pdfType', 'documentType'];
|
|
482
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 5);
|
|
483
|
+
expect(result).toEqual({
|
|
484
|
+
queryParams: {
|
|
485
|
+
arg_mime_folderType_6: 'folder',
|
|
486
|
+
arg_mimetype_7: 'pdf',
|
|
487
|
+
arg_mimetype_8: 'doc',
|
|
488
|
+
arg_mimetype_9: 'docx',
|
|
489
|
+
arg_mimetype_10: 'gdoc',
|
|
490
|
+
arg_mimetype_11: 'rtf',
|
|
491
|
+
arg_mimetype_12: 'txt',
|
|
492
|
+
},
|
|
493
|
+
queries: [
|
|
494
|
+
'((item.type = :arg_mime_folderType_6) OR (item.extension IN (:arg_mimetype_7, :arg_mimetype_8, :arg_mimetype_9, :arg_mimetype_10, :arg_mimetype_11, :arg_mimetype_12)))',
|
|
495
|
+
],
|
|
496
|
+
keysGenerated: 7,
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
test('should handle multiple folderType entries (should only process one)', () => {
|
|
501
|
+
const filterValue = ['folderType', 'pdfType', 'folderType', 'documentType'];
|
|
502
|
+
const result = getMimeTypeFilter(filterValue, 'mimetype', 0);
|
|
503
|
+
expect(result).toEqual({
|
|
504
|
+
queryParams: {
|
|
505
|
+
arg_mime_folderType_1: 'folder',
|
|
506
|
+
arg_mimetype_2: 'pdf',
|
|
507
|
+
arg_mimetype_3: 'doc',
|
|
508
|
+
arg_mimetype_4: 'docx',
|
|
509
|
+
arg_mimetype_5: 'gdoc',
|
|
510
|
+
arg_mimetype_6: 'rtf',
|
|
511
|
+
arg_mimetype_7: 'txt',
|
|
512
|
+
},
|
|
513
|
+
queries: [
|
|
514
|
+
'((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mimetype_2, :arg_mimetype_3, :arg_mimetype_4, :arg_mimetype_5, :arg_mimetype_6, :arg_mimetype_7)))',
|
|
515
|
+
],
|
|
516
|
+
keysGenerated: 7,
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
test('should handle folderType with field names containing special characters', () => {
|
|
521
|
+
const filterValue = ['folderType', 'pdfType'];
|
|
522
|
+
const result = getMimeTypeFilter(filterValue, 'mime-type.with/special_chars', 0);
|
|
523
|
+
expect(result).toEqual({
|
|
524
|
+
queryParams: {
|
|
525
|
+
arg_mime_folderType_1: 'folder',
|
|
526
|
+
arg_mime_type_with_special_chars_2: 'pdf',
|
|
527
|
+
},
|
|
528
|
+
queries: [
|
|
529
|
+
'((item.type = :arg_mime_folderType_1) OR (item.extension IN (:arg_mime_type_with_special_chars_2)))',
|
|
530
|
+
],
|
|
531
|
+
keysGenerated: 2,
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
});
|