Skip to content

Commit c7c1d84

Browse files
committed
modify tests
1 parent c1d8eb1 commit c7c1d84

File tree

1 file changed

+73
-32
lines changed

1 file changed

+73
-32
lines changed

packages/form-core/tests/FieldGroupApi.spec.ts

Lines changed: 73 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -922,98 +922,139 @@ describe('field group api', () => {
922922
it('should remap the name of field options correctly', () => {
923923
const form = new FormApi({
924924
defaultValues: {
925-
account: {
926-
password: '',
927-
confirmPassword: '',
925+
user: {
926+
profile: {
927+
personal: {
928+
firstName: '',
929+
lastName: '',
930+
email: '',
931+
},
932+
preferences: {
933+
theme: 'light',
934+
notifications: true,
935+
},
936+
},
937+
settings: {
938+
privacy: {
939+
shareData: false,
940+
allowMarketing: true,
941+
},
942+
},
943+
},
944+
alternateProfile: {
945+
firstName: '',
946+
lastName: '',
947+
email: '',
928948
},
929-
userPassword: '',
930-
userConfirmPassword: '',
931949
},
932950
})
933951
form.mount()
934952

935953
const fieldGroupString = new FieldGroupApi({
936954
form,
937-
fields: 'account',
938-
defaultValues: { password: '' },
955+
fields: 'user.profile.personal',
956+
defaultValues: { firstName: '' },
939957
})
940958
fieldGroupString.mount()
941959

942960
const props1 = {
943-
name: 'password',
961+
name: 'firstName',
944962
}
945963
const remappedProps1 = fieldGroupString.getFormFieldOptions(props1)
946-
expect(remappedProps1.name).toBe('account.password')
964+
expect(remappedProps1.name).toBe('user.profile.personal.firstName')
947965

948966
const fieldGroupObject = new FieldGroupApi({
949967
form,
950968
fields: {
951-
password: 'userPassword',
952-
confirmPassword: 'userConfirmPassword',
969+
firstName: 'alternateProfile.firstName',
970+
lastName: 'alternateProfile.lastName',
971+
email: 'alternateProfile.email',
953972
},
954-
defaultValues: { password: '' },
973+
defaultValues: { firstName: '' },
955974
})
956975
fieldGroupObject.mount()
957976

958977
const props2 = {
959-
name: 'password',
978+
name: 'firstName',
960979
}
961980
const remappedProps2 = fieldGroupObject.getFormFieldOptions(props2)
962-
expect(remappedProps2.name).toBe('userPassword')
981+
expect(remappedProps2.name).toBe('alternateProfile.firstName')
963982
})
964983

965984
it('should remap listener paths with its remapFieldProps method', () => {
966985
const form = new FormApi({
967986
defaultValues: {
968-
account: {
969-
password: '',
970-
confirmPassword: '',
987+
user: {
988+
profile: {
989+
personal: {
990+
firstName: '',
991+
lastName: '',
992+
email: '',
993+
},
994+
preferences: {
995+
theme: 'light',
996+
notifications: true,
997+
},
998+
},
999+
settings: {
1000+
privacy: {
1001+
shareData: false,
1002+
allowMarketing: true,
1003+
},
1004+
},
1005+
},
1006+
alternateProfile: {
1007+
firstName: '',
1008+
lastName: '',
1009+
email: '',
9711010
},
972-
userPassword: '',
973-
userConfirmPassword: '',
9741011
},
9751012
})
9761013
form.mount()
9771014

9781015
const fieldGroupString = new FieldGroupApi({
9791016
form,
980-
fields: 'account',
981-
defaultValues: { password: '', confirmPassword: '' },
1017+
fields: 'user.profile.personal',
1018+
defaultValues: { firstName: '', lastName: '', email: '' },
9821019
})
9831020
fieldGroupString.mount()
9841021

9851022
const props1 = {
986-
name: 'confirmPassword',
1023+
name: 'email',
9871024
validators: {
988-
onChangeListenTo: ['password'],
989-
onBlurListenTo: ['confirmPassword'],
1025+
onChangeListenTo: ['firstName'],
1026+
onBlurListenTo: ['lastName'],
9901027
},
9911028
}
9921029
const remappedProps1 = fieldGroupString.getFormFieldOptions(props1)
9931030
expect(remappedProps1.validators.onChangeListenTo).toEqual([
994-
'account.password',
1031+
'user.profile.personal.firstName',
9951032
])
9961033
expect(remappedProps1.validators.onBlurListenTo).toEqual([
997-
'account.confirmPassword',
1034+
'user.profile.personal.lastName',
9981035
])
9991036

10001037
const fieldGroupObject = new FieldGroupApi({
10011038
form,
10021039
fields: {
1003-
password: 'userPassword',
1004-
confirmPassword: 'userConfirmPassword',
1040+
firstName: 'alternateProfile.firstName',
1041+
lastName: 'alternateProfile.lastName',
1042+
email: 'alternateProfile.email',
10051043
},
1006-
defaultValues: { password: '', confirmPassword: '' },
1044+
defaultValues: { firstName: '', lastName: '', email: '' },
10071045
})
10081046
fieldGroupObject.mount()
10091047

10101048
const props2 = {
1011-
name: 'confirmPassword',
1049+
name: 'email',
10121050
validators: {
1013-
onChangeListenTo: ['password'],
1051+
onChangeListenTo: ['firstName', 'lastName'],
10141052
},
10151053
}
10161054
const remappedProps2 = fieldGroupObject.getFormFieldOptions(props2)
1017-
expect(remappedProps2.validators.onChangeListenTo).toEqual(['userPassword'])
1055+
expect(remappedProps2.validators.onChangeListenTo).toEqual([
1056+
'alternateProfile.firstName',
1057+
'alternateProfile.lastName',
1058+
])
10181059
})
10191060
})

0 commit comments

Comments
 (0)