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.
Files changed (101) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/package.json +5 -1
  3. package/react/ActionsMenu/Actions/viewInDrive.js +2 -1
  4. package/react/Contacts/AddModal/ContactAddressDialog/helpers.js +22 -0
  5. package/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.js +64 -0
  6. package/react/Contacts/AddModal/ContactAddressDialog/index.jsx +84 -0
  7. package/react/Contacts/AddModal/ContactAddressDialog/locales/en.json +25 -0
  8. package/react/Contacts/AddModal/ContactAddressDialog/locales/fr.json +25 -0
  9. package/react/Contacts/AddModal/ContactAddressDialog/locales/index.jsx +7 -0
  10. package/react/Contacts/AddModal/ContactForm/FieldInput.jsx +117 -0
  11. package/react/Contacts/AddModal/ContactForm/FieldInputArray.jsx +80 -0
  12. package/react/Contacts/AddModal/ContactForm/FieldInputLayout.jsx +65 -0
  13. package/react/Contacts/AddModal/ContactForm/FieldInputWrapper.jsx +41 -0
  14. package/react/Contacts/AddModal/ContactForm/HasValueCondition.jsx +31 -0
  15. package/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.jsx +79 -0
  16. package/react/Contacts/AddModal/ContactForm/RelatedContactList.jsx +37 -0
  17. package/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.jsx +78 -0
  18. package/react/Contacts/AddModal/ContactForm/TextFieldSelect.jsx +39 -0
  19. package/react/Contacts/AddModal/ContactForm/__snapshots__/HasValueCondition.spec.jsx.snap +33 -0
  20. package/react/Contacts/AddModal/ContactForm/contactToFormValues.js +99 -0
  21. package/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.js +128 -0
  22. package/react/Contacts/AddModal/ContactForm/fieldsConfig.jsx +341 -0
  23. package/react/Contacts/AddModal/ContactForm/formValuesToContact.js +100 -0
  24. package/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.js +494 -0
  25. package/react/Contacts/AddModal/ContactForm/helpers.js +324 -0
  26. package/react/Contacts/AddModal/ContactForm/helpers.spec.js +152 -0
  27. package/react/Contacts/AddModal/ContactForm/index.jsx +104 -0
  28. package/react/Contacts/AddModal/ContactForm/index.spec.jsx +289 -0
  29. package/react/Contacts/AddModal/ContactForm/locales/en.json +73 -0
  30. package/react/Contacts/AddModal/ContactForm/locales/fr.json +73 -0
  31. package/react/Contacts/AddModal/ContactForm/locales/index.jsx +7 -0
  32. package/react/Contacts/AddModal/ContactForm/styles.styl +2 -0
  33. package/react/Contacts/AddModal/CustomLabelDialog/index.jsx +108 -0
  34. package/react/Contacts/AddModal/CustomLabelDialog/locales/en.json +15 -0
  35. package/react/Contacts/AddModal/CustomLabelDialog/locales/fr.json +15 -0
  36. package/react/Contacts/AddModal/CustomLabelDialog/locales/index.jsx +7 -0
  37. package/react/Contacts/AddModal/Readme.md +46 -0
  38. package/react/Contacts/AddModal/index.jsx +78 -0
  39. package/react/Contacts/AddModal/locales/en.json +13 -0
  40. package/react/Contacts/AddModal/locales/fr.json +13 -0
  41. package/react/Contacts/AddModal/locales/index.jsx +7 -0
  42. package/react/Contacts/AddModal/mocks.js +249 -0
  43. package/react/Contacts/AddModal/types.js +57 -0
  44. package/react/Contacts/Header/Readme.md +0 -2
  45. package/react/providers/DemoProvider.jsx +3 -2
  46. package/transpiled/react/ActionsMenu/Actions/viewInDrive.js +2 -1
  47. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.d.ts +4 -0
  48. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.js +20 -0
  49. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.d.ts +1 -0
  50. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.d.ts +39 -0
  51. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.js +87 -0
  52. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.d.ts +6 -0
  53. package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.js +54 -0
  54. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.d.ts +35 -0
  55. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.js +126 -0
  56. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.d.ts +14 -0
  57. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.js +82 -0
  58. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.d.ts +20 -0
  59. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.js +70 -0
  60. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.d.ts +16 -0
  61. package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.js +31 -0
  62. package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.d.ts +18 -0
  63. package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.js +32 -0
  64. package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.d.ts +1 -0
  65. package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.d.ts +15 -0
  66. package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.js +39 -0
  67. package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.d.ts +9 -0
  68. package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.js +81 -0
  69. package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.d.ts +5 -0
  70. package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.js +42 -0
  71. package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.d.ts +2 -0
  72. package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.js +88 -0
  73. package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.d.ts +1 -0
  74. package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.d.ts +4 -0
  75. package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.js +278 -0
  76. package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.d.ts +6 -0
  77. package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.js +94 -0
  78. package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.d.ts +1 -0
  79. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.d.ts +28 -0
  80. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.js +335 -0
  81. package/transpiled/react/Contacts/AddModal/ContactForm/helpers.spec.d.ts +1 -0
  82. package/transpiled/react/Contacts/AddModal/ContactForm/index.d.ts +11 -0
  83. package/transpiled/react/Contacts/AddModal/ContactForm/index.js +114 -0
  84. package/transpiled/react/Contacts/AddModal/ContactForm/index.spec.d.ts +1 -0
  85. package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.d.ts +6 -0
  86. package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.js +150 -0
  87. package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.d.ts +22 -0
  88. package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.js +113 -0
  89. package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.d.ts +6 -0
  90. package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.js +34 -0
  91. package/transpiled/react/Contacts/AddModal/index.d.ts +7 -0
  92. package/transpiled/react/Contacts/AddModal/index.js +109 -0
  93. package/transpiled/react/Contacts/AddModal/locales/index.d.ts +6 -0
  94. package/transpiled/react/Contacts/AddModal/locales/index.js +30 -0
  95. package/transpiled/react/Contacts/AddModal/mocks.d.ts +270 -0
  96. package/transpiled/react/Contacts/AddModal/mocks.js +214 -0
  97. package/transpiled/react/Contacts/AddModal/types.d.ts +54 -0
  98. package/transpiled/react/Contacts/AddModal/types.js +49 -0
  99. package/transpiled/react/providers/DemoProvider.d.ts +2 -1
  100. package/transpiled/react/providers/DemoProvider.js +7 -3
  101. package/transpiled/react/stylesheet.css +1 -1
@@ -0,0 +1,79 @@
1
+ import React from 'react'
2
+ import { Form } from 'react-final-form'
3
+ import renderer from 'react-test-renderer'
4
+
5
+ import HasValueCondition from './HasValueCondition'
6
+
7
+ describe('HasValueCondition component', () => {
8
+ it('should render its children if value is truthy', () => {
9
+ const jsx = (
10
+ <Form
11
+ initialValues={{ foo: 'anything' }}
12
+ onSubmit={jest.fn()}
13
+ render={({ handleSubmit }) => (
14
+ <form onSubmit={handleSubmit}>
15
+ <HasValueCondition name="foo">
16
+ <span>Foo should be here</span>
17
+ </HasValueCondition>
18
+ </form>
19
+ )}
20
+ />
21
+ )
22
+ const tree = renderer.create(jsx).toJSON()
23
+ expect(tree).toMatchSnapshot()
24
+ })
25
+
26
+ it('should not render its children if value is falsy', () => {
27
+ const jsx = (
28
+ <Form
29
+ initialValues={{ foo: '' }}
30
+ onSubmit={jest.fn()}
31
+ render={({ handleSubmit }) => (
32
+ <form onSubmit={handleSubmit}>
33
+ <HasValueCondition name="foo">
34
+ <span>Foo should not be here</span>
35
+ </HasValueCondition>
36
+ </form>
37
+ )}
38
+ />
39
+ )
40
+ const tree = renderer.create(jsx).toJSON()
41
+ expect(tree).toMatchSnapshot()
42
+ })
43
+
44
+ it('should render its children if value is falsy but other condition is fulfilled', () => {
45
+ const jsx = (
46
+ <Form
47
+ initialValues={{ foo: '' }}
48
+ onSubmit={jest.fn()}
49
+ render={({ handleSubmit }) => (
50
+ <form onSubmit={handleSubmit}>
51
+ <HasValueCondition name="foo" otherCondition={true}>
52
+ <span>Foo should be here</span>
53
+ </HasValueCondition>
54
+ </form>
55
+ )}
56
+ />
57
+ )
58
+ const tree = renderer.create(jsx).toJSON()
59
+ expect(tree).toMatchSnapshot()
60
+ })
61
+
62
+ it('should not render its children if value is falsy and other condition is not fulfilled', () => {
63
+ const jsx = (
64
+ <Form
65
+ initialValues={{ foo: '' }}
66
+ onSubmit={jest.fn()}
67
+ render={({ handleSubmit }) => (
68
+ <form onSubmit={handleSubmit}>
69
+ <HasValueCondition name="foo" otherCondition={false}>
70
+ <span>Foo should not be here</span>
71
+ </HasValueCondition>
72
+ </form>
73
+ )}
74
+ />
75
+ )
76
+ const tree = renderer.create(jsx).toJSON()
77
+ expect(tree).toMatchSnapshot()
78
+ })
79
+ })
@@ -0,0 +1,37 @@
1
+ import PropTypes from 'prop-types'
2
+ import React from 'react'
3
+ import { useForm } from 'react-final-form'
4
+
5
+ import { makeDisplayName } from 'cozy-client/dist/models/contact'
6
+
7
+ import ContactsListModal from '../../../ContactsListModal'
8
+
9
+ export const RelatedContactList = ({ name, onClose, contacts }) => {
10
+ const { change } = useForm()
11
+
12
+ /**
13
+ * @param {import('cozy-client/types/types').IOCozyContact} contact
14
+ */
15
+ const onClickContactsListModal = contact => {
16
+ // Use `makeDisplayName` because if the contact is newly created, it has no `displayName` attribute. (Creation of a contact when selecting a linked contact)
17
+ change(name, makeDisplayName(contact))
18
+ change(`${name}Id`, contact._id)
19
+ onClose()
20
+ }
21
+
22
+ return (
23
+ <ContactsListModal
24
+ dismissAction={onClose}
25
+ onItemClick={contact => onClickContactsListModal(contact)}
26
+ contacts={contacts}
27
+ />
28
+ )
29
+ }
30
+
31
+ RelatedContactList.propTypes = {
32
+ name: PropTypes.string.isRequired,
33
+ onClose: PropTypes.func.isRequired,
34
+ contacts: PropTypes.shape({
35
+ data: PropTypes.arrayOf(PropTypes.object)
36
+ }).isRequired
37
+ }
@@ -0,0 +1,78 @@
1
+ import React, { useState } from 'react'
2
+
3
+ import TextFieldSelect from './TextFieldSelect'
4
+ import { makeCustomLabel, makeInitialCustomValue } from './helpers'
5
+ import { locales } from './locales'
6
+ import { useI18n, useExtendI18n } from '../../../providers/I18n'
7
+ import CustomLabelDialog from '../CustomLabelDialog'
8
+ import { FieldInputWrapperPropTypes } from '../types'
9
+
10
+ const TextFieldCustomLabelSelect = ({
11
+ name,
12
+ value,
13
+ options,
14
+ customLabelOptions,
15
+ onChange,
16
+ ...props
17
+ }) => {
18
+ useExtendI18n(locales)
19
+ const { t } = useI18n()
20
+ const [openModal, setOpenModal] = useState(false)
21
+ const [customValue, setCustomValue] = useState(() =>
22
+ makeInitialCustomValue(name, value)
23
+ )
24
+
25
+ const customOption = customValue
26
+ ? [
27
+ {
28
+ value: customValue,
29
+ label: makeCustomLabel(customValue, t),
30
+ translated: true,
31
+ onClick: () => {
32
+ // trigger modal only if customValue is already selected
33
+ if (value === customValue) {
34
+ return setOpenModal(true)
35
+ }
36
+ }
37
+ }
38
+ ]
39
+ : [
40
+ {
41
+ value: 'skip',
42
+ label: 'Contacts.AddModal.ContactForm.label.custom',
43
+ onClick: () => setOpenModal(true)
44
+ }
45
+ ]
46
+ const _options = options.concat(customOption)
47
+
48
+ return (
49
+ <>
50
+ <TextFieldSelect
51
+ {...props}
52
+ name={name}
53
+ value={value}
54
+ options={_options}
55
+ onChange={ev => {
56
+ if (ev.target.value === 'skip') {
57
+ return
58
+ }
59
+
60
+ onChange(ev)
61
+ }}
62
+ />
63
+ {openModal && (
64
+ <CustomLabelDialog
65
+ customValue={customValue}
66
+ customLabelOptions={customLabelOptions}
67
+ setCustomValue={setCustomValue}
68
+ onSubmit={onChange}
69
+ onClose={() => setOpenModal(false)}
70
+ />
71
+ )}
72
+ </>
73
+ )
74
+ }
75
+
76
+ TextFieldCustomLabelSelect.prototype = FieldInputWrapperPropTypes
77
+
78
+ export default TextFieldCustomLabelSelect
@@ -0,0 +1,39 @@
1
+ import React from 'react'
2
+
3
+ import { locales } from './locales'
4
+ import MenuItem from '../../../MenuItem'
5
+ import TextField from '../../../TextField'
6
+ import { useI18n, useExtendI18n } from '../../../providers/I18n'
7
+ import { FieldInputWrapperPropTypes } from '../types'
8
+
9
+ const TextFieldSelect = ({ options, ...props }) => {
10
+ useExtendI18n(locales)
11
+ const { t } = useI18n()
12
+
13
+ const _options = [
14
+ ...options.map(option => ({
15
+ ...option,
16
+ label: option.translated ? option.label : t(option.label)
17
+ }))
18
+ ]
19
+
20
+ return (
21
+ <TextField {...props}>
22
+ {_options.map((option, index) => {
23
+ return (
24
+ <MenuItem
25
+ key={`${props.name}-${index}`}
26
+ value={option.value}
27
+ onClick={option.onClick}
28
+ >
29
+ {option.label}
30
+ </MenuItem>
31
+ )
32
+ })}
33
+ </TextField>
34
+ )
35
+ }
36
+
37
+ TextFieldSelect.prototype = FieldInputWrapperPropTypes
38
+
39
+ export default TextFieldSelect
@@ -0,0 +1,33 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`HasValueCondition component should not render its children if value is falsy 1`] = `
4
+ <form
5
+ onSubmit={[Function]}
6
+ />
7
+ `;
8
+
9
+ exports[`HasValueCondition component should not render its children if value is falsy and other condition is not fulfilled 1`] = `
10
+ <form
11
+ onSubmit={[Function]}
12
+ />
13
+ `;
14
+
15
+ exports[`HasValueCondition component should render its children if value is falsy but other condition is fulfilled 1`] = `
16
+ <form
17
+ onSubmit={[Function]}
18
+ >
19
+ <span>
20
+ Foo should be here
21
+ </span>
22
+ </form>
23
+ `;
24
+
25
+ exports[`HasValueCondition component should render its children if value is truthy 1`] = `
26
+ <form
27
+ onSubmit={[Function]}
28
+ >
29
+ <span>
30
+ Foo should be here
31
+ </span>
32
+ </form>
33
+ `;
@@ -0,0 +1,99 @@
1
+ import uniqueId from 'lodash/uniqueId'
2
+
3
+ import { getFormattedAddress } from 'cozy-client/dist/models/contact'
4
+
5
+ import { fields } from './fieldsConfig'
6
+ import { makeItemLabel, makeRelatedContact, movePrimaryToHead } from './helpers'
7
+
8
+ const contactToFormValues = (contact, t) => {
9
+ // initialize the form values, required so that array fields start with at least one editable field
10
+ const initialFieldValues = fields.reduce(
11
+ (initialValues, { name, isArray }) => {
12
+ initialValues[name] = isArray ? [undefined] : undefined
13
+ return initialValues
14
+ },
15
+ {}
16
+ )
17
+
18
+ if (contact) {
19
+ const {
20
+ gender,
21
+ address,
22
+ birthday,
23
+ birthplace,
24
+ company,
25
+ jobTitle,
26
+ cozy,
27
+ email,
28
+ name,
29
+ note,
30
+ phone
31
+ } = contact
32
+
33
+ const addressValue =
34
+ address && address.length > 0
35
+ ? movePrimaryToHead(address).map(addressInfo => ({
36
+ fieldId: uniqueId('fieldId_'),
37
+ address: getFormattedAddress(addressInfo, t),
38
+ addressnumber: addressInfo.number,
39
+ addressstreet:
40
+ addressInfo.street || getFormattedAddress(addressInfo, t),
41
+ addresscode: addressInfo.postcode || addressInfo.code,
42
+ addresscity: addressInfo.city,
43
+ addressregion: addressInfo.region,
44
+ addresscountry: addressInfo.country,
45
+ addresslocality: addressInfo.extendedAddress?.locality,
46
+ addressbuilding: addressInfo.extendedAddress?.building,
47
+ addressstairs: addressInfo.extendedAddress?.stairs,
48
+ addressfloor: addressInfo.extendedAddress?.floor,
49
+ addressapartment: addressInfo.extendedAddress?.apartment,
50
+ addressentrycode: addressInfo.extendedAddress?.entrycode,
51
+ addressLabel: makeItemLabel(addressInfo)
52
+ }))
53
+ : [undefined]
54
+ const cozyValue = cozy && cozy.length > 0 ? cozy[0].url : undefined
55
+ const cozyLabel =
56
+ cozy && cozy.length > 0 ? makeItemLabel(cozy[0]) : undefined
57
+ const emailValue =
58
+ email && email.length > 0
59
+ ? movePrimaryToHead(email).map(item => ({
60
+ fieldId: uniqueId('fieldId_'),
61
+ email: item?.address,
62
+ emailLabel: makeItemLabel(item)
63
+ }))
64
+ : [undefined]
65
+ const phoneValue =
66
+ phone && phone.length > 0
67
+ ? movePrimaryToHead(phone).map(item => ({
68
+ fieldId: uniqueId('fieldId_'),
69
+ phone: item?.number,
70
+ phoneLabel: makeItemLabel(item)
71
+ }))
72
+ : [undefined]
73
+
74
+ const relatedContactValue = makeRelatedContact(contact)
75
+
76
+ return {
77
+ gender,
78
+ givenName: name?.givenName,
79
+ additionalName: name?.additionalName,
80
+ surname: name?.surname,
81
+ familyName: name?.familyName,
82
+ phone: phoneValue,
83
+ email: emailValue,
84
+ address: addressValue,
85
+ cozy: cozyValue,
86
+ cozyLabel: cozyLabel,
87
+ company,
88
+ jobTitle,
89
+ birthday,
90
+ birthplace,
91
+ note,
92
+ relatedContact: relatedContactValue
93
+ }
94
+ }
95
+
96
+ return initialFieldValues
97
+ }
98
+
99
+ export default contactToFormValues
@@ -0,0 +1,128 @@
1
+ /* eslint-disable jest/no-focused-tests */
2
+ import contactToFormValues from './contactToFormValues'
3
+ import { johnDoeContact, johnDoeFormValues } from '../mocks'
4
+
5
+ describe('contactToFormValues function', () => {
6
+ const tSpy = jest.fn()
7
+
8
+ it('should return default initial values', () => {
9
+ const expected = {
10
+ address: [undefined],
11
+ birthday: undefined,
12
+ birthplace: undefined,
13
+ gender: undefined,
14
+ company: undefined,
15
+ jobTitle: undefined,
16
+ cozy: undefined,
17
+ cozyLabel: undefined,
18
+ email: [undefined],
19
+ familyName: undefined,
20
+ givenName: undefined,
21
+ note: undefined,
22
+ phone: [undefined],
23
+ relatedContact: [undefined]
24
+ }
25
+
26
+ const result = contactToFormValues(null, tSpy)
27
+ expect(result).toEqual(expected)
28
+ })
29
+
30
+ it('should return initial values when a contact is given (edit)', () => {
31
+ const expected = { ...johnDoeFormValues, relatedContact: [undefined] }
32
+ tSpy.mockReturnValue(
33
+ '426 Runolfsson Knolls 84573 Port Easter Cocos (Keeling) Islands'
34
+ )
35
+
36
+ const result = contactToFormValues(johnDoeContact, tSpy)
37
+ expect(result).toEqual(expected)
38
+ expect(tSpy).toHaveBeenCalledWith('formatted.address', {
39
+ street: '426 Runolfsson Knolls',
40
+ code: '84573',
41
+ number: '',
42
+ city: 'Port Easter',
43
+ region: '',
44
+ country: 'Cocos (Keeling) Islands'
45
+ })
46
+ })
47
+
48
+ it('should return initial values when a contact with missing fields is given', () => {
49
+ const contact = {
50
+ id: '9ecfbf4b-20e7-4bac-87f1-eea53350857d',
51
+ _id: '9ecfbf4b-20e7-4bac-87f1-eea53350857d',
52
+ _type: 'io.cozy.contacts',
53
+ _rev: '1-19c313536e8b27473aa26bf105b03269',
54
+ address: [],
55
+ birthday: undefined,
56
+ birthplace: 'somewhere',
57
+ gender: 'female',
58
+ company: undefined,
59
+ jobTitle: undefined,
60
+ cozy: undefined,
61
+ email: undefined,
62
+ name: {
63
+ givenName: 'Jane',
64
+ familyName: 'Doe'
65
+ },
66
+ note: undefined,
67
+ phone: []
68
+ }
69
+ const expected = {
70
+ address: [undefined],
71
+ birthday: undefined,
72
+ birthplace: 'somewhere',
73
+ gender: 'female',
74
+ company: undefined,
75
+ jobTitle: undefined,
76
+ cozy: undefined,
77
+ cozyLabel: undefined,
78
+ email: [undefined],
79
+ givenName: 'Jane',
80
+ familyName: 'Doe',
81
+ note: undefined,
82
+ phone: [undefined],
83
+ relatedContact: [undefined]
84
+ }
85
+
86
+ const result = contactToFormValues(contact, tSpy)
87
+ expect(result).toEqual(expected)
88
+ })
89
+
90
+ it('should not crash if name is undefined (contacts created via sharing)', () => {
91
+ const contact = {
92
+ id: '9ecfbf4b-20e7-4bac-87f1-eea53350857d',
93
+ _id: '9ecfbf4b-20e7-4bac-87f1-eea53350857d',
94
+ _type: 'io.cozy.contacts',
95
+ _rev: '1-19c313536e8b27473aa26bf105b03269',
96
+ address: [],
97
+ birthday: undefined,
98
+ birthplace: '',
99
+ gender: '',
100
+ company: undefined,
101
+ jobTitle: undefined,
102
+ cozy: undefined,
103
+ email: undefined,
104
+ name: undefined,
105
+ note: 'Eligendi velit eos ab libero molestiae consequatur autem sed.',
106
+ phone: []
107
+ }
108
+ const expected = {
109
+ address: [undefined],
110
+ birthday: undefined,
111
+ birthplace: '',
112
+ gender: '',
113
+ company: undefined,
114
+ jobTitle: undefined,
115
+ cozy: undefined,
116
+ cozyLabel: undefined,
117
+ email: [undefined],
118
+ givenName: undefined,
119
+ familyName: undefined,
120
+ note: 'Eligendi velit eos ab libero molestiae consequatur autem sed.',
121
+ phone: [undefined],
122
+ relatedContact: [undefined]
123
+ }
124
+
125
+ const result = contactToFormValues(contact, tSpy)
126
+ expect(result).toEqual(expected)
127
+ })
128
+ })