Skip to content

Commit e451111

Browse files
committed
feat(davinci-client): add support for single select collectors
1 parent 9aa0791 commit e451111

9 files changed

+414
-390
lines changed

packages/davinci-client/src/lib/collector.types.test-d.ts

+105-157
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import type {
1111
FlowCollector,
1212
SocialLoginCollector,
1313
SubmitCollector,
14-
DropDownCollector,
15-
ComboboxCollector,
16-
RadioCollector,
17-
FlowLinkCollector,
18-
InferSingleValueCollectorFromSingleValueCollectorType,
14+
SingleSelectCollector,
15+
MultiValueCollectorWithValue,
16+
MultiSelectCollector,
17+
InferSingleValueCollectorType,
18+
InferMultiValueCollectorType,
19+
InferActionCollectorType,
1920
} from './collector.types.js';
2021

2122
describe('Collector Types', () => {
@@ -45,48 +46,30 @@ describe('Collector Types', () => {
4546
}>();
4647
});
4748

48-
it('should validate DropDownCollector structure', () => {
49-
expectTypeOf<DropDownCollector>().toMatchTypeOf<
50-
SingleValueCollectorWithValue<'DropDownCollector'>
49+
it('should validate SingleCollector structure', () => {
50+
expectTypeOf<SingleSelectCollector>().toMatchTypeOf<
51+
SingleValueCollectorWithValue<'SingleSelectCollector'>
5152
>();
52-
expectTypeOf<DropDownCollector>()
53+
expectTypeOf<SingleSelectCollector>()
5354
.toHaveProperty('category')
5455
.toEqualTypeOf<'SingleValueCollector'>();
55-
expectTypeOf<DropDownCollector>().toHaveProperty('type').toEqualTypeOf<'DropDownCollector'>();
56-
expectTypeOf<DropDownCollector['output']>().toHaveProperty('value');
57-
});
58-
59-
it('should validate ComboboxCollector structure', () => {
60-
expectTypeOf<ComboboxCollector>().toMatchTypeOf<
61-
SingleValueCollectorWithValue<'ComboboxCollector'>
62-
>();
63-
expectTypeOf<ComboboxCollector>()
64-
.toHaveProperty('category')
65-
.toEqualTypeOf<'SingleValueCollector'>();
66-
expectTypeOf<ComboboxCollector>().toHaveProperty('type').toEqualTypeOf<'ComboboxCollector'>();
67-
expectTypeOf<ComboboxCollector['output']>().toHaveProperty('value');
68-
});
69-
70-
it('should validate RadioCollector structure', () => {
71-
expectTypeOf<RadioCollector>().toMatchTypeOf<
72-
SingleValueCollectorWithValue<'RadioCollector'>
73-
>();
74-
expectTypeOf<RadioCollector>()
75-
.toHaveProperty('category')
76-
.toEqualTypeOf<'SingleValueCollector'>();
77-
expectTypeOf<RadioCollector>().toHaveProperty('type').toEqualTypeOf<'RadioCollector'>();
78-
expectTypeOf<RadioCollector['output']>().toHaveProperty('value');
56+
expectTypeOf<SingleSelectCollector>()
57+
.toHaveProperty('type')
58+
.toEqualTypeOf<'SingleSelectCollector'>();
59+
expectTypeOf<SingleSelectCollector['output']>().toHaveProperty('value');
7960
});
8061

81-
it('should validate FlowLinkCollector structure', () => {
82-
expectTypeOf<FlowLinkCollector>().toMatchTypeOf<
83-
SingleValueCollectorNoValue<'FlowLinkCollector'>
62+
it('should validate MultiSelectCollector structure', () => {
63+
expectTypeOf<MultiSelectCollector>().toMatchTypeOf<
64+
MultiValueCollectorWithValue<'MultiSelectCollector'>
8465
>();
85-
expectTypeOf<FlowLinkCollector>()
66+
expectTypeOf<MultiSelectCollector>()
8667
.toHaveProperty('category')
87-
.toEqualTypeOf<'SingleValueCollector'>();
88-
expectTypeOf<FlowLinkCollector>().toHaveProperty('type').toEqualTypeOf<'FlowLinkCollector'>();
89-
expectTypeOf<TextCollector['output']['value']>().toBeString();
68+
.toEqualTypeOf<'MultiValueCollector'>();
69+
expectTypeOf<MultiSelectCollector>()
70+
.toHaveProperty('type')
71+
.toEqualTypeOf<'MultiSelectCollector'>();
72+
expectTypeOf<MultiSelectCollector['output']>().toHaveProperty('value');
9073
});
9174
});
9275

@@ -121,21 +104,19 @@ describe('Collector Types', () => {
121104

122105
describe('Type Inference', () => {
123106
it('should correctly infer SingleValueCollector types', () => {
124-
expectTypeOf<
125-
InferSingleValueCollectorFromSingleValueCollectorType<'TextCollector'>
126-
>().toEqualTypeOf<TextCollector>();
107+
expectTypeOf<InferSingleValueCollectorType<'TextCollector'>>().toEqualTypeOf<TextCollector>();
127108

128109
expectTypeOf<
129-
InferSingleValueCollectorFromSingleValueCollectorType<'PasswordCollector'>
110+
InferSingleValueCollectorType<'PasswordCollector'>
130111
>().toEqualTypeOf<PasswordCollector>();
131112

132113
expectTypeOf<
133-
InferSingleValueCollectorFromSingleValueCollectorType<'DropDownCollector'>
134-
>().toEqualTypeOf<DropDownCollector>();
114+
InferSingleValueCollectorType<'SingleSelectCollector'>
115+
>().toEqualTypeOf<SingleSelectCollector>();
135116
});
136117

137118
it('should handle generic SingleValueCollector type', () => {
138-
type Generic = InferSingleValueCollectorFromSingleValueCollectorType<'SingleValueCollector'>;
119+
type Generic = InferSingleValueCollectorType<'SingleValueCollector'>;
139120
expectTypeOf<Generic>().toMatchTypeOf<
140121
| SingleValueCollectorWithValue<'SingleValueCollector'>
141122
| SingleValueCollectorNoValue<'SingleValueCollector'>
@@ -148,10 +129,7 @@ describe('Collector Types', () => {
148129
const validTypes: SingleValueCollectorTypes[] = [
149130
'TextCollector',
150131
'PasswordCollector',
151-
'DropDownCollector',
152-
'ComboboxCollector',
153-
'RadioCollector',
154-
'FlowLinkCollector',
132+
'SingleSelectCollector',
155133
];
156134

157135
// Type assertion to ensure SingleValueCollectorTypes includes all these values
@@ -245,7 +223,7 @@ describe('Collector Types', () => {
245223
});
246224
describe('InferSingleValueCollectorFromSingleValueCollectorType', () => {
247225
it('should correctly infer TextCollector Type', () => {
248-
const tCollector: InferSingleValueCollectorFromSingleValueCollectorType<'TextCollector'> = {
226+
const tCollector: InferSingleValueCollectorType<'TextCollector'> = {
249227
category: 'SingleValueCollector',
250228
error: null,
251229
type: 'TextCollector',
@@ -267,103 +245,78 @@ describe('Collector Types', () => {
267245
expectTypeOf(tCollector).toMatchTypeOf<TextCollector>();
268246
});
269247
it('should correctly infer PasswordCollector Type', () => {
270-
const tCollector: InferSingleValueCollectorFromSingleValueCollectorType<'PasswordCollector'> =
271-
{
272-
category: 'SingleValueCollector',
273-
error: null,
274-
type: 'PasswordCollector',
275-
id: '',
276-
name: '',
277-
input: {
278-
key: '',
279-
value: '',
280-
type: '',
281-
},
282-
output: {
283-
key: '',
284-
label: '',
285-
type: '',
286-
},
287-
};
248+
const tCollector: InferSingleValueCollectorType<'PasswordCollector'> = {
249+
category: 'SingleValueCollector',
250+
error: null,
251+
type: 'PasswordCollector',
252+
id: '',
253+
name: '',
254+
input: {
255+
key: '',
256+
value: '',
257+
type: '',
258+
},
259+
output: {
260+
key: '',
261+
label: '',
262+
type: '',
263+
},
264+
};
288265

289266
expectTypeOf(tCollector).toMatchTypeOf<PasswordCollector>();
290267
});
291268
it('should correctly infer SingleValueCollector Type', () => {
292-
const tCollector: InferSingleValueCollectorFromSingleValueCollectorType<'SingleValueCollector'> =
293-
{
294-
category: 'SingleValueCollector',
295-
error: null,
296-
type: 'SingleValueCollector',
297-
id: '',
298-
name: '',
299-
input: {
300-
key: '',
301-
value: '',
302-
type: '',
303-
},
304-
output: {
305-
key: '',
306-
label: '',
307-
type: '',
308-
value: '',
309-
},
310-
};
269+
const tCollector: InferSingleValueCollectorType<'SingleValueCollector'> = {
270+
category: 'SingleValueCollector',
271+
error: null,
272+
type: 'SingleValueCollector',
273+
id: '',
274+
name: '',
275+
input: {
276+
key: '',
277+
value: '',
278+
type: '',
279+
},
280+
output: {
281+
key: '',
282+
label: '',
283+
type: '',
284+
value: '',
285+
},
286+
};
311287

312288
expectTypeOf(tCollector).toMatchTypeOf<
313289
SingleValueCollectorWithValue<'SingleValueCollector'>
314290
>();
315291
});
316-
it('should correctly infer ComboboxCollector Type', () => {
317-
const tCollector: InferSingleValueCollectorFromSingleValueCollectorType<'ComboboxCollector'> =
318-
{
319-
category: 'SingleValueCollector',
320-
error: null,
321-
type: 'ComboboxCollector',
322-
id: '',
323-
name: '',
324-
input: {
325-
key: '',
326-
value: '',
327-
type: '',
328-
},
329-
output: {
330-
key: '',
331-
label: '',
332-
type: '',
333-
value: '',
334-
},
335-
};
336-
337-
expectTypeOf(tCollector).toMatchTypeOf<ComboboxCollector>();
338-
});
339-
it('should correctly infer DropDownCollector Type', () => {
340-
const tCollector: InferSingleValueCollectorFromSingleValueCollectorType<'DropDownCollector'> =
341-
{
342-
category: 'SingleValueCollector',
343-
error: null,
344-
type: 'DropDownCollector',
345-
id: '',
346-
name: '',
347-
input: {
348-
key: '',
349-
value: '',
350-
type: '',
351-
},
352-
output: {
353-
key: '',
354-
label: '',
355-
type: '',
356-
value: '',
357-
},
358-
};
292+
it('should correctly infer MultiSelectCollector Type', () => {
293+
const tCollector: InferMultiValueCollectorType<'MultiSelectCollector'> = {
294+
category: 'MultiValueCollector',
295+
error: null,
296+
type: 'MultiSelectCollector',
297+
id: '',
298+
name: '',
299+
input: {
300+
key: '',
301+
value: [''],
302+
type: '',
303+
},
304+
output: {
305+
key: '',
306+
label: '',
307+
type: '',
308+
value: [''],
309+
options: [{ label: '', value: '' }],
310+
},
311+
};
359312

360-
expectTypeOf(tCollector).toMatchTypeOf<DropDownCollector>();
313+
expectTypeOf(tCollector).toMatchTypeOf<MultiSelectCollector>();
361314
});
362-
it('should correctly infer RadioCollector Type', () => {
363-
const tCollector: InferSingleValueCollectorFromSingleValueCollectorType<'RadioCollector'> = {
315+
it('should correctly infer SingleSelectCollector Type', () => {
316+
const tCollector: InferSingleValueCollectorType<'SingleSelectCollector'> = {
364317
category: 'SingleValueCollector',
365318
error: null,
366-
type: 'RadioCollector',
319+
type: 'SingleSelectCollector',
367320
id: '',
368321
name: '',
369322
input: {
@@ -376,32 +329,27 @@ describe('Collector Types', () => {
376329
label: '',
377330
type: '',
378331
value: '',
332+
options: [{ label: '', value: '' }],
379333
},
380334
};
381335

382-
expectTypeOf(tCollector).toMatchTypeOf<RadioCollector>();
336+
expectTypeOf(tCollector).toMatchTypeOf<SingleSelectCollector>();
383337
});
384-
it('should correctly infer FlowLinkCollector Type', () => {
385-
const tCollector: InferSingleValueCollectorFromSingleValueCollectorType<'FlowLinkCollector'> =
386-
{
387-
category: 'SingleValueCollector',
388-
error: null,
389-
type: 'FlowLinkCollector',
390-
id: '',
391-
name: '',
392-
input: {
393-
key: '',
394-
value: '',
395-
type: '',
396-
},
397-
output: {
398-
key: '',
399-
label: '',
400-
type: '',
401-
},
402-
};
338+
it('should correctly infer FlowCollector Type', () => {
339+
const tCollector: InferActionCollectorType<'FlowCollector'> = {
340+
category: 'ActionCollector',
341+
error: null,
342+
type: 'FlowCollector',
343+
id: '',
344+
name: '',
345+
output: {
346+
key: '',
347+
label: '',
348+
type: '',
349+
},
350+
};
403351

404-
expectTypeOf(tCollector).toMatchTypeOf<FlowLinkCollector>();
352+
expectTypeOf(tCollector).toMatchTypeOf<FlowCollector>();
405353
});
406354
});
407355
});

0 commit comments

Comments
 (0)