cozy-sharing 12.1.0 → 12.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 +22 -0
- package/dist/components/Avatar/AvatarList.js +13 -2
- package/dist/components/Avatar/AvatarList.spec.js +11 -6
- package/dist/components/Avatar/AvatarList.stories.js +13 -1
- package/dist/components/Avatar/GroupAvatar.js +4 -2
- package/dist/components/ContactSuggestion.js +3 -14
- package/dist/components/ContactSuggestion.spec.js +22 -104
- package/dist/components/ShareAutosuggest.js +0 -3
- package/dist/components/ShareRecipientsInput.js +23 -1
- package/dist/components/ShareRecipientsInput.spec.js +206 -115
- package/jest.config.js +2 -1
- package/package.json +2 -2
- package/src/components/Avatar/AvatarList.jsx +33 -14
- package/src/components/Avatar/AvatarList.spec.jsx +11 -6
- package/src/components/Avatar/AvatarList.stories.jsx +19 -1
- package/src/components/Avatar/GroupAvatar.jsx +2 -2
- package/src/components/ContactSuggestion.jsx +3 -17
- package/src/components/ContactSuggestion.spec.jsx +16 -99
- package/src/components/ShareAutosuggest.jsx +1 -6
- package/src/components/ShareRecipientsInput.jsx +19 -1
- package/src/components/ShareRecipientsInput.spec.jsx +170 -108
- package/src/components/__snapshots__/ContactSuggestion.spec.jsx.snap +0 -1192
- package/src/components/__snapshots__/ShareRecipientsInput.spec.jsx.snap +0 -99
|
@@ -1,119 +1,210 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
2
4
|
import React from 'react';
|
|
3
5
|
import ShareRecipientsInput from './ShareRecipientsInput';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
name
|
|
18
|
-
givenName: 'Michale',
|
|
19
|
-
familyName: 'Russel'
|
|
20
|
-
}
|
|
21
|
-
}, {
|
|
22
|
-
id: '5a3b4ccf-c257',
|
|
23
|
-
_id: '5a3b4ccf-c257',
|
|
24
|
-
_type: 'io.cozy.contacts',
|
|
25
|
-
name: {
|
|
26
|
-
givenName: 'Teagan',
|
|
27
|
-
familyName: 'Wolf'
|
|
28
|
-
}
|
|
29
|
-
}]
|
|
30
|
-
},
|
|
31
|
-
contactGroups: {
|
|
32
|
-
id: 'groups',
|
|
33
|
-
fetchStatus: 'loaded',
|
|
34
|
-
hasMore: false,
|
|
35
|
-
data: [{
|
|
36
|
-
id: 'fe86af20-c6c5',
|
|
37
|
-
name: "The Night's Watch",
|
|
38
|
-
_id: 'fe86af20-c6c5',
|
|
39
|
-
_type: 'io.cozy.contacts.groups'
|
|
40
|
-
}, {
|
|
41
|
-
id: '3d8193ab-2ce4',
|
|
42
|
-
name: 'The North',
|
|
43
|
-
_id: '3d8193ab-2ce4',
|
|
44
|
-
_type: 'io.cozy.contacts.groups'
|
|
45
|
-
}]
|
|
46
|
-
},
|
|
47
|
-
recipients: [{
|
|
48
|
-
id: '5a3b4ccf-c257',
|
|
49
|
-
name: {
|
|
50
|
-
givenName: 'Teagan',
|
|
51
|
-
familyName: 'Wolf'
|
|
52
|
-
}
|
|
53
|
-
}],
|
|
54
|
-
onPick: jest.fn().mockName('onPick'),
|
|
55
|
-
onRemove: jest.fn().mockName('onRemove'),
|
|
56
|
-
placeholder: 'Enter recipients here'
|
|
57
|
-
};
|
|
58
|
-
var jsx = /*#__PURE__*/React.createElement(ShareRecipientsInput, props);
|
|
59
|
-
var wrapper = shallow(jsx);
|
|
60
|
-
expect(wrapper).toMatchSnapshot();
|
|
61
|
-
});
|
|
62
|
-
it('should include groups only if all contacts are loaded', function () {
|
|
63
|
-
var props = {
|
|
64
|
-
client: '',
|
|
65
|
-
label: 'Recipients',
|
|
66
|
-
contacts: {
|
|
67
|
-
id: 'contacts',
|
|
68
|
-
fetchStatus: 'loading',
|
|
69
|
-
hasMore: false,
|
|
70
|
-
data: [{
|
|
71
|
-
id: 'df563cc4-6440',
|
|
72
|
-
_id: 'df563cc4-6440',
|
|
73
|
-
_type: 'io.cozy.contacts',
|
|
74
|
-
name: {
|
|
75
|
-
givenName: 'Michale',
|
|
76
|
-
familyName: 'Russel'
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
id: '5a3b4ccf-c257',
|
|
80
|
-
_id: '5a3b4ccf-c257',
|
|
81
|
-
_type: 'io.cozy.contacts',
|
|
82
|
-
name: {
|
|
83
|
-
givenName: 'Teagan',
|
|
84
|
-
familyName: 'Wolf'
|
|
85
|
-
}
|
|
86
|
-
}]
|
|
87
|
-
},
|
|
88
|
-
contactGroups: {
|
|
89
|
-
id: 'groups',
|
|
90
|
-
fetchStatus: 'loaded',
|
|
91
|
-
hasMore: false,
|
|
92
|
-
data: [{
|
|
93
|
-
id: 'fe86af20-c6c5',
|
|
94
|
-
name: "The Night's Watch",
|
|
95
|
-
_id: 'fe86af20-c6c5',
|
|
96
|
-
_type: 'io.cozy.contacts.groups'
|
|
97
|
-
}, {
|
|
98
|
-
id: '3d8193ab-2ce4',
|
|
99
|
-
name: 'The North',
|
|
100
|
-
_id: '3d8193ab-2ce4',
|
|
101
|
-
_type: 'io.cozy.contacts.groups'
|
|
102
|
-
}]
|
|
103
|
-
},
|
|
104
|
-
recipients: [{
|
|
105
|
-
id: '5a3b4ccf-c257',
|
|
106
|
-
name: {
|
|
107
|
-
givenName: 'Teagan',
|
|
108
|
-
familyName: 'Wolf'
|
|
6
|
+
jest.mock('./ShareAutosuggest', function () {
|
|
7
|
+
return {
|
|
8
|
+
__esModule: true,
|
|
9
|
+
default: function _default(_ref) {
|
|
10
|
+
var contactsAndGroups = _ref.contactsAndGroups;
|
|
11
|
+
return /*#__PURE__*/React.createElement("ul", null, contactsAndGroups.map(function (contactOrGroup) {
|
|
12
|
+
if (contactOrGroup._type === 'io.cozy.contacts') {
|
|
13
|
+
return /*#__PURE__*/React.createElement("li", {
|
|
14
|
+
key: contactOrGroup.id
|
|
15
|
+
}, contactOrGroup.name.givenName, " ", contactOrGroup.name.familyName);
|
|
16
|
+
} else {
|
|
17
|
+
return /*#__PURE__*/React.createElement("li", {
|
|
18
|
+
key: contactOrGroup.id
|
|
19
|
+
}, contactOrGroup.name);
|
|
109
20
|
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
describe('ShareRecipientsInput component', function () {
|
|
26
|
+
var setup = function setup(_ref2) {
|
|
27
|
+
var contacts = _ref2.contacts,
|
|
28
|
+
contactGroups = _ref2.contactGroups;
|
|
29
|
+
render( /*#__PURE__*/React.createElement(ShareRecipientsInput, {
|
|
30
|
+
contacts: contacts,
|
|
31
|
+
contactGroups: contactGroups,
|
|
32
|
+
onPick: function onPick() {},
|
|
33
|
+
onRemove: function onRemove() {},
|
|
34
|
+
placeholder: "Enter recipients here"
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
it('should include groups and contacts when are loaded', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
39
|
+
var contacts, contactGroups;
|
|
40
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
41
|
+
while (1) switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
contacts = {
|
|
44
|
+
id: 'contacts',
|
|
45
|
+
fetchStatus: 'loaded',
|
|
46
|
+
hasMore: false,
|
|
47
|
+
data: [{
|
|
48
|
+
id: 'df563cc4-6440',
|
|
49
|
+
_id: 'df563cc4-6440',
|
|
50
|
+
_type: 'io.cozy.contacts',
|
|
51
|
+
name: {
|
|
52
|
+
givenName: 'Michale',
|
|
53
|
+
familyName: 'Russel'
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
id: '5a3b4ccf-c257',
|
|
57
|
+
_id: '5a3b4ccf-c257',
|
|
58
|
+
_type: 'io.cozy.contacts',
|
|
59
|
+
name: {
|
|
60
|
+
givenName: 'Teagan',
|
|
61
|
+
familyName: 'Wolf'
|
|
62
|
+
},
|
|
63
|
+
relationships: {
|
|
64
|
+
groups: {
|
|
65
|
+
data: [{
|
|
66
|
+
_id: 'fe86af20-c6c5',
|
|
67
|
+
_type: 'io.cozy.contacts.groups'
|
|
68
|
+
}]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}]
|
|
72
|
+
};
|
|
73
|
+
contactGroups = {
|
|
74
|
+
id: 'groups',
|
|
75
|
+
fetchStatus: 'loaded',
|
|
76
|
+
hasMore: false,
|
|
77
|
+
data: [{
|
|
78
|
+
id: 'fe86af20-c6c5',
|
|
79
|
+
name: "The Night's Watch",
|
|
80
|
+
_id: 'fe86af20-c6c5',
|
|
81
|
+
_type: 'io.cozy.contacts.groups'
|
|
82
|
+
}]
|
|
83
|
+
};
|
|
84
|
+
setup({
|
|
85
|
+
contacts: contacts,
|
|
86
|
+
contactGroups: contactGroups
|
|
87
|
+
});
|
|
88
|
+
expect(screen.getByText('Michale Russel')).toBeInTheDocument();
|
|
89
|
+
expect(screen.getByText('Teagan Wolf')).toBeInTheDocument();
|
|
90
|
+
expect(screen.getByText("The Night's Watch")).toBeInTheDocument();
|
|
91
|
+
|
|
92
|
+
case 6:
|
|
93
|
+
case "end":
|
|
94
|
+
return _context.stop();
|
|
95
|
+
}
|
|
96
|
+
}, _callee);
|
|
97
|
+
})));
|
|
98
|
+
it('should include groups only if all contacts are loaded', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
99
|
+
var contacts, contactGroups;
|
|
100
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
101
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
102
|
+
case 0:
|
|
103
|
+
contacts = {
|
|
104
|
+
id: 'contacts',
|
|
105
|
+
fetchStatus: 'loading',
|
|
106
|
+
hasMore: false,
|
|
107
|
+
data: [{
|
|
108
|
+
id: 'df563cc4-6440',
|
|
109
|
+
_id: 'df563cc4-6440',
|
|
110
|
+
_type: 'io.cozy.contacts',
|
|
111
|
+
name: {
|
|
112
|
+
givenName: 'Michale',
|
|
113
|
+
familyName: 'Russel'
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
id: '5a3b4ccf-c257',
|
|
117
|
+
_id: '5a3b4ccf-c257',
|
|
118
|
+
_type: 'io.cozy.contacts',
|
|
119
|
+
name: {
|
|
120
|
+
givenName: 'Teagan',
|
|
121
|
+
familyName: 'Wolf'
|
|
122
|
+
},
|
|
123
|
+
relationships: {
|
|
124
|
+
groups: {
|
|
125
|
+
data: [{
|
|
126
|
+
_id: 'fe86af20-c6c5',
|
|
127
|
+
_type: 'io.cozy.contacts.groups'
|
|
128
|
+
}]
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}]
|
|
132
|
+
};
|
|
133
|
+
contactGroups = {
|
|
134
|
+
id: 'groups',
|
|
135
|
+
fetchStatus: 'loaded',
|
|
136
|
+
hasMore: false,
|
|
137
|
+
data: [{
|
|
138
|
+
id: 'fe86af20-c6c5',
|
|
139
|
+
name: "The Night's Watch",
|
|
140
|
+
_id: 'fe86af20-c6c5',
|
|
141
|
+
_type: 'io.cozy.contacts.groups'
|
|
142
|
+
}]
|
|
143
|
+
};
|
|
144
|
+
setup({
|
|
145
|
+
contacts: contacts,
|
|
146
|
+
contactGroups: contactGroups
|
|
147
|
+
});
|
|
148
|
+
expect(screen.getByText('Michale Russel')).toBeInTheDocument();
|
|
149
|
+
expect(screen.getByText('Teagan Wolf')).toBeInTheDocument();
|
|
150
|
+
expect(screen.queryByText("The Night's Watch")).toBeNull();
|
|
151
|
+
|
|
152
|
+
case 6:
|
|
153
|
+
case "end":
|
|
154
|
+
return _context2.stop();
|
|
155
|
+
}
|
|
156
|
+
}, _callee2);
|
|
157
|
+
})));
|
|
158
|
+
it('should include groups only if they have more than one member', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
159
|
+
var contacts, contactGroups;
|
|
160
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
161
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
162
|
+
case 0:
|
|
163
|
+
contacts = {
|
|
164
|
+
id: 'contacts',
|
|
165
|
+
fetchStatus: 'loaded',
|
|
166
|
+
hasMore: false,
|
|
167
|
+
data: [{
|
|
168
|
+
id: 'df563cc4-6440',
|
|
169
|
+
_id: 'df563cc4-6440',
|
|
170
|
+
_type: 'io.cozy.contacts',
|
|
171
|
+
name: {
|
|
172
|
+
givenName: 'Michale',
|
|
173
|
+
familyName: 'Russel'
|
|
174
|
+
}
|
|
175
|
+
}, {
|
|
176
|
+
id: '5a3b4ccf-c257',
|
|
177
|
+
_id: '5a3b4ccf-c257',
|
|
178
|
+
_type: 'io.cozy.contacts',
|
|
179
|
+
name: {
|
|
180
|
+
givenName: 'Teagan',
|
|
181
|
+
familyName: 'Wolf'
|
|
182
|
+
}
|
|
183
|
+
}]
|
|
184
|
+
};
|
|
185
|
+
contactGroups = {
|
|
186
|
+
id: 'groups',
|
|
187
|
+
fetchStatus: 'loaded',
|
|
188
|
+
hasMore: false,
|
|
189
|
+
data: [{
|
|
190
|
+
id: 'fe86af20-c6c5',
|
|
191
|
+
name: "The Night's Watch",
|
|
192
|
+
_id: 'fe86af20-c6c5',
|
|
193
|
+
_type: 'io.cozy.contacts.groups'
|
|
194
|
+
}]
|
|
195
|
+
};
|
|
196
|
+
setup({
|
|
197
|
+
contacts: contacts,
|
|
198
|
+
contactGroups: contactGroups
|
|
199
|
+
});
|
|
200
|
+
expect(screen.getByText('Michale Russel')).toBeInTheDocument();
|
|
201
|
+
expect(screen.getByText('Teagan Wolf')).toBeInTheDocument();
|
|
202
|
+
expect(screen.queryByText("The Night's Watch")).toBeNull();
|
|
203
|
+
|
|
204
|
+
case 6:
|
|
205
|
+
case "end":
|
|
206
|
+
return _context3.stop();
|
|
207
|
+
}
|
|
208
|
+
}, _callee3);
|
|
209
|
+
})));
|
|
119
210
|
});
|
package/jest.config.js
CHANGED
|
@@ -2,7 +2,8 @@ module.exports = {
|
|
|
2
2
|
collectCoverageFrom: [
|
|
3
3
|
'src/**/*.{js,jsx}',
|
|
4
4
|
'!**/node_modules/**',
|
|
5
|
-
'!**/vendor/**'
|
|
5
|
+
'!**/vendor/**',
|
|
6
|
+
'!**/*.stories.{js,jsx,ts,tsx}'
|
|
6
7
|
],
|
|
7
8
|
snapshotSerializers: ['enzyme-to-json/serializer'],
|
|
8
9
|
testPathIgnorePatterns: ['node_modules', 'dist', '__tests__'],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-sharing",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"description": "Provides sharing login for React applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"sideEffects": [
|
|
72
72
|
"*.css"
|
|
73
73
|
],
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "b1ad6f5933b463878f641d9fbb63eddd4c45b0d0"
|
|
75
75
|
}
|
|
@@ -6,6 +6,7 @@ import Avatar from 'cozy-ui/transpiled/react/Avatar'
|
|
|
6
6
|
import LinkIcon from 'cozy-ui/transpiled/react/Icons/Link'
|
|
7
7
|
|
|
8
8
|
import { ExtraAvatar } from './ExtraAvatar'
|
|
9
|
+
import { GroupAvatar } from './GroupAvatar'
|
|
9
10
|
import { MemberAvatar } from './MemberAvatar'
|
|
10
11
|
import { getDisplayName } from '../../models'
|
|
11
12
|
import styles from '../../styles/recipient.styl'
|
|
@@ -88,20 +89,38 @@ const AvatarList = ({
|
|
|
88
89
|
/>
|
|
89
90
|
</span>
|
|
90
91
|
)}
|
|
91
|
-
{shownRecipients.map(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
{shownRecipients.map(recipient => {
|
|
93
|
+
if (recipient.members) {
|
|
94
|
+
return (
|
|
95
|
+
<span
|
|
96
|
+
data-testid={`AvatarList-avatar${
|
|
97
|
+
recipient.status === 'owner' ? '-owner' : ''
|
|
98
|
+
}`}
|
|
99
|
+
key={recipient.index}
|
|
100
|
+
>
|
|
101
|
+
<GroupAvatar
|
|
102
|
+
size={size}
|
|
103
|
+
className={cx(styles['recipients-avatars--avatar'])}
|
|
104
|
+
/>
|
|
105
|
+
</span>
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<span
|
|
111
|
+
data-testid={`AvatarList-avatar${
|
|
112
|
+
recipient.status === 'owner' ? '-owner' : ''
|
|
113
|
+
}`}
|
|
114
|
+
key={recipient.index}
|
|
115
|
+
>
|
|
116
|
+
<MemberAvatar
|
|
117
|
+
recipient={recipient}
|
|
118
|
+
size={size}
|
|
119
|
+
className={cx(styles['recipients-avatars--avatar'])}
|
|
120
|
+
/>
|
|
121
|
+
</span>
|
|
122
|
+
)
|
|
123
|
+
})}
|
|
105
124
|
</div>
|
|
106
125
|
)
|
|
107
126
|
}
|
|
@@ -14,7 +14,8 @@ const mockRecipients = new Array(MAX_DISPLAYED_RECIPIENTS - 1)
|
|
|
14
14
|
.fill(
|
|
15
15
|
{
|
|
16
16
|
status: 'owner',
|
|
17
|
-
public_name: 'cozy'
|
|
17
|
+
public_name: 'cozy',
|
|
18
|
+
index: 'sharing-123-member-0'
|
|
18
19
|
},
|
|
19
20
|
0,
|
|
20
21
|
1
|
|
@@ -22,7 +23,8 @@ const mockRecipients = new Array(MAX_DISPLAYED_RECIPIENTS - 1)
|
|
|
22
23
|
.fill(
|
|
23
24
|
{
|
|
24
25
|
status: 'pending',
|
|
25
|
-
name: 'Mitch Young'
|
|
26
|
+
name: 'Mitch Young',
|
|
27
|
+
index: 'sharing-123-member-1'
|
|
26
28
|
},
|
|
27
29
|
1
|
|
28
30
|
)
|
|
@@ -31,15 +33,18 @@ const mockMoreRecipientsThanMaxDisplayed = [
|
|
|
31
33
|
...mockRecipients,
|
|
32
34
|
{
|
|
33
35
|
status: 'mail-not-send',
|
|
34
|
-
name: 'Lyn Webster'
|
|
36
|
+
name: 'Lyn Webster',
|
|
37
|
+
index: 'sharing-123-member-2'
|
|
35
38
|
},
|
|
36
39
|
{
|
|
37
40
|
status: 'ready',
|
|
38
|
-
name: 'Richelle Young'
|
|
41
|
+
name: 'Richelle Young',
|
|
42
|
+
index: 'sharing-123-member-3'
|
|
39
43
|
},
|
|
40
44
|
{
|
|
41
45
|
status: 'ready',
|
|
42
|
-
name: 'John Connor'
|
|
46
|
+
name: 'John Connor',
|
|
47
|
+
index: 'sharing-123-member-4'
|
|
43
48
|
}
|
|
44
49
|
]
|
|
45
50
|
|
|
@@ -120,7 +125,7 @@ describe('AvatarList', () => {
|
|
|
120
125
|
})
|
|
121
126
|
|
|
122
127
|
describe('excludeMeAsOwnerFromRecipients', () => {
|
|
123
|
-
|
|
128
|
+
it('excludeMeAsOwnerFromRecipients behavior', () => {
|
|
124
129
|
const recipients = [
|
|
125
130
|
{
|
|
126
131
|
status: 'owner',
|
|
@@ -4,7 +4,7 @@ import { recipients } from '../../../.storybook/fixtures/recipients'
|
|
|
4
4
|
const meta = {
|
|
5
5
|
component: AvatarList,
|
|
6
6
|
args: {
|
|
7
|
-
recipients: [...recipients
|
|
7
|
+
recipients: [...recipients]
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -14,3 +14,21 @@ export const Default = {
|
|
|
14
14
|
name: 'Default',
|
|
15
15
|
args: {}
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
export const WithGroups = {
|
|
19
|
+
name: 'With groups',
|
|
20
|
+
args: {
|
|
21
|
+
recipients: [
|
|
22
|
+
...recipients,
|
|
23
|
+
{
|
|
24
|
+
name: 'Group 1',
|
|
25
|
+
type: 'group',
|
|
26
|
+
members: [
|
|
27
|
+
{
|
|
28
|
+
public_name: 'Alice'
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -3,8 +3,8 @@ import React from 'react'
|
|
|
3
3
|
import Avatar from 'cozy-ui/transpiled/react/Avatar'
|
|
4
4
|
import TeamIcon from 'cozy-ui/transpiled/react/Icons/Team'
|
|
5
5
|
|
|
6
|
-
const GroupAvatar = ({ size }) => {
|
|
7
|
-
return <Avatar icon={TeamIcon} size={size} />
|
|
6
|
+
const GroupAvatar = ({ size, className }) => {
|
|
7
|
+
return <Avatar icon={TeamIcon} size={size} className={className} />
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export { GroupAvatar }
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import get from 'lodash/get'
|
|
2
1
|
import PropTypes from 'prop-types'
|
|
3
2
|
import React from 'react'
|
|
4
3
|
|
|
@@ -13,28 +12,15 @@ import { Contact, Group, getDisplayName, getInitials } from '../models'
|
|
|
13
12
|
|
|
14
13
|
const ContactModel = models.contact
|
|
15
14
|
|
|
16
|
-
export const ContactSuggestion = ({ contactOrGroup
|
|
15
|
+
export const ContactSuggestion = ({ contactOrGroup }) => {
|
|
17
16
|
const { t } = useI18n()
|
|
18
17
|
let avatarText, name, details
|
|
19
18
|
if (contactOrGroup._type === Group.doctype) {
|
|
20
19
|
name = contactOrGroup.name
|
|
21
|
-
|
|
22
|
-
.reduce((total, contact) => {
|
|
23
|
-
if (
|
|
24
|
-
get(contact, 'relationships.groups.data', [])
|
|
25
|
-
.map(group => group._id)
|
|
26
|
-
.includes(contactOrGroup._id)
|
|
27
|
-
) {
|
|
28
|
-
return total + 1
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return total
|
|
32
|
-
}, 0)
|
|
33
|
-
.toString()
|
|
20
|
+
avatarText = 'G'
|
|
34
21
|
details = t('Share.members.count', {
|
|
35
|
-
smart_count: membersCount
|
|
22
|
+
smart_count: contactOrGroup.membersCount.toString()
|
|
36
23
|
})
|
|
37
|
-
avatarText = 'G'
|
|
38
24
|
} else {
|
|
39
25
|
name = getDisplayName(contactOrGroup)
|
|
40
26
|
avatarText = getInitials(contactOrGroup)
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, screen } from '@testing-library/react'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { ContactSuggestion } from './ContactSuggestion'
|
|
5
5
|
import AppLike from '../../test/AppLike'
|
|
6
6
|
|
|
7
|
-
const WrappingComponent = ({ children }) => <AppLike>{children}</AppLike>
|
|
8
|
-
|
|
9
7
|
describe('ContactSuggestion component', () => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
8
|
+
const setup = ({ contactOrGroup }) => {
|
|
9
|
+
return render(<ContactSuggestion contactOrGroup={contactOrGroup} />, {
|
|
10
|
+
wrapper: AppLike
|
|
11
|
+
})
|
|
12
|
+
}
|
|
14
13
|
|
|
15
|
-
return s
|
|
16
|
-
})
|
|
17
14
|
it('should display contact suggestion for a contact', () => {
|
|
18
15
|
const jonSnow = {
|
|
19
16
|
_id: 'f3a4e501-abbd',
|
|
@@ -36,17 +33,9 @@ describe('ContactSuggestion component', () => {
|
|
|
36
33
|
],
|
|
37
34
|
_type: 'io.cozy.contacts'
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
contacts,
|
|
43
|
-
t: fakeT
|
|
44
|
-
}
|
|
45
|
-
const jsx = <ContactSuggestion {...props} />
|
|
46
|
-
const wrapper = mount(jsx, {
|
|
47
|
-
wrappingComponent: WrappingComponent
|
|
48
|
-
})
|
|
49
|
-
expect(wrapper).toMatchSnapshot()
|
|
36
|
+
setup({ contactOrGroup: jonSnow })
|
|
37
|
+
expect(screen.getByText('Jon Snow')).toBeInTheDocument()
|
|
38
|
+
expect(screen.getByText('https://jonsnow.mycozy.cloud')).toBeInTheDocument()
|
|
50
39
|
})
|
|
51
40
|
|
|
52
41
|
it('should display contact suggestion for a contact without fullname (for example created by a share modal)', () => {
|
|
@@ -62,91 +51,19 @@ describe('ContactSuggestion component', () => {
|
|
|
62
51
|
name: undefined,
|
|
63
52
|
_type: 'io.cozy.contacts'
|
|
64
53
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
contactOrGroup: jonSnow,
|
|
68
|
-
contacts,
|
|
69
|
-
t: fakeT
|
|
70
|
-
}
|
|
71
|
-
const jsx = <ContactSuggestion {...props} />
|
|
72
|
-
const wrapper = mount(jsx, {
|
|
73
|
-
wrappingComponent: WrappingComponent
|
|
74
|
-
})
|
|
75
|
-
expect(wrapper).toMatchSnapshot()
|
|
54
|
+
setup({ contactOrGroup: jonSnow })
|
|
55
|
+
expect(screen.getByText('jon.snow@email.com')).toBeInTheDocument()
|
|
76
56
|
})
|
|
77
57
|
|
|
78
58
|
it('should display contact suggestion for a group', () => {
|
|
79
|
-
const jon = {
|
|
80
|
-
_id: 'f3a4e501-abbd',
|
|
81
|
-
fullname: 'Jon Snow',
|
|
82
|
-
name: {
|
|
83
|
-
givenName: 'Jon',
|
|
84
|
-
familyName: 'Snow'
|
|
85
|
-
},
|
|
86
|
-
email: [
|
|
87
|
-
{
|
|
88
|
-
address: 'jon.snow@email.com',
|
|
89
|
-
type: 'primary'
|
|
90
|
-
}
|
|
91
|
-
],
|
|
92
|
-
_type: 'io.cozy.contacts',
|
|
93
|
-
relationships: {
|
|
94
|
-
groups: {
|
|
95
|
-
data: [{ _id: '610718e6-2d7a', _type: 'io.cozy.contacts.groups' }]
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const cersei = {
|
|
100
|
-
_id: '42dc490a-7878',
|
|
101
|
-
fullname: 'Cersei Lannister',
|
|
102
|
-
name: {
|
|
103
|
-
givenName: 'Cersei',
|
|
104
|
-
familyName: 'Lannister'
|
|
105
|
-
},
|
|
106
|
-
email: [
|
|
107
|
-
{
|
|
108
|
-
address: 'cersei@email.com',
|
|
109
|
-
type: 'primary'
|
|
110
|
-
}
|
|
111
|
-
],
|
|
112
|
-
_type: 'io.cozy.contacts',
|
|
113
|
-
relationships: { groups: { data: [] } }
|
|
114
|
-
}
|
|
115
|
-
const sam = {
|
|
116
|
-
_id: 'b5bed853-93da',
|
|
117
|
-
fullname: 'Samwell Tarly',
|
|
118
|
-
name: {
|
|
119
|
-
givenName: 'Samwell',
|
|
120
|
-
familyName: 'Tarly'
|
|
121
|
-
},
|
|
122
|
-
email: [
|
|
123
|
-
{
|
|
124
|
-
address: 'samwell@email.com',
|
|
125
|
-
type: 'primary'
|
|
126
|
-
}
|
|
127
|
-
],
|
|
128
|
-
_type: 'io.cozy.contacts',
|
|
129
|
-
relationships: {
|
|
130
|
-
groups: {
|
|
131
|
-
data: [{ _id: '610718e6-2d7a', _type: 'io.cozy.contacts.groups' }]
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
const contacts = [jon, cersei, sam]
|
|
136
59
|
const theNightsWatch = {
|
|
137
60
|
_id: '610718e6-2d7a',
|
|
138
61
|
name: "The Night's Watch",
|
|
139
|
-
_type: 'io.cozy.contacts.groups'
|
|
62
|
+
_type: 'io.cozy.contacts.groups',
|
|
63
|
+
membersCount: 2
|
|
140
64
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
t: fakeT
|
|
145
|
-
}
|
|
146
|
-
const jsx = <ContactSuggestion {...props} />
|
|
147
|
-
const wrapper = mount(jsx, {
|
|
148
|
-
wrappingComponent: WrappingComponent
|
|
149
|
-
})
|
|
150
|
-
expect(wrapper).toMatchSnapshot()
|
|
65
|
+
setup({ contactOrGroup: theNightsWatch })
|
|
66
|
+
expect(screen.getByText("The Night's Watch")).toBeInTheDocument()
|
|
67
|
+
expect(screen.getByText('2 members')).toBeInTheDocument()
|
|
151
68
|
})
|
|
152
69
|
})
|