@teamnovu/kit-vue-forms 0.0.1 → 0.0.2
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/PLAN.md +3 -1
- package/package.json +1 -1
- package/src/composables/useField.ts +4 -4
- package/src/composables/useFieldRegistry.ts +1 -1
- package/src/composables/useForm.ts +5 -5
- package/src/composables/useFormData.ts +4 -4
- package/src/composables/useFormState.ts +2 -3
- package/src/composables/useSubform.ts +4 -4
- package/src/composables/useValidation.ts +5 -8
- package/src/index.ts +1 -1
- package/src/types/form.ts +4 -4
- package/src/utils/path.ts +3 -3
- package/tests/formState.test.ts +36 -65
- package/tests/integration.test.ts +7 -7
- package/tests/nestedPath.test.ts +70 -70
- package/tests/subform.test.ts +64 -64
- package/tests/useField.test.ts +10 -10
- package/tests/useForm.test.ts +3 -3
- package/tests/useValidation.test.ts +9 -9
package/tests/subform.test.ts
CHANGED
|
@@ -20,7 +20,7 @@ describe('Subform Implementation', () => {
|
|
|
20
20
|
|
|
21
21
|
const userForm = form.getSubForm('user')
|
|
22
22
|
|
|
23
|
-
expect(userForm.
|
|
23
|
+
expect(userForm.data.value).toEqual({
|
|
24
24
|
name: 'John',
|
|
25
25
|
email: 'john@example.com',
|
|
26
26
|
})
|
|
@@ -49,11 +49,11 @@ describe('Subform Implementation', () => {
|
|
|
49
49
|
const firstUserForm = form.getSubForm('users.0')
|
|
50
50
|
const secondUserForm = form.getSubForm('users.1')
|
|
51
51
|
|
|
52
|
-
expect(firstUserForm.
|
|
52
|
+
expect(firstUserForm.data.value).toEqual({
|
|
53
53
|
name: 'John',
|
|
54
54
|
email: 'john@example.com',
|
|
55
55
|
})
|
|
56
|
-
expect(secondUserForm.
|
|
56
|
+
expect(secondUserForm.data.value).toEqual({
|
|
57
57
|
name: 'Jane',
|
|
58
58
|
email: 'jane@example.com',
|
|
59
59
|
})
|
|
@@ -81,7 +81,7 @@ describe('Subform Implementation', () => {
|
|
|
81
81
|
const profileForm = userForm.getSubForm('profile')
|
|
82
82
|
const personalForm = profileForm.getSubForm('personal')
|
|
83
83
|
|
|
84
|
-
expect(personalForm.
|
|
84
|
+
expect(personalForm.data.value).toEqual({
|
|
85
85
|
name: 'John',
|
|
86
86
|
age: 30,
|
|
87
87
|
})
|
|
@@ -100,7 +100,7 @@ describe('Subform Implementation', () => {
|
|
|
100
100
|
const nameField = userForm.defineField({ path: 'name' })
|
|
101
101
|
|
|
102
102
|
expect(nameField.path.value).toBe('name')
|
|
103
|
-
expect(nameField.
|
|
103
|
+
expect(nameField.data.value).toBe('John')
|
|
104
104
|
expect(form.getField('user.name')).toBeDefined()
|
|
105
105
|
})
|
|
106
106
|
|
|
@@ -144,7 +144,7 @@ describe('Subform Implementation', () => {
|
|
|
144
144
|
const nameField = profileForm.defineField({ path: 'name' })
|
|
145
145
|
|
|
146
146
|
expect(nameField.path.value).toBe('name')
|
|
147
|
-
expect(nameField.
|
|
147
|
+
expect(nameField.data.value).toBe('John')
|
|
148
148
|
|
|
149
149
|
// Should be registered in main form with full path
|
|
150
150
|
expect(form.getField('user.profile.name')).toBeDefined()
|
|
@@ -160,12 +160,12 @@ describe('Subform Implementation', () => {
|
|
|
160
160
|
const userForm = form.getSubForm('user')
|
|
161
161
|
const nameField = userForm.defineField({ path: 'name' })
|
|
162
162
|
|
|
163
|
-
nameField.
|
|
163
|
+
nameField.setData('Jane')
|
|
164
164
|
await nextTick()
|
|
165
165
|
|
|
166
|
-
expect(nameField.
|
|
167
|
-
expect(userForm.
|
|
168
|
-
expect(form.
|
|
166
|
+
expect(nameField.data.value).toBe('Jane')
|
|
167
|
+
expect(userForm.data.value.name).toBe('Jane')
|
|
168
|
+
expect(form.data.value.user.name).toBe('Jane')
|
|
169
169
|
})
|
|
170
170
|
})
|
|
171
171
|
|
|
@@ -189,7 +189,7 @@ describe('Subform Implementation', () => {
|
|
|
189
189
|
const profileForm = userForm.getSubForm('profile')
|
|
190
190
|
const settingsForm = profileForm.getSubForm('settings')
|
|
191
191
|
|
|
192
|
-
expect(settingsForm.
|
|
192
|
+
expect(settingsForm.data.value).toEqual({
|
|
193
193
|
theme: 'dark',
|
|
194
194
|
notifications: true,
|
|
195
195
|
})
|
|
@@ -218,7 +218,7 @@ describe('Subform Implementation', () => {
|
|
|
218
218
|
const level4Form = level3Form.getSubForm('level4')
|
|
219
219
|
const level5Form = level4Form.getSubForm('level5')
|
|
220
220
|
|
|
221
|
-
expect(level5Form.
|
|
221
|
+
expect(level5Form.data.value).toEqual({
|
|
222
222
|
name: 'Deep Value',
|
|
223
223
|
})
|
|
224
224
|
|
|
@@ -250,7 +250,7 @@ describe('Subform Implementation', () => {
|
|
|
250
250
|
const teamForm = form.getSubForm('teams.0')
|
|
251
251
|
const memberForm = teamForm.getSubForm('members.0')
|
|
252
252
|
|
|
253
|
-
expect(memberForm.
|
|
253
|
+
expect(memberForm.data.value).toEqual({
|
|
254
254
|
name: 'John',
|
|
255
255
|
role: 'lead',
|
|
256
256
|
})
|
|
@@ -279,8 +279,8 @@ describe('Subform Implementation', () => {
|
|
|
279
279
|
})
|
|
280
280
|
|
|
281
281
|
// Set invalid data
|
|
282
|
-
userForm.
|
|
283
|
-
userForm.
|
|
282
|
+
userForm.data.value.name = ''
|
|
283
|
+
userForm.data.value.email = 'invalid'
|
|
284
284
|
|
|
285
285
|
const result = await form.validateForm()
|
|
286
286
|
|
|
@@ -312,8 +312,8 @@ describe('Subform Implementation', () => {
|
|
|
312
312
|
})
|
|
313
313
|
|
|
314
314
|
// Set invalid data
|
|
315
|
-
profileForm.
|
|
316
|
-
profileForm.
|
|
315
|
+
profileForm.data.value.name = ''
|
|
316
|
+
profileForm.data.value.bio = 'Short'
|
|
317
317
|
|
|
318
318
|
const result = await form.validateForm()
|
|
319
319
|
|
|
@@ -535,7 +535,7 @@ describe('Subform Implementation', () => {
|
|
|
535
535
|
expect(userForm.isDirty.value).toBe(false)
|
|
536
536
|
expect(companyForm.isDirty.value).toBe(false)
|
|
537
537
|
|
|
538
|
-
userNameField.
|
|
538
|
+
userNameField.setData('Jane')
|
|
539
539
|
await nextTick()
|
|
540
540
|
|
|
541
541
|
expect(userForm.isDirty.value).toBe(true)
|
|
@@ -562,7 +562,7 @@ describe('Subform Implementation', () => {
|
|
|
562
562
|
|
|
563
563
|
expect(profileForm.isDirty.value).toBe(false)
|
|
564
564
|
|
|
565
|
-
nameField.
|
|
565
|
+
nameField.setData('Jane')
|
|
566
566
|
await nextTick()
|
|
567
567
|
|
|
568
568
|
expect(profileForm.isDirty.value).toBe(true)
|
|
@@ -589,7 +589,7 @@ describe('Subform Implementation', () => {
|
|
|
589
589
|
expect(firstUserForm.isDirty.value).toBe(false)
|
|
590
590
|
expect(secondUserForm.isDirty.value).toBe(false)
|
|
591
591
|
|
|
592
|
-
firstNameField.
|
|
592
|
+
firstNameField.setData('Johnny')
|
|
593
593
|
await nextTick()
|
|
594
594
|
|
|
595
595
|
expect(firstUserForm.isDirty.value).toBe(true)
|
|
@@ -798,19 +798,19 @@ describe('Subform Implementation', () => {
|
|
|
798
798
|
const companyNameField = companyForm.defineField({ path: 'name' })
|
|
799
799
|
|
|
800
800
|
// Change values
|
|
801
|
-
userNameField.
|
|
802
|
-
companyNameField.
|
|
801
|
+
userNameField.setData('Jane')
|
|
802
|
+
companyNameField.setData('New Corp')
|
|
803
803
|
await nextTick()
|
|
804
804
|
|
|
805
|
-
expect(userForm.
|
|
806
|
-
expect(companyForm.
|
|
805
|
+
expect(userForm.data.value.name).toBe('Jane')
|
|
806
|
+
expect(companyForm.data.value.name).toBe('New Corp')
|
|
807
807
|
|
|
808
808
|
// Reset only user subform
|
|
809
809
|
userForm.reset()
|
|
810
810
|
await nextTick()
|
|
811
811
|
|
|
812
|
-
expect(userForm.
|
|
813
|
-
expect(companyForm.
|
|
812
|
+
expect(userForm.data.value.name).toBe('John')
|
|
813
|
+
expect(companyForm.data.value.name).toBe('New Corp')
|
|
814
814
|
})
|
|
815
815
|
|
|
816
816
|
it('should handle nested subform reset', async () => {
|
|
@@ -832,19 +832,19 @@ describe('Subform Implementation', () => {
|
|
|
832
832
|
const bioField = profileForm.defineField({ path: 'bio' })
|
|
833
833
|
|
|
834
834
|
// Change values
|
|
835
|
-
nameField.
|
|
836
|
-
bioField.
|
|
835
|
+
nameField.setData('Jane')
|
|
836
|
+
bioField.setData('Designer')
|
|
837
837
|
await nextTick()
|
|
838
838
|
|
|
839
|
-
expect(profileForm.
|
|
840
|
-
expect(profileForm.
|
|
839
|
+
expect(profileForm.data.value.name).toBe('Jane')
|
|
840
|
+
expect(profileForm.data.value.bio).toBe('Designer')
|
|
841
841
|
|
|
842
842
|
// Reset profile subform
|
|
843
843
|
profileForm.reset()
|
|
844
844
|
await nextTick()
|
|
845
845
|
|
|
846
|
-
expect(profileForm.
|
|
847
|
-
expect(profileForm.
|
|
846
|
+
expect(profileForm.data.value.name).toBe('John')
|
|
847
|
+
expect(profileForm.data.value.bio).toBe('Developer')
|
|
848
848
|
})
|
|
849
849
|
|
|
850
850
|
it('should handle array subform reset', async () => {
|
|
@@ -864,19 +864,19 @@ describe('Subform Implementation', () => {
|
|
|
864
864
|
const secondNameField = secondUserForm.defineField({ path: 'name' })
|
|
865
865
|
|
|
866
866
|
// Change values
|
|
867
|
-
firstNameField.
|
|
868
|
-
secondNameField.
|
|
867
|
+
firstNameField.setData('Johnny')
|
|
868
|
+
secondNameField.setData('Janie')
|
|
869
869
|
await nextTick()
|
|
870
870
|
|
|
871
|
-
expect(firstUserForm.
|
|
872
|
-
expect(secondUserForm.
|
|
871
|
+
expect(firstUserForm.data.value.name).toBe('Johnny')
|
|
872
|
+
expect(secondUserForm.data.value.name).toBe('Janie')
|
|
873
873
|
|
|
874
874
|
// Reset only first user subform
|
|
875
875
|
firstUserForm.reset()
|
|
876
876
|
await nextTick()
|
|
877
877
|
|
|
878
|
-
expect(firstUserForm.
|
|
879
|
-
expect(secondUserForm.
|
|
878
|
+
expect(firstUserForm.data.value.name).toBe('John')
|
|
879
|
+
expect(secondUserForm.data.value.name).toBe('Janie')
|
|
880
880
|
})
|
|
881
881
|
})
|
|
882
882
|
|
|
@@ -892,18 +892,18 @@ describe('Subform Implementation', () => {
|
|
|
892
892
|
const nameField = userForm.defineField({ path: 'name' })
|
|
893
893
|
|
|
894
894
|
// Change through subform
|
|
895
|
-
userForm.
|
|
895
|
+
userForm.data.value.name = 'Jane'
|
|
896
896
|
await nextTick()
|
|
897
897
|
|
|
898
|
-
expect(form.
|
|
899
|
-
expect(nameField.
|
|
898
|
+
expect(form.data.value.user.name).toBe('Jane')
|
|
899
|
+
expect(nameField.data.value).toBe('Jane')
|
|
900
900
|
|
|
901
901
|
// Change through main form
|
|
902
|
-
form.
|
|
902
|
+
form.data.value.user.name = 'Bob'
|
|
903
903
|
await nextTick()
|
|
904
904
|
|
|
905
|
-
expect(userForm.
|
|
906
|
-
expect(nameField.
|
|
905
|
+
expect(userForm.data.value.name).toBe('Bob')
|
|
906
|
+
expect(nameField.data.value).toBe('Bob')
|
|
907
907
|
})
|
|
908
908
|
|
|
909
909
|
it('should handle state changes through main form', async () => {
|
|
@@ -921,11 +921,11 @@ describe('Subform Implementation', () => {
|
|
|
921
921
|
const profileForm = userForm.getSubForm('profile')
|
|
922
922
|
|
|
923
923
|
// Change through main form
|
|
924
|
-
form.
|
|
924
|
+
form.data.value.user.profile.name = 'Jane'
|
|
925
925
|
await nextTick()
|
|
926
926
|
|
|
927
|
-
expect(userForm.
|
|
928
|
-
expect(profileForm.
|
|
927
|
+
expect(userForm.data.value.profile.name).toBe('Jane')
|
|
928
|
+
expect(profileForm.data.value.name).toBe('Jane')
|
|
929
929
|
})
|
|
930
930
|
|
|
931
931
|
it('should handle initial data changes', async () => {
|
|
@@ -1042,7 +1042,7 @@ describe('Subform Implementation', () => {
|
|
|
1042
1042
|
})
|
|
1043
1043
|
|
|
1044
1044
|
const userForm = form.getSubForm('user-name')
|
|
1045
|
-
expect(userForm.
|
|
1045
|
+
expect(userForm.data.value).toEqual({ 'first-name': 'John' })
|
|
1046
1046
|
})
|
|
1047
1047
|
|
|
1048
1048
|
it('should handle numeric string paths', () => {
|
|
@@ -1053,7 +1053,7 @@ describe('Subform Implementation', () => {
|
|
|
1053
1053
|
})
|
|
1054
1054
|
|
|
1055
1055
|
const numericForm = form.getSubForm('123')
|
|
1056
|
-
expect(numericForm.
|
|
1056
|
+
expect(numericForm.data.value).toEqual({ name: 'test' })
|
|
1057
1057
|
})
|
|
1058
1058
|
})
|
|
1059
1059
|
|
|
@@ -1069,8 +1069,8 @@ describe('Subform Implementation', () => {
|
|
|
1069
1069
|
})
|
|
1070
1070
|
|
|
1071
1071
|
const userForm = form.getSubForm('user')
|
|
1072
|
-
expect(userForm.
|
|
1073
|
-
expect(userForm.
|
|
1072
|
+
expect(userForm.data.value.name).toBe(null)
|
|
1073
|
+
expect(userForm.data.value.email).toBe('test@example.com')
|
|
1074
1074
|
})
|
|
1075
1075
|
|
|
1076
1076
|
it('should handle undefined values in subform data', () => {
|
|
@@ -1084,8 +1084,8 @@ describe('Subform Implementation', () => {
|
|
|
1084
1084
|
})
|
|
1085
1085
|
|
|
1086
1086
|
const userForm = form.getSubForm('user')
|
|
1087
|
-
expect(userForm.
|
|
1088
|
-
expect(userForm.
|
|
1087
|
+
expect(userForm.data.value.name).toBe(undefined)
|
|
1088
|
+
expect(userForm.data.value.email).toBe('test@example.com')
|
|
1089
1089
|
})
|
|
1090
1090
|
|
|
1091
1091
|
it('should handle empty objects', () => {
|
|
@@ -1096,7 +1096,7 @@ describe('Subform Implementation', () => {
|
|
|
1096
1096
|
})
|
|
1097
1097
|
|
|
1098
1098
|
const userForm = form.getSubForm('user' as never)
|
|
1099
|
-
expect(userForm.
|
|
1099
|
+
expect(userForm.data.value).toEqual({})
|
|
1100
1100
|
})
|
|
1101
1101
|
|
|
1102
1102
|
it('should handle empty arrays', () => {
|
|
@@ -1107,7 +1107,7 @@ describe('Subform Implementation', () => {
|
|
|
1107
1107
|
})
|
|
1108
1108
|
|
|
1109
1109
|
const usersForm = form.getSubForm('users')
|
|
1110
|
-
expect(usersForm.
|
|
1110
|
+
expect(usersForm.data.value).toEqual([])
|
|
1111
1111
|
})
|
|
1112
1112
|
})
|
|
1113
1113
|
})
|
|
@@ -1152,8 +1152,8 @@ describe('Subform Implementation', () => {
|
|
|
1152
1152
|
// Should complete within reasonable time (less than 100ms)
|
|
1153
1153
|
expect(duration).toBeLessThan(100)
|
|
1154
1154
|
expect(subforms).toHaveLength(100)
|
|
1155
|
-
expect(subforms[0].
|
|
1156
|
-
expect(subforms[99].
|
|
1155
|
+
expect(subforms[0].data.value.name).toBe('User 0')
|
|
1156
|
+
expect(subforms[99].data.value.name).toBe('User 99')
|
|
1157
1157
|
})
|
|
1158
1158
|
|
|
1159
1159
|
it('should handle rapid field registration efficiently', () => {
|
|
@@ -1188,7 +1188,7 @@ describe('Subform Implementation', () => {
|
|
|
1188
1188
|
// Should complete within reasonable time
|
|
1189
1189
|
expect(duration).toBeLessThan(50)
|
|
1190
1190
|
expect(fields).toHaveLength(5)
|
|
1191
|
-
expect(fields[0].
|
|
1191
|
+
expect(fields[0].data.value).toBe('John')
|
|
1192
1192
|
})
|
|
1193
1193
|
|
|
1194
1194
|
it('should handle complex validation on large forms', async () => {
|
|
@@ -1273,14 +1273,14 @@ describe('Subform Implementation', () => {
|
|
|
1273
1273
|
let userForm: Form<{
|
|
1274
1274
|
name: string
|
|
1275
1275
|
}> | undefined = form.getSubForm('users.0')
|
|
1276
|
-
expect(userForm.
|
|
1276
|
+
expect(userForm.data.value.name).toBe('John')
|
|
1277
1277
|
|
|
1278
1278
|
// Remove reference
|
|
1279
1279
|
userForm = undefined
|
|
1280
1280
|
|
|
1281
1281
|
// Should not cause issues
|
|
1282
1282
|
const newUserForm = form.getSubForm('users.0')
|
|
1283
|
-
expect(newUserForm.
|
|
1283
|
+
expect(newUserForm.data.value.name).toBe('John')
|
|
1284
1284
|
})
|
|
1285
1285
|
})
|
|
1286
1286
|
|
|
@@ -1299,7 +1299,7 @@ describe('Subform Implementation', () => {
|
|
|
1299
1299
|
|
|
1300
1300
|
// Make many rapid updates
|
|
1301
1301
|
for (let i = 0; i < 100; i++) {
|
|
1302
|
-
nameField.
|
|
1302
|
+
nameField.setData(`Name ${i}`)
|
|
1303
1303
|
await nextTick()
|
|
1304
1304
|
}
|
|
1305
1305
|
|
|
@@ -1308,7 +1308,7 @@ describe('Subform Implementation', () => {
|
|
|
1308
1308
|
|
|
1309
1309
|
// Should complete within reasonable time (less than 500ms)
|
|
1310
1310
|
expect(duration).toBeLessThan(500)
|
|
1311
|
-
expect(nameField.
|
|
1311
|
+
expect(nameField.data.value).toBe('Name 99')
|
|
1312
1312
|
})
|
|
1313
1313
|
|
|
1314
1314
|
it('should handle nested reactivity updates efficiently', async () => {
|
|
@@ -1332,7 +1332,7 @@ describe('Subform Implementation', () => {
|
|
|
1332
1332
|
|
|
1333
1333
|
// Make updates at different levels
|
|
1334
1334
|
for (let i = 0; i < 50; i++) {
|
|
1335
|
-
personalForm.
|
|
1335
|
+
personalForm.data.value.name = `Name ${i}`
|
|
1336
1336
|
await nextTick()
|
|
1337
1337
|
}
|
|
1338
1338
|
|
|
@@ -1341,7 +1341,7 @@ describe('Subform Implementation', () => {
|
|
|
1341
1341
|
|
|
1342
1342
|
// Should complete within reasonable time
|
|
1343
1343
|
expect(duration).toBeLessThan(500)
|
|
1344
|
-
expect(personalForm.
|
|
1344
|
+
expect(personalForm.data.value.name).toBe('Name 49')
|
|
1345
1345
|
})
|
|
1346
1346
|
})
|
|
1347
1347
|
})
|
package/tests/useField.test.ts
CHANGED
|
@@ -18,7 +18,7 @@ describe('useField', () => {
|
|
|
18
18
|
initialValue: 'John',
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
expect(field.
|
|
21
|
+
expect(field.data.value).toBe('John')
|
|
22
22
|
expect(field.initialValue.value).toBe('John')
|
|
23
23
|
expect(field.dirty.value).toBe(false)
|
|
24
24
|
})
|
|
@@ -32,8 +32,8 @@ describe('useField', () => {
|
|
|
32
32
|
|
|
33
33
|
expect(field.dirty.value).toBe(false)
|
|
34
34
|
|
|
35
|
-
field.
|
|
36
|
-
expect(field.
|
|
35
|
+
field.setData('Jane')
|
|
36
|
+
expect(field.data.value).toBe('Jane')
|
|
37
37
|
expect(field.dirty.value).toBe(true)
|
|
38
38
|
})
|
|
39
39
|
|
|
@@ -98,18 +98,18 @@ describe('useField', () => {
|
|
|
98
98
|
initialValue: 'Initial',
|
|
99
99
|
})
|
|
100
100
|
|
|
101
|
-
field.
|
|
101
|
+
field.setData('Modified')
|
|
102
102
|
field.onBlur()
|
|
103
103
|
field.setErrors(['Error'])
|
|
104
104
|
|
|
105
|
-
expect(field.
|
|
105
|
+
expect(field.data.value).toBe('Modified')
|
|
106
106
|
expect(field.touched.value).toBe(true)
|
|
107
107
|
expect(field.errors.value).toEqual(['Error'])
|
|
108
108
|
expect(field.dirty.value).toBe(true)
|
|
109
109
|
|
|
110
110
|
field.reset()
|
|
111
111
|
|
|
112
|
-
expect(field.
|
|
112
|
+
expect(field.data.value).toBe('Initial')
|
|
113
113
|
expect(field.touched.value).toBe(false)
|
|
114
114
|
expect(field.errors.value).toEqual([])
|
|
115
115
|
expect(field.dirty.value).toBe(false)
|
|
@@ -123,10 +123,10 @@ describe('useField', () => {
|
|
|
123
123
|
initialValue,
|
|
124
124
|
})
|
|
125
125
|
|
|
126
|
-
expect(field.
|
|
126
|
+
expect(field.data.value).toEqual(initialValue)
|
|
127
127
|
expect(field.dirty.value).toBe(false)
|
|
128
128
|
|
|
129
|
-
field.
|
|
129
|
+
field.setData({ nested: { value: 'changed' } })
|
|
130
130
|
expect(field.dirty.value).toBe(true)
|
|
131
131
|
})
|
|
132
132
|
|
|
@@ -138,10 +138,10 @@ describe('useField', () => {
|
|
|
138
138
|
initialValue,
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
expect(field.
|
|
141
|
+
expect(field.data.value).toEqual(initialValue)
|
|
142
142
|
expect(field.dirty.value).toBe(false)
|
|
143
143
|
|
|
144
|
-
field.
|
|
144
|
+
field.setData(['a', 'b', 'c', 'd'])
|
|
145
145
|
expect(field.dirty.value).toBe(true)
|
|
146
146
|
})
|
|
147
147
|
})
|
package/tests/useForm.test.ts
CHANGED
|
@@ -11,7 +11,7 @@ describe('useForm', () => {
|
|
|
11
11
|
}
|
|
12
12
|
const form = useForm({ initialData })
|
|
13
13
|
|
|
14
|
-
expect(form.
|
|
14
|
+
expect(form.data.value).toEqual(initialData)
|
|
15
15
|
expect(form.initialData.value).toEqual(initialData)
|
|
16
16
|
})
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ describe('useForm', () => {
|
|
|
22
22
|
})
|
|
23
23
|
const form = useForm({ initialData })
|
|
24
24
|
|
|
25
|
-
expect(form.
|
|
25
|
+
expect(form.data.value).toEqual({
|
|
26
26
|
name: 'John',
|
|
27
27
|
age: 30,
|
|
28
28
|
})
|
|
@@ -100,7 +100,7 @@ describe('useForm', () => {
|
|
|
100
100
|
}
|
|
101
101
|
const form = useForm({ initialData })
|
|
102
102
|
|
|
103
|
-
expect(form.
|
|
103
|
+
expect(form.data.value).toEqual(initialData)
|
|
104
104
|
expect(form.initialData.value).toEqual(initialData)
|
|
105
105
|
})
|
|
106
106
|
|
|
@@ -7,7 +7,7 @@ import { hasErrors } from '../src/utils/validation'
|
|
|
7
7
|
|
|
8
8
|
describe('useValidation', () => {
|
|
9
9
|
it('should initialize with no errors', () => {
|
|
10
|
-
const formState = {
|
|
10
|
+
const formState = { data: { name: 'John' } }
|
|
11
11
|
const validation = useValidation(formState, {})
|
|
12
12
|
|
|
13
13
|
expect(validation.isValidated.value).toBe(false)
|
|
@@ -22,7 +22,7 @@ describe('useValidation', () => {
|
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
const formState = {
|
|
25
|
-
|
|
25
|
+
data: {
|
|
26
26
|
name: 'John',
|
|
27
27
|
age: 30,
|
|
28
28
|
},
|
|
@@ -44,7 +44,7 @@ describe('useValidation', () => {
|
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
const formState = {
|
|
47
|
-
|
|
47
|
+
data: {
|
|
48
48
|
name: 'A',
|
|
49
49
|
age: 16,
|
|
50
50
|
},
|
|
@@ -80,7 +80,7 @@ describe('useValidation', () => {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
const formState = {
|
|
83
|
+
const formState = { data: { name: 'A' } }
|
|
84
84
|
const validation = useValidation(formState, { validateFn })
|
|
85
85
|
|
|
86
86
|
const result = await validation.validateForm()
|
|
@@ -102,7 +102,7 @@ describe('useValidation', () => {
|
|
|
102
102
|
},
|
|
103
103
|
})
|
|
104
104
|
|
|
105
|
-
const formState = {
|
|
105
|
+
const formState = { data: { name: 'forbidden' } }
|
|
106
106
|
const validation = useValidation(formState, {
|
|
107
107
|
schema,
|
|
108
108
|
validateFn,
|
|
@@ -120,7 +120,7 @@ describe('useValidation', () => {
|
|
|
120
120
|
}))
|
|
121
121
|
|
|
122
122
|
const formState = {
|
|
123
|
-
|
|
123
|
+
data: {
|
|
124
124
|
name: 'A',
|
|
125
125
|
age: 25,
|
|
126
126
|
},
|
|
@@ -159,7 +159,7 @@ describe('useValidation', () => {
|
|
|
159
159
|
})
|
|
160
160
|
|
|
161
161
|
const validateFn = ref(strictValidation)
|
|
162
|
-
const formState = {
|
|
162
|
+
const formState = { data: { name: 'John' } }
|
|
163
163
|
const validation = useValidation(formState, { validateFn })
|
|
164
164
|
|
|
165
165
|
// Initial validation with strict rules
|
|
@@ -179,7 +179,7 @@ describe('useValidation', () => {
|
|
|
179
179
|
propertyErrors: { name: ['External field error'] },
|
|
180
180
|
})
|
|
181
181
|
|
|
182
|
-
const formState = {
|
|
182
|
+
const formState = { data: { name: 'John' } }
|
|
183
183
|
const validation = useValidation(formState, { errors })
|
|
184
184
|
|
|
185
185
|
await nextTick()
|
|
@@ -195,7 +195,7 @@ describe('useValidation', () => {
|
|
|
195
195
|
|
|
196
196
|
const errors = ref<ErrorBag>(SuccessValidationResult.errors)
|
|
197
197
|
|
|
198
|
-
const formState = {
|
|
198
|
+
const formState = { data: { name: 'A' } }
|
|
199
199
|
const validation = useValidation(formState, {
|
|
200
200
|
schema,
|
|
201
201
|
errors,
|