Skip to content

Commit bcd1d78

Browse files
committed
chore: add-test
1 parent 31d6c10 commit bcd1d78

File tree

3 files changed

+170
-12
lines changed

3 files changed

+170
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Collector Types', () => {
2828
.toEqualTypeOf<'SingleValueCollector'>();
2929
expectTypeOf<TextCollector>().toHaveProperty('type').toEqualTypeOf<'TextCollector'>();
3030
expectTypeOf<TextCollector['output']>().toHaveProperty('value');
31-
expectTypeOf<TextCollector['output']['value']>().toBeString();
31+
expectTypeOf<TextCollector['output']['value']>().toMatchTypeOf<string | boolean | number>();
3232
});
3333

3434
it('should validate PasswordCollector structure', () => {

packages/davinci-client/src/lib/node.reducer.test.ts

Lines changed: 168 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,63 @@ describe('The node collector reducer', () => {
1212
it('should handle next node with one field', () => {
1313
const action = {
1414
type: 'node/next',
15-
payload: [
16-
{
15+
payload: {
16+
fields: [
17+
{
18+
key: 'username',
19+
type: 'TEXT',
20+
label: 'Username',
21+
},
22+
],
23+
formData: {},
24+
},
25+
};
26+
expect(nodeCollectorReducer(undefined, action)).toEqual([
27+
{
28+
category: 'SingleValueCollector',
29+
error: null,
30+
type: 'TextCollector',
31+
id: 'username-0',
32+
name: 'username',
33+
input: {
1734
key: 'username',
35+
value: '',
1836
type: 'TEXT',
37+
},
38+
output: {
39+
key: 'username',
1940
label: 'Username',
41+
type: 'TEXT',
42+
value: '',
2043
},
21-
],
44+
},
45+
]);
46+
});
47+
it('should NOT populate the formData with input information for password collector', () => {
48+
const action = {
49+
type: 'node/next',
50+
payload: {
51+
fields: [
52+
{
53+
key: 'username',
54+
type: 'TEXT',
55+
label: 'Username',
56+
},
57+
{
58+
key: 'password',
59+
type: 'PASSWORD',
60+
label: 'Password',
61+
},
62+
{
63+
key: 'submit',
64+
type: 'SUBMIT_BUTTON',
65+
label: 'Submit',
66+
},
67+
],
68+
formData: {
69+
password: 'SUPERSECRETPASSWORD',
70+
},
71+
},
2272
};
2373
expect(nodeCollectorReducer(undefined, action)).toEqual([
2474
{
@@ -39,29 +89,136 @@ describe('The node collector reducer', () => {
3989
value: '',
4090
},
4191
},
92+
{
93+
category: 'SingleValueCollector',
94+
error: null,
95+
type: 'PasswordCollector',
96+
id: 'password-1',
97+
name: 'password',
98+
input: {
99+
key: 'password',
100+
value: '',
101+
type: 'PASSWORD',
102+
},
103+
output: {
104+
key: 'password',
105+
label: 'Password',
106+
type: 'PASSWORD',
107+
},
108+
},
109+
{
110+
category: 'ActionCollector',
111+
error: null,
112+
type: 'SubmitCollector',
113+
id: 'submit-2',
114+
name: 'submit',
115+
output: {
116+
key: 'submit',
117+
label: 'Submit',
118+
type: 'SUBMIT_BUTTON',
119+
},
120+
},
42121
]);
43122
});
44-
45-
it('should handle next node with multiple fields', () => {
123+
it('should populate the formData with input information', () => {
46124
const action = {
47125
type: 'node/next',
48-
payload: [
49-
{
126+
payload: {
127+
fields: [
128+
{
129+
key: 'username',
130+
type: 'TEXT',
131+
label: 'Username',
132+
},
133+
{
134+
key: 'password',
135+
type: 'PASSWORD',
136+
label: 'Password',
137+
},
138+
{
139+
key: 'submit',
140+
type: 'SUBMIT_BUTTON',
141+
label: 'Submit',
142+
},
143+
],
144+
formData: {
145+
username: 'This is the default data',
146+
},
147+
},
148+
};
149+
expect(nodeCollectorReducer(undefined, action)).toEqual([
150+
{
151+
category: 'SingleValueCollector',
152+
error: null,
153+
type: 'TextCollector',
154+
id: 'username-0',
155+
name: 'username',
156+
input: {
50157
key: 'username',
158+
value: '',
51159
type: 'TEXT',
160+
},
161+
output: {
162+
key: 'username',
52163
label: 'Username',
164+
type: 'TEXT',
165+
value: 'This is the default data',
53166
},
54-
{
167+
},
168+
{
169+
category: 'SingleValueCollector',
170+
error: null,
171+
type: 'PasswordCollector',
172+
id: 'password-1',
173+
name: 'password',
174+
input: {
55175
key: 'password',
176+
value: '',
56177
type: 'PASSWORD',
178+
},
179+
output: {
180+
key: 'password',
57181
label: 'Password',
182+
type: 'PASSWORD',
58183
},
59-
{
184+
},
185+
{
186+
category: 'ActionCollector',
187+
error: null,
188+
type: 'SubmitCollector',
189+
id: 'submit-2',
190+
name: 'submit',
191+
output: {
60192
key: 'submit',
61-
type: 'SUBMIT_BUTTON',
62193
label: 'Submit',
194+
type: 'SUBMIT_BUTTON',
63195
},
64-
],
196+
},
197+
]);
198+
});
199+
it('should handle next node with multiple fields', () => {
200+
const action = {
201+
type: 'node/next',
202+
payload: {
203+
fields: [
204+
{
205+
key: 'username',
206+
type: 'TEXT',
207+
label: 'Username',
208+
},
209+
{
210+
key: 'password',
211+
type: 'PASSWORD',
212+
label: 'Password',
213+
},
214+
{
215+
key: 'submit',
216+
type: 'SUBMIT_BUTTON',
217+
label: 'Submit',
218+
},
219+
],
220+
formData: {},
221+
},
65222
};
66223
expect(nodeCollectorReducer(undefined, action)).toEqual([
67224
{

packages/davinci-client/tsconfig.tsbuildinfo

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)