cozy-ui 128.1.0 → 128.3.0
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/CHANGELOG.md +15 -0
- package/package.json +5 -1
- package/react/ActionsMenu/Actions/viewInDrive.js +2 -1
- package/react/Contacts/AddModal/ContactAddressDialog/helpers.js +22 -0
- package/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.js +64 -0
- package/react/Contacts/AddModal/ContactAddressDialog/index.jsx +84 -0
- package/react/Contacts/AddModal/ContactAddressDialog/locales/en.json +25 -0
- package/react/Contacts/AddModal/ContactAddressDialog/locales/fr.json +25 -0
- package/react/Contacts/AddModal/ContactAddressDialog/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/ContactForm/FieldInput.jsx +117 -0
- package/react/Contacts/AddModal/ContactForm/FieldInputArray.jsx +80 -0
- package/react/Contacts/AddModal/ContactForm/FieldInputLayout.jsx +65 -0
- package/react/Contacts/AddModal/ContactForm/FieldInputWrapper.jsx +41 -0
- package/react/Contacts/AddModal/ContactForm/HasValueCondition.jsx +31 -0
- package/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.jsx +79 -0
- package/react/Contacts/AddModal/ContactForm/RelatedContactList.jsx +37 -0
- package/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.jsx +78 -0
- package/react/Contacts/AddModal/ContactForm/TextFieldSelect.jsx +39 -0
- package/react/Contacts/AddModal/ContactForm/__snapshots__/HasValueCondition.spec.jsx.snap +33 -0
- package/react/Contacts/AddModal/ContactForm/contactToFormValues.js +99 -0
- package/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.js +128 -0
- package/react/Contacts/AddModal/ContactForm/fieldsConfig.jsx +341 -0
- package/react/Contacts/AddModal/ContactForm/formValuesToContact.js +100 -0
- package/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.js +494 -0
- package/react/Contacts/AddModal/ContactForm/helpers.js +324 -0
- package/react/Contacts/AddModal/ContactForm/helpers.spec.js +152 -0
- package/react/Contacts/AddModal/ContactForm/index.jsx +104 -0
- package/react/Contacts/AddModal/ContactForm/index.spec.jsx +289 -0
- package/react/Contacts/AddModal/ContactForm/locales/en.json +73 -0
- package/react/Contacts/AddModal/ContactForm/locales/fr.json +73 -0
- package/react/Contacts/AddModal/ContactForm/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/ContactForm/styles.styl +2 -0
- package/react/Contacts/AddModal/CustomLabelDialog/index.jsx +108 -0
- package/react/Contacts/AddModal/CustomLabelDialog/locales/en.json +15 -0
- package/react/Contacts/AddModal/CustomLabelDialog/locales/fr.json +15 -0
- package/react/Contacts/AddModal/CustomLabelDialog/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/Readme.md +46 -0
- package/react/Contacts/AddModal/index.jsx +78 -0
- package/react/Contacts/AddModal/locales/en.json +13 -0
- package/react/Contacts/AddModal/locales/fr.json +13 -0
- package/react/Contacts/AddModal/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/mocks.js +249 -0
- package/react/Contacts/AddModal/types.js +57 -0
- package/react/Contacts/Header/Readme.md +0 -2
- package/react/providers/DemoProvider.jsx +3 -2
- package/transpiled/react/ActionsMenu/Actions/viewInDrive.js +2 -1
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.d.ts +4 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.js +20 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.d.ts +39 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.js +87 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.js +54 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.d.ts +35 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.js +126 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.d.ts +14 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.js +82 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.d.ts +20 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.js +70 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.d.ts +16 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.js +31 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.d.ts +18 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.js +32 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.d.ts +15 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.js +39 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.d.ts +9 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.js +81 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.d.ts +5 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.js +42 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.d.ts +2 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.js +88 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.d.ts +4 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.js +278 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.js +94 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/helpers.d.ts +28 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/helpers.js +335 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/helpers.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/index.d.ts +11 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/index.js +114 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/index.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.js +150 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.d.ts +22 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.js +113 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.js +34 -0
- package/transpiled/react/Contacts/AddModal/index.d.ts +7 -0
- package/transpiled/react/Contacts/AddModal/index.js +109 -0
- package/transpiled/react/Contacts/AddModal/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/locales/index.js +30 -0
- package/transpiled/react/Contacts/AddModal/mocks.d.ts +270 -0
- package/transpiled/react/Contacts/AddModal/mocks.js +214 -0
- package/transpiled/react/Contacts/AddModal/types.d.ts +54 -0
- package/transpiled/react/Contacts/AddModal/types.js +49 -0
- package/transpiled/react/providers/DemoProvider.d.ts +2 -1
- package/transpiled/react/providers/DemoProvider.js +7 -3
- package/transpiled/react/stylesheet.css +1 -1
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import Polyglot from 'node-polyglot'
|
|
2
|
+
|
|
3
|
+
import { updateIndexFullNameAndDisplayName } from 'cozy-client/dist/models/contact'
|
|
4
|
+
|
|
5
|
+
import formValuesToContact from './formValuesToContact'
|
|
6
|
+
import en from './locales/en.json'
|
|
7
|
+
import { johnDoeFormValues, johnDoeContact } from '../mocks'
|
|
8
|
+
|
|
9
|
+
const polyglot = new Polyglot()
|
|
10
|
+
polyglot.extend(en)
|
|
11
|
+
const t = polyglot.t.bind(polyglot)
|
|
12
|
+
|
|
13
|
+
describe('formValuesToContact', () => {
|
|
14
|
+
it('should convert form values to contact when creating a contact', () => {
|
|
15
|
+
const expected = {
|
|
16
|
+
address: [
|
|
17
|
+
{
|
|
18
|
+
formattedAddress: '94 Hinton Road 05034 Fresno, Singapore',
|
|
19
|
+
city: undefined,
|
|
20
|
+
code: undefined,
|
|
21
|
+
region: undefined,
|
|
22
|
+
country: undefined,
|
|
23
|
+
extendedAddress: {
|
|
24
|
+
apartment: undefined,
|
|
25
|
+
floor: undefined,
|
|
26
|
+
locality: undefined,
|
|
27
|
+
stairs: undefined,
|
|
28
|
+
entrycode: undefined,
|
|
29
|
+
building: undefined
|
|
30
|
+
},
|
|
31
|
+
number: undefined,
|
|
32
|
+
street: '94 Hinton Road 05034 Fresno, Singapore',
|
|
33
|
+
primary: true,
|
|
34
|
+
type: 'Home',
|
|
35
|
+
label: undefined
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
formattedAddress:
|
|
39
|
+
'426 Runolfsson Knolls 84573 Port Easter Cocos (Keeling) Islands',
|
|
40
|
+
city: 'Port Easter',
|
|
41
|
+
code: '84573',
|
|
42
|
+
country: 'Cocos (Keeling) Islands',
|
|
43
|
+
extendedAddress: {
|
|
44
|
+
apartment: undefined,
|
|
45
|
+
floor: undefined,
|
|
46
|
+
locality: undefined,
|
|
47
|
+
stairs: undefined,
|
|
48
|
+
entrycode: undefined,
|
|
49
|
+
building: undefined
|
|
50
|
+
},
|
|
51
|
+
number: undefined,
|
|
52
|
+
street: '426 Runolfsson Knolls',
|
|
53
|
+
region: undefined,
|
|
54
|
+
primary: false,
|
|
55
|
+
type: 'Work',
|
|
56
|
+
label: undefined
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
birthday: '1999-5-1',
|
|
60
|
+
birthplace: 'somewhere',
|
|
61
|
+
gender: 'male',
|
|
62
|
+
company: 'Cozy cloud',
|
|
63
|
+
cozy: [
|
|
64
|
+
{
|
|
65
|
+
type: 'MyCozy',
|
|
66
|
+
label: undefined,
|
|
67
|
+
primary: true,
|
|
68
|
+
url: 'https://johndoe.mycozy.cloud'
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
displayName: 'John J. Doe',
|
|
72
|
+
email: [
|
|
73
|
+
{
|
|
74
|
+
address: 'john.doe@cozycloud.cc',
|
|
75
|
+
primary: true,
|
|
76
|
+
type: undefined,
|
|
77
|
+
label: undefined
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
address: 'john.doe@posteo.net',
|
|
81
|
+
primary: false,
|
|
82
|
+
type: 'personal',
|
|
83
|
+
label: undefined
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
fullname: 'John J. Doe',
|
|
87
|
+
indexes: {
|
|
88
|
+
byFamilyNameGivenNameEmailCozyUrl:
|
|
89
|
+
'doejohnjohn.doe@cozycloud.ccjohndoe.mycozy.cloud'
|
|
90
|
+
},
|
|
91
|
+
jobTitle: 'Dreamer',
|
|
92
|
+
metadata: { cozy: true, version: 1 },
|
|
93
|
+
name: {
|
|
94
|
+
familyName: 'Doe',
|
|
95
|
+
givenName: 'John',
|
|
96
|
+
additionalName: 'J.',
|
|
97
|
+
surname: undefined
|
|
98
|
+
},
|
|
99
|
+
note: 'Atque cupiditate saepe omnis quos ut molestiae labore voluptates omnis.',
|
|
100
|
+
phone: [
|
|
101
|
+
{
|
|
102
|
+
number: '+33 (2)0 90 00 54 04',
|
|
103
|
+
primary: true,
|
|
104
|
+
type: undefined,
|
|
105
|
+
label: undefined
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
number: '+33 6 77 11 22 33',
|
|
109
|
+
primary: false,
|
|
110
|
+
type: undefined,
|
|
111
|
+
label: undefined
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
relationships: {
|
|
115
|
+
groups: {
|
|
116
|
+
data: []
|
|
117
|
+
},
|
|
118
|
+
related: {
|
|
119
|
+
data: [
|
|
120
|
+
{
|
|
121
|
+
_id: 'relatedContactID',
|
|
122
|
+
_type: 'io.cozy.contacts',
|
|
123
|
+
metadata: {
|
|
124
|
+
relationTypes: ['related']
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const result = formValuesToContact({
|
|
133
|
+
formValues: johnDoeFormValues,
|
|
134
|
+
oldContact: null,
|
|
135
|
+
t
|
|
136
|
+
})
|
|
137
|
+
expect(result).toEqual(expected)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('should convert form values that have been cleared to contact', () => {
|
|
141
|
+
const formValues = {
|
|
142
|
+
address: [
|
|
143
|
+
{
|
|
144
|
+
formattedAddress: undefined,
|
|
145
|
+
primary: true,
|
|
146
|
+
type: undefined,
|
|
147
|
+
label: undefined
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
birthday: undefined,
|
|
151
|
+
birthplace: 'somewhere',
|
|
152
|
+
gender: 'female',
|
|
153
|
+
company: undefined,
|
|
154
|
+
jobTitle: undefined,
|
|
155
|
+
cozy: undefined,
|
|
156
|
+
cozyLabel: undefined,
|
|
157
|
+
email: [
|
|
158
|
+
{
|
|
159
|
+
email: undefined,
|
|
160
|
+
emailLabel: undefined
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
familyName: 'Doe',
|
|
164
|
+
givenName: 'Jane',
|
|
165
|
+
note: undefined,
|
|
166
|
+
relatedContact: [],
|
|
167
|
+
phone: [
|
|
168
|
+
{
|
|
169
|
+
number: undefined,
|
|
170
|
+
primary: true,
|
|
171
|
+
type: undefined
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const expected = {
|
|
177
|
+
address: [],
|
|
178
|
+
birthday: '',
|
|
179
|
+
birthplace: 'somewhere',
|
|
180
|
+
gender: 'female',
|
|
181
|
+
company: '',
|
|
182
|
+
cozy: [],
|
|
183
|
+
displayName: 'Jane Doe',
|
|
184
|
+
email: [],
|
|
185
|
+
fullname: 'Jane Doe',
|
|
186
|
+
indexes: { byFamilyNameGivenNameEmailCozyUrl: 'doejane' },
|
|
187
|
+
jobTitle: '',
|
|
188
|
+
metadata: { cozy: true, version: 1 },
|
|
189
|
+
name: { familyName: 'Doe', givenName: 'Jane' },
|
|
190
|
+
note: '',
|
|
191
|
+
phone: [],
|
|
192
|
+
relationships: { groups: { data: [] }, related: { data: [] } }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const result = formValuesToContact({ formValues, oldContact: null, t })
|
|
196
|
+
expect(result).toEqual(expected)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
it('should not erase metadata.google if it was present in the contact', () => {
|
|
200
|
+
const oldContact = {
|
|
201
|
+
metadata: {
|
|
202
|
+
google: {
|
|
203
|
+
metadata: {
|
|
204
|
+
sources: [
|
|
205
|
+
{
|
|
206
|
+
etag: 'bb0d4f0c-ac79-4519-8873-e0445b378fd7'
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const expectedMetadata = {
|
|
215
|
+
cozy: true,
|
|
216
|
+
google: {
|
|
217
|
+
metadata: {
|
|
218
|
+
sources: [
|
|
219
|
+
{
|
|
220
|
+
etag: 'bb0d4f0c-ac79-4519-8873-e0445b378fd7'
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
version: 1
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const result = formValuesToContact({
|
|
229
|
+
formValues: johnDoeFormValues,
|
|
230
|
+
oldContact,
|
|
231
|
+
t
|
|
232
|
+
})
|
|
233
|
+
expect(result.metadata).toEqual(expectedMetadata)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('should not remove additional data if it was present in the contact', () => {
|
|
237
|
+
const oldContact = {
|
|
238
|
+
name: {
|
|
239
|
+
additionalName: 'J.',
|
|
240
|
+
familyName: 'House',
|
|
241
|
+
givenName: 'Gregory',
|
|
242
|
+
namePrefix: 'Dr.',
|
|
243
|
+
nameSuffix: 'III'
|
|
244
|
+
},
|
|
245
|
+
me: true
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const expected = {
|
|
249
|
+
name: {
|
|
250
|
+
additionalName: 'J.',
|
|
251
|
+
familyName: 'Doe',
|
|
252
|
+
givenName: 'John',
|
|
253
|
+
namePrefix: 'Dr.',
|
|
254
|
+
nameSuffix: 'III'
|
|
255
|
+
},
|
|
256
|
+
me: true
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const result = formValuesToContact({
|
|
260
|
+
formValues: johnDoeFormValues,
|
|
261
|
+
oldContact,
|
|
262
|
+
t
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
for (const key of Object.keys(oldContact)) {
|
|
266
|
+
expect(result[key]).toEqual(expected[key])
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('should not remove attributes not in the doctype if it was present in the contact', () => {
|
|
271
|
+
const oldContact = {
|
|
272
|
+
otherInfoNotInDoctype: {
|
|
273
|
+
information: 'Lorem Ipsum'
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const expected = { information: 'Lorem Ipsum' }
|
|
277
|
+
|
|
278
|
+
const result = formValuesToContact({
|
|
279
|
+
formValues: johnDoeFormValues,
|
|
280
|
+
oldContact,
|
|
281
|
+
t
|
|
282
|
+
})
|
|
283
|
+
expect(result.otherInfoNotInDoctype).toEqual(expected)
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
it('should erase contact datas for empty fields', () => {
|
|
287
|
+
const formValues = {
|
|
288
|
+
gender: undefined,
|
|
289
|
+
givenName: undefined,
|
|
290
|
+
familyName: undefined,
|
|
291
|
+
company: undefined,
|
|
292
|
+
jobTitle: undefined,
|
|
293
|
+
birthday: undefined,
|
|
294
|
+
birthplace: undefined,
|
|
295
|
+
note: undefined,
|
|
296
|
+
address: [undefined],
|
|
297
|
+
email: [undefined],
|
|
298
|
+
phone: [undefined],
|
|
299
|
+
cozy: undefined,
|
|
300
|
+
relatedContact: [undefined]
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const expected = updateIndexFullNameAndDisplayName({
|
|
304
|
+
...johnDoeContact,
|
|
305
|
+
name: { givenName: '', familyName: '' },
|
|
306
|
+
company: '',
|
|
307
|
+
jobTitle: '',
|
|
308
|
+
address: [],
|
|
309
|
+
email: [],
|
|
310
|
+
cozy: [],
|
|
311
|
+
phone: [],
|
|
312
|
+
birthday: '',
|
|
313
|
+
birthplace: '',
|
|
314
|
+
gender: '',
|
|
315
|
+
note: '',
|
|
316
|
+
relationships: { groups: { data: [] }, related: { data: [] } }
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
const result = formValuesToContact({
|
|
320
|
+
formValues,
|
|
321
|
+
oldContact: johnDoeContact,
|
|
322
|
+
t
|
|
323
|
+
})
|
|
324
|
+
expect(result).toEqual(expected)
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
it('should erase contact datas for emptied fields', () => {
|
|
328
|
+
const formValues = {
|
|
329
|
+
gender: '',
|
|
330
|
+
givenName: '',
|
|
331
|
+
familyName: '',
|
|
332
|
+
company: '',
|
|
333
|
+
jobTitle: '',
|
|
334
|
+
birthday: '',
|
|
335
|
+
birthplace: '',
|
|
336
|
+
note: '',
|
|
337
|
+
address: [{}],
|
|
338
|
+
email: [{}],
|
|
339
|
+
phone: [{}],
|
|
340
|
+
cozy: '',
|
|
341
|
+
relatedContact: []
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const expected = updateIndexFullNameAndDisplayName({
|
|
345
|
+
...johnDoeContact,
|
|
346
|
+
name: { givenName: '', familyName: '' },
|
|
347
|
+
company: '',
|
|
348
|
+
jobTitle: '',
|
|
349
|
+
address: [],
|
|
350
|
+
email: [],
|
|
351
|
+
cozy: [],
|
|
352
|
+
phone: [],
|
|
353
|
+
birthday: '',
|
|
354
|
+
birthplace: '',
|
|
355
|
+
gender: '',
|
|
356
|
+
note: '',
|
|
357
|
+
relationships: { groups: { data: [] }, related: { data: [] } }
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
const result = formValuesToContact({
|
|
361
|
+
formValues,
|
|
362
|
+
oldContact: johnDoeContact,
|
|
363
|
+
t
|
|
364
|
+
})
|
|
365
|
+
expect(result).toEqual(expected)
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
it('should not remove contact unformatted address if nothing change', () => {
|
|
369
|
+
const formValues = {
|
|
370
|
+
address: [
|
|
371
|
+
{
|
|
372
|
+
fieldId: 'fieldId_1',
|
|
373
|
+
address: 'Hinton Road, 05034 Fresno, Singapore',
|
|
374
|
+
addressnumber: undefined,
|
|
375
|
+
addressstreet: 'Hinton Road',
|
|
376
|
+
addresscode: '05034',
|
|
377
|
+
addressregion: undefined,
|
|
378
|
+
addresscity: 'Fresno',
|
|
379
|
+
addresscountry: 'Singapore',
|
|
380
|
+
addresslocality: undefined,
|
|
381
|
+
addressbuilding: undefined,
|
|
382
|
+
addressstairs: undefined,
|
|
383
|
+
addressfloor: undefined,
|
|
384
|
+
addressapartment: undefined,
|
|
385
|
+
addressentrycode: undefined,
|
|
386
|
+
addressLabel: '{"type":"Work"}'
|
|
387
|
+
}
|
|
388
|
+
],
|
|
389
|
+
relatedContact: []
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const oldContact = {
|
|
393
|
+
address: [
|
|
394
|
+
{
|
|
395
|
+
pobox: '94',
|
|
396
|
+
street: 'Hinton Road',
|
|
397
|
+
city: 'Fresno',
|
|
398
|
+
country: 'Singapore',
|
|
399
|
+
postcode: '05034',
|
|
400
|
+
type: 'Work'
|
|
401
|
+
}
|
|
402
|
+
]
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const expected = {
|
|
406
|
+
address: [
|
|
407
|
+
{
|
|
408
|
+
pobox: '94',
|
|
409
|
+
street: 'Hinton Road',
|
|
410
|
+
city: 'Fresno',
|
|
411
|
+
country: 'Singapore',
|
|
412
|
+
postcode: '05034',
|
|
413
|
+
type: 'Work'
|
|
414
|
+
}
|
|
415
|
+
]
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const result = formValuesToContact({ formValues, oldContact, t })
|
|
419
|
+
expect(result.address).toEqual(expected.address)
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
it('should replace contact unformatted address by formatted one if something change', () => {
|
|
423
|
+
const formValues = {
|
|
424
|
+
address: [{ address: '01 Hinton Road 05034 Fresno, Singapore' }],
|
|
425
|
+
relatedContact: []
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const oldContact = {
|
|
429
|
+
address: [
|
|
430
|
+
{
|
|
431
|
+
pobox: '94',
|
|
432
|
+
street: 'Hinton Road',
|
|
433
|
+
city: 'Fresno',
|
|
434
|
+
country: 'Singapore',
|
|
435
|
+
postcode: '05034',
|
|
436
|
+
type: 'Work'
|
|
437
|
+
}
|
|
438
|
+
]
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const expected = {
|
|
442
|
+
address: [
|
|
443
|
+
{
|
|
444
|
+
city: undefined,
|
|
445
|
+
code: undefined,
|
|
446
|
+
country: undefined,
|
|
447
|
+
formattedAddress: '01 Hinton Road 05034 Fresno, Singapore',
|
|
448
|
+
number: undefined,
|
|
449
|
+
pobox: '94',
|
|
450
|
+
primary: true,
|
|
451
|
+
street: undefined,
|
|
452
|
+
type: undefined
|
|
453
|
+
}
|
|
454
|
+
]
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const result = formValuesToContact({ formValues, oldContact, t })
|
|
458
|
+
expect(result.address).toEqual(expected.address)
|
|
459
|
+
})
|
|
460
|
+
|
|
461
|
+
it('should replace name, index, fullname and displayName properly to name change', () => {
|
|
462
|
+
const formValues = {
|
|
463
|
+
givenName: 'Jane',
|
|
464
|
+
familyName: 'Doe',
|
|
465
|
+
relatedContact: []
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const oldContact = {
|
|
469
|
+
name: {
|
|
470
|
+
givenName: 'John',
|
|
471
|
+
familyName: 'Doe'
|
|
472
|
+
},
|
|
473
|
+
fullname: 'John Doe',
|
|
474
|
+
displayName: 'John Doe',
|
|
475
|
+
indexes: { byFamilyNameGivenNameEmailCozyUrl: 'doejohn' }
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const expected = {
|
|
479
|
+
name: {
|
|
480
|
+
givenName: 'Jane',
|
|
481
|
+
familyName: 'Doe'
|
|
482
|
+
},
|
|
483
|
+
fullname: 'Jane Doe',
|
|
484
|
+
displayName: 'Jane Doe',
|
|
485
|
+
indexes: { byFamilyNameGivenNameEmailCozyUrl: 'doejane' }
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const result = formValuesToContact({ formValues, oldContact, t })
|
|
489
|
+
expect(result.name).toEqual(expected.name)
|
|
490
|
+
expect(result.fullname).toEqual(expected.fullname)
|
|
491
|
+
expect(result.displayName).toEqual(expected.displayName)
|
|
492
|
+
expect(result.indexes).toEqual(expected.indexes)
|
|
493
|
+
})
|
|
494
|
+
})
|