@instructure/ui-avatar 8.39.1-snapshot-2 → 8.40.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 CHANGED
@@ -3,22 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [8.39.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v8.39.0...v8.39.1-snapshot-2) (2023-08-10)
6
+ # [8.40.0](https://github.com/instructure/instructure-ui/compare/v8.39.0...v8.40.0) (2023-08-17)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-avatar
9
9
 
10
-
11
-
12
-
13
-
14
10
  # [8.39.0](https://github.com/instructure/instructure-ui/compare/v8.38.1...v8.39.0) (2023-07-21)
15
11
 
16
12
  **Note:** Version bump only for package @instructure/ui-avatar
17
13
 
18
-
19
-
20
-
21
-
22
14
  ## [8.38.1](https://github.com/instructure/instructure-ui/compare/v8.38.0...v8.38.1) (2023-06-13)
23
15
 
24
16
  **Note:** Version bump only for package @instructure/ui-avatar
@@ -0,0 +1,312 @@
1
+ var _Avatar, _Avatar2, _Avatar3, _Avatar4, _Avatar5, _Avatar6, _svg, _Avatar7, _IconGroupLine, _IconGroupLine2, _Avatar11, _Avatar12, _Avatar13, _Avatar14, _Avatar15, _Avatar16, _Avatar17, _Avatar18, _Avatar19, _Avatar20, _Avatar21, _Avatar22;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ import React from 'react';
26
+ import { fireEvent, render, screen } from '@testing-library/react';
27
+ import { runAxeCheck } from '@instructure/ui-axe-check';
28
+ import '@testing-library/jest-dom/extend-expect';
29
+ import Avatar from '../index';
30
+ import { IconGroupLine } from '@instructure/ui-icons';
31
+ describe('<Avatar />', () => {
32
+ describe('for a11y', () => {
33
+ it('should be accessible', async () => {
34
+ const _render = render(_Avatar || (_Avatar = /*#__PURE__*/React.createElement(Avatar, {
35
+ name: "Jessica Jones"
36
+ }))),
37
+ container = _render.container;
38
+ const axeCheck = await runAxeCheck(container);
39
+ expect(axeCheck).toBe(true);
40
+ });
41
+ it('initials should have aria-hidden=true', async () => {
42
+ render(_Avatar2 || (_Avatar2 = /*#__PURE__*/React.createElement(Avatar, {
43
+ name: "Jessica Jones"
44
+ })));
45
+ const initials = screen.getByText('JJ');
46
+ expect(initials).toHaveAttribute('aria-hidden', 'true');
47
+ });
48
+ });
49
+ describe('with the default props', () => {
50
+ it('should display as a circle', async () => {
51
+ const _render2 = render(_Avatar3 || (_Avatar3 = /*#__PURE__*/React.createElement(Avatar, {
52
+ name: "Avatar Name"
53
+ }))),
54
+ container = _render2.container;
55
+ const avatarImg = container.querySelector('span[name="Avatar Name"]');
56
+ expect(avatarImg).toHaveAttribute('shape', 'circle');
57
+ });
58
+ it('should render initials', async () => {
59
+ render(_Avatar4 || (_Avatar4 = /*#__PURE__*/React.createElement(Avatar, {
60
+ name: "Avatar Name"
61
+ })));
62
+ const avatarWithInitials = await screen.findByText('AN');
63
+ expect(avatarWithInitials).toBeVisible();
64
+ });
65
+ it('should have border and no box-shadow', async () => {
66
+ const _render3 = render(_Avatar5 || (_Avatar5 = /*#__PURE__*/React.createElement(Avatar, {
67
+ name: "Avatar Name"
68
+ }))),
69
+ container = _render3.container;
70
+ const element = container.querySelector('span');
71
+ expect(element).not.toHaveStyle('border-width: 0px');
72
+ const containerStyle = element && getComputedStyle(element);
73
+ expect(containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.boxShadow).toBe('');
74
+ });
75
+ it('should display the initials in brand color', async () => {
76
+ render(_Avatar6 || (_Avatar6 = /*#__PURE__*/React.createElement(Avatar, {
77
+ name: "Jessica Jones"
78
+ })));
79
+ const initials = screen.getByText('JJ');
80
+ expect(getComputedStyle(initials).color).toBe('rgb(3, 116, 181)');
81
+ });
82
+ it('should return the underlying component', async () => {
83
+ const elementRef = jest.fn();
84
+ const _render4 = render( /*#__PURE__*/React.createElement(Avatar, {
85
+ name: "Avatar Name",
86
+ elementRef: elementRef
87
+ })),
88
+ container = _render4.container;
89
+ expect(elementRef).toHaveBeenCalledWith(container.firstChild);
90
+ });
91
+ });
92
+ describe('when the renderIcon prop is provided', () => {
93
+ it('should display an svg passed', async () => {
94
+ const SomeIcon = () => _svg || (_svg = /*#__PURE__*/React.createElement("svg", null, /*#__PURE__*/React.createElement("circle", {
95
+ cx: "25",
96
+ cy: "75",
97
+ r: "20"
98
+ })));
99
+ const _render5 = render( /*#__PURE__*/React.createElement(Avatar, {
100
+ name: "avatar name",
101
+ renderIcon: SomeIcon
102
+ }, "hello")),
103
+ container = _render5.container;
104
+ const avatarSvg = container.querySelector('svg');
105
+ expect(avatarSvg).toBeInTheDocument();
106
+ });
107
+ it('should display an InstUI icon passed', async () => {
108
+ const _render6 = render(_Avatar7 || (_Avatar7 = /*#__PURE__*/React.createElement(Avatar, {
109
+ name: "avatar name",
110
+ renderIcon: /*#__PURE__*/React.createElement(IconGroupLine, null)
111
+ }, "hello"))),
112
+ container = _render6.container;
113
+ const avatarSvg = container.querySelector('svg');
114
+ expect(avatarSvg).toBeInTheDocument();
115
+ });
116
+ it('should display correctly when an icon renderer is passed', async () => {
117
+ const _render7 = render( /*#__PURE__*/React.createElement(Avatar, {
118
+ name: "Jessica Jones",
119
+ renderIcon: () => _IconGroupLine || (_IconGroupLine = /*#__PURE__*/React.createElement(IconGroupLine, null))
120
+ }, "Hello World")),
121
+ container = _render7.container;
122
+ const avatarSvg = container.querySelector('svg');
123
+ expect(avatarSvg).toBeInTheDocument();
124
+ });
125
+ });
126
+ describe('when an image src url is provided', () => {
127
+ var _Avatar8, _Avatar9, _Avatar10;
128
+ // eslint-disable-next-line max-len
129
+ const src = 'data:image/gif;base64,R0lGODlhFAAUAJEAAP/9/fYQEPytrflWViH5BAAAAAAALAAAAAAUABQAQAJKhI+pGe09lnhBnEETfodatVHNh1BR+ZzH9LAOCYrVYpiAfWWJOxrC/5MASbyZT4d6AUIBlUYGoR1FsAXUuTN5YhxAEYbrpKRkQwEAOw==';
130
+ it('should display the image url provided', async () => {
131
+ const _render8 = render(_Avatar8 || (_Avatar8 = /*#__PURE__*/React.createElement(Avatar, {
132
+ name: "avatar name",
133
+ src: src
134
+ }))),
135
+ container = _render8.container;
136
+ const avatarImg = container.querySelector('img');
137
+ expect(avatarImg).toHaveAttribute('src', src);
138
+ });
139
+ it('should display the image even if an icon is provided', async () => {
140
+ const _render9 = render(_Avatar9 || (_Avatar9 = /*#__PURE__*/React.createElement(Avatar, {
141
+ name: "avatar name",
142
+ src: src,
143
+ renderIcon: _IconGroupLine2 || (_IconGroupLine2 = /*#__PURE__*/React.createElement(IconGroupLine, null))
144
+ }))),
145
+ container = _render9.container;
146
+ const avatarImg = container.querySelector('img');
147
+ expect(avatarImg).toHaveAttribute('src', src);
148
+ });
149
+ it('should call onImageLoaded once the image loads', async () => {
150
+ const onImageLoaded = jest.fn();
151
+ const _render10 = render( /*#__PURE__*/React.createElement(Avatar, {
152
+ name: "Avatar Name",
153
+ onImageLoaded: onImageLoaded
154
+ })),
155
+ container = _render10.container;
156
+ const avatarImg = container.querySelector('img');
157
+ if (avatarImg) {
158
+ fireEvent.load(avatarImg);
159
+ }
160
+ expect(onImageLoaded).toHaveBeenCalled();
161
+ });
162
+ it('should have box-shadow instead of border', async () => {
163
+ const _render11 = render(_Avatar10 || (_Avatar10 = /*#__PURE__*/React.createElement(Avatar, {
164
+ name: "Avatar Name",
165
+ src: src
166
+ }))),
167
+ container = _render11.container;
168
+ const element = container.querySelector('span');
169
+ const avatarImg = container.querySelector('img');
170
+ if (avatarImg) {
171
+ fireEvent.load(avatarImg);
172
+ }
173
+ expect(element).toHaveStyle('border-width: 0px');
174
+ const containerStyle = element && window.getComputedStyle(element);
175
+ expect(containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.boxShadow).not.toBe('');
176
+ });
177
+ });
178
+ describe('when shape is set to "rectangle"', () => {
179
+ it('should display as a rectangle', async () => {
180
+ const _render12 = render(_Avatar11 || (_Avatar11 = /*#__PURE__*/React.createElement(Avatar, {
181
+ name: "Avatar Name",
182
+ shape: "rectangle"
183
+ }))),
184
+ container = _render12.container;
185
+ const avatarImg = container.querySelector('span[name="Avatar Name"]');
186
+ expect(avatarImg).toHaveAttribute('shape', 'rectangle');
187
+ });
188
+ });
189
+ describe('when the color is set to "shamrock"', () => {
190
+ it('should display the initials in green (shamrock)', async () => {
191
+ render(_Avatar12 || (_Avatar12 = /*#__PURE__*/React.createElement(Avatar, {
192
+ name: "Jessica Jones",
193
+ color: "shamrock"
194
+ })));
195
+ const initials = screen.getByText('JJ');
196
+ expect(getComputedStyle(initials).color).toBe('rgb(11, 135, 75)');
197
+ });
198
+ it('should display the icon in green (shamrock)', async () => {
199
+ const _render13 = render(_Avatar13 || (_Avatar13 = /*#__PURE__*/React.createElement(Avatar, {
200
+ name: "Jessica Jones",
201
+ renderIcon: /*#__PURE__*/React.createElement(IconGroupLine, null),
202
+ color: "fire"
203
+ }, "Hello World"))),
204
+ container = _render13.container;
205
+ const avatarSvg = container.querySelector('svg');
206
+ expect(avatarSvg).toHaveStyle({
207
+ fill: '#FC5E13'
208
+ });
209
+ });
210
+ });
211
+ describe('when "hasInverseColor" is set', () => {
212
+ describe('with initials', () => {
213
+ it('should display the background in the color', async () => {
214
+ render(_Avatar14 || (_Avatar14 = /*#__PURE__*/React.createElement(Avatar, {
215
+ name: "Jessica Jones",
216
+ color: "shamrock",
217
+ hasInverseColor: true
218
+ })));
219
+ const initials = screen.getByText('JJ');
220
+ expect(initials.parentNode).toHaveStyle({
221
+ backgroundColor: 'rgb(11, 135, 75)'
222
+ });
223
+ });
224
+ it('should display the initials in white', async () => {
225
+ render(_Avatar15 || (_Avatar15 = /*#__PURE__*/React.createElement(Avatar, {
226
+ name: "Jessica Jones",
227
+ color: "shamrock",
228
+ hasInverseColor: true
229
+ })));
230
+ const initials = screen.getByText('JJ');
231
+ expect(initials).toHaveStyle({
232
+ color: 'rgb(255, 255, 255)'
233
+ });
234
+ });
235
+ });
236
+ describe('with icon', () => {
237
+ it('should display the background in the color', async () => {
238
+ const _render14 = render(_Avatar16 || (_Avatar16 = /*#__PURE__*/React.createElement(Avatar, {
239
+ name: "Jessica Jones",
240
+ color: "shamrock",
241
+ hasInverseColor: true,
242
+ renderIcon: /*#__PURE__*/React.createElement(IconGroupLine, null)
243
+ }))),
244
+ container = _render14.container;
245
+ const element = container.querySelector('span');
246
+ expect(element).toHaveStyle({
247
+ backgroundColor: 'rgb(11, 135, 75)'
248
+ });
249
+ });
250
+ it('should display the icon in white', async () => {
251
+ const _render15 = render(_Avatar17 || (_Avatar17 = /*#__PURE__*/React.createElement(Avatar, {
252
+ name: "Jessica Jones",
253
+ renderIcon: /*#__PURE__*/React.createElement(IconGroupLine, null),
254
+ hasInverseColor: true,
255
+ color: "fire"
256
+ }, "Hello World"))),
257
+ container = _render15.container;
258
+ const avatarSvg = container.querySelector('svg');
259
+ expect(avatarSvg).toHaveStyle({
260
+ fill: '#FFFFFF'
261
+ });
262
+ });
263
+ });
264
+ });
265
+ describe('when the user name has no spaces', () => {
266
+ it('should render a single initial', async () => {
267
+ render(_Avatar18 || (_Avatar18 = /*#__PURE__*/React.createElement(Avatar, {
268
+ name: "Jessica"
269
+ })));
270
+ const initials = screen.getByText('J');
271
+ expect(initials).toBeInTheDocument();
272
+ });
273
+ });
274
+ describe('when the user name has leading spaces', () => {
275
+ it('should skip them', async () => {
276
+ render(_Avatar19 || (_Avatar19 = /*#__PURE__*/React.createElement(Avatar, {
277
+ name: " Jessica Jones"
278
+ })));
279
+ const initials = screen.getByText('JJ');
280
+ expect(initials).toBeInTheDocument();
281
+ });
282
+ });
283
+ describe('when the user name is empty', () => {
284
+ it('should render', async () => {
285
+ const _render16 = render(_Avatar20 || (_Avatar20 = /*#__PURE__*/React.createElement(Avatar, {
286
+ name: ""
287
+ }))),
288
+ container = _render16.container;
289
+ const initials = container.querySelector('[class$="-avatar__initials"]');
290
+ expect(initials).toBeInTheDocument();
291
+ expect(initials).toHaveTextContent('');
292
+ });
293
+ });
294
+ describe('when alt text is provided', () => {
295
+ it('should render the text as an aria-label attribute', async () => {
296
+ render(_Avatar21 || (_Avatar21 = /*#__PURE__*/React.createElement(Avatar, {
297
+ name: "Jessica Jones",
298
+ alt: "This is a test"
299
+ })));
300
+ const initials = screen.getByText('JJ');
301
+ expect(initials.parentNode).toHaveAttribute('aria-label', 'This is a test');
302
+ });
303
+ it('should set the role attribute to img', async () => {
304
+ render(_Avatar22 || (_Avatar22 = /*#__PURE__*/React.createElement(Avatar, {
305
+ name: "Jessica Jones",
306
+ alt: "This is a test"
307
+ })));
308
+ const initials = screen.getByText('JJ');
309
+ expect(initials.parentNode).toHaveAttribute('role', 'img');
310
+ });
311
+ });
312
+ });
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _react = _interopRequireDefault(require("react"));
5
+ var _react2 = require("@testing-library/react");
6
+ var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
7
+ require("@testing-library/jest-dom/extend-expect");
8
+ var _index = _interopRequireDefault(require("../index"));
9
+ var _IconGroupLine3 = require("@instructure/ui-icons/lib/IconGroupLine.js");
10
+ var _Avatar, _Avatar2, _Avatar3, _Avatar4, _Avatar5, _Avatar6, _svg, _Avatar7, _IconGroupLine, _IconGroupLine2, _Avatar11, _Avatar12, _Avatar13, _Avatar14, _Avatar15, _Avatar16, _Avatar17, _Avatar18, _Avatar19, _Avatar20, _Avatar21, _Avatar22;
11
+ /*
12
+ * The MIT License (MIT)
13
+ *
14
+ * Copyright (c) 2015 - present Instructure, Inc.
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ * of this software and associated documentation files (the "Software"), to deal
18
+ * in the Software without restriction, including without limitation the rights
19
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ * copies of the Software, and to permit persons to whom the Software is
21
+ * furnished to do so, subject to the following conditions:
22
+ *
23
+ * The above copyright notice and this permission notice shall be included in all
24
+ * copies or substantial portions of the Software.
25
+ *
26
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ * SOFTWARE.
33
+ */
34
+ describe('<Avatar />', () => {
35
+ describe('for a11y', () => {
36
+ it('should be accessible', async () => {
37
+ const _render = (0, _react2.render)(_Avatar || (_Avatar = /*#__PURE__*/_react.default.createElement(_index.default, {
38
+ name: "Jessica Jones"
39
+ }))),
40
+ container = _render.container;
41
+ const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
42
+ expect(axeCheck).toBe(true);
43
+ });
44
+ it('initials should have aria-hidden=true', async () => {
45
+ (0, _react2.render)(_Avatar2 || (_Avatar2 = /*#__PURE__*/_react.default.createElement(_index.default, {
46
+ name: "Jessica Jones"
47
+ })));
48
+ const initials = _react2.screen.getByText('JJ');
49
+ expect(initials).toHaveAttribute('aria-hidden', 'true');
50
+ });
51
+ });
52
+ describe('with the default props', () => {
53
+ it('should display as a circle', async () => {
54
+ const _render2 = (0, _react2.render)(_Avatar3 || (_Avatar3 = /*#__PURE__*/_react.default.createElement(_index.default, {
55
+ name: "Avatar Name"
56
+ }))),
57
+ container = _render2.container;
58
+ const avatarImg = container.querySelector('span[name="Avatar Name"]');
59
+ expect(avatarImg).toHaveAttribute('shape', 'circle');
60
+ });
61
+ it('should render initials', async () => {
62
+ (0, _react2.render)(_Avatar4 || (_Avatar4 = /*#__PURE__*/_react.default.createElement(_index.default, {
63
+ name: "Avatar Name"
64
+ })));
65
+ const avatarWithInitials = await _react2.screen.findByText('AN');
66
+ expect(avatarWithInitials).toBeVisible();
67
+ });
68
+ it('should have border and no box-shadow', async () => {
69
+ const _render3 = (0, _react2.render)(_Avatar5 || (_Avatar5 = /*#__PURE__*/_react.default.createElement(_index.default, {
70
+ name: "Avatar Name"
71
+ }))),
72
+ container = _render3.container;
73
+ const element = container.querySelector('span');
74
+ expect(element).not.toHaveStyle('border-width: 0px');
75
+ const containerStyle = element && getComputedStyle(element);
76
+ expect(containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.boxShadow).toBe('');
77
+ });
78
+ it('should display the initials in brand color', async () => {
79
+ (0, _react2.render)(_Avatar6 || (_Avatar6 = /*#__PURE__*/_react.default.createElement(_index.default, {
80
+ name: "Jessica Jones"
81
+ })));
82
+ const initials = _react2.screen.getByText('JJ');
83
+ expect(getComputedStyle(initials).color).toBe('rgb(3, 116, 181)');
84
+ });
85
+ it('should return the underlying component', async () => {
86
+ const elementRef = jest.fn();
87
+ const _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
88
+ name: "Avatar Name",
89
+ elementRef: elementRef
90
+ })),
91
+ container = _render4.container;
92
+ expect(elementRef).toHaveBeenCalledWith(container.firstChild);
93
+ });
94
+ });
95
+ describe('when the renderIcon prop is provided', () => {
96
+ it('should display an svg passed', async () => {
97
+ const SomeIcon = () => _svg || (_svg = /*#__PURE__*/_react.default.createElement("svg", null, /*#__PURE__*/_react.default.createElement("circle", {
98
+ cx: "25",
99
+ cy: "75",
100
+ r: "20"
101
+ })));
102
+ const _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
103
+ name: "avatar name",
104
+ renderIcon: SomeIcon
105
+ }, "hello")),
106
+ container = _render5.container;
107
+ const avatarSvg = container.querySelector('svg');
108
+ expect(avatarSvg).toBeInTheDocument();
109
+ });
110
+ it('should display an InstUI icon passed', async () => {
111
+ const _render6 = (0, _react2.render)(_Avatar7 || (_Avatar7 = /*#__PURE__*/_react.default.createElement(_index.default, {
112
+ name: "avatar name",
113
+ renderIcon: /*#__PURE__*/_react.default.createElement(_IconGroupLine3.IconGroupLine, null)
114
+ }, "hello"))),
115
+ container = _render6.container;
116
+ const avatarSvg = container.querySelector('svg');
117
+ expect(avatarSvg).toBeInTheDocument();
118
+ });
119
+ it('should display correctly when an icon renderer is passed', async () => {
120
+ const _render7 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
121
+ name: "Jessica Jones",
122
+ renderIcon: () => _IconGroupLine || (_IconGroupLine = /*#__PURE__*/_react.default.createElement(_IconGroupLine3.IconGroupLine, null))
123
+ }, "Hello World")),
124
+ container = _render7.container;
125
+ const avatarSvg = container.querySelector('svg');
126
+ expect(avatarSvg).toBeInTheDocument();
127
+ });
128
+ });
129
+ describe('when an image src url is provided', () => {
130
+ var _Avatar8, _Avatar9, _Avatar10;
131
+ // eslint-disable-next-line max-len
132
+ const src = 'data:image/gif;base64,R0lGODlhFAAUAJEAAP/9/fYQEPytrflWViH5BAAAAAAALAAAAAAUABQAQAJKhI+pGe09lnhBnEETfodatVHNh1BR+ZzH9LAOCYrVYpiAfWWJOxrC/5MASbyZT4d6AUIBlUYGoR1FsAXUuTN5YhxAEYbrpKRkQwEAOw==';
133
+ it('should display the image url provided', async () => {
134
+ const _render8 = (0, _react2.render)(_Avatar8 || (_Avatar8 = /*#__PURE__*/_react.default.createElement(_index.default, {
135
+ name: "avatar name",
136
+ src: src
137
+ }))),
138
+ container = _render8.container;
139
+ const avatarImg = container.querySelector('img');
140
+ expect(avatarImg).toHaveAttribute('src', src);
141
+ });
142
+ it('should display the image even if an icon is provided', async () => {
143
+ const _render9 = (0, _react2.render)(_Avatar9 || (_Avatar9 = /*#__PURE__*/_react.default.createElement(_index.default, {
144
+ name: "avatar name",
145
+ src: src,
146
+ renderIcon: _IconGroupLine2 || (_IconGroupLine2 = /*#__PURE__*/_react.default.createElement(_IconGroupLine3.IconGroupLine, null))
147
+ }))),
148
+ container = _render9.container;
149
+ const avatarImg = container.querySelector('img');
150
+ expect(avatarImg).toHaveAttribute('src', src);
151
+ });
152
+ it('should call onImageLoaded once the image loads', async () => {
153
+ const onImageLoaded = jest.fn();
154
+ const _render10 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
155
+ name: "Avatar Name",
156
+ onImageLoaded: onImageLoaded
157
+ })),
158
+ container = _render10.container;
159
+ const avatarImg = container.querySelector('img');
160
+ if (avatarImg) {
161
+ _react2.fireEvent.load(avatarImg);
162
+ }
163
+ expect(onImageLoaded).toHaveBeenCalled();
164
+ });
165
+ it('should have box-shadow instead of border', async () => {
166
+ const _render11 = (0, _react2.render)(_Avatar10 || (_Avatar10 = /*#__PURE__*/_react.default.createElement(_index.default, {
167
+ name: "Avatar Name",
168
+ src: src
169
+ }))),
170
+ container = _render11.container;
171
+ const element = container.querySelector('span');
172
+ const avatarImg = container.querySelector('img');
173
+ if (avatarImg) {
174
+ _react2.fireEvent.load(avatarImg);
175
+ }
176
+ expect(element).toHaveStyle('border-width: 0px');
177
+ const containerStyle = element && window.getComputedStyle(element);
178
+ expect(containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.boxShadow).not.toBe('');
179
+ });
180
+ });
181
+ describe('when shape is set to "rectangle"', () => {
182
+ it('should display as a rectangle', async () => {
183
+ const _render12 = (0, _react2.render)(_Avatar11 || (_Avatar11 = /*#__PURE__*/_react.default.createElement(_index.default, {
184
+ name: "Avatar Name",
185
+ shape: "rectangle"
186
+ }))),
187
+ container = _render12.container;
188
+ const avatarImg = container.querySelector('span[name="Avatar Name"]');
189
+ expect(avatarImg).toHaveAttribute('shape', 'rectangle');
190
+ });
191
+ });
192
+ describe('when the color is set to "shamrock"', () => {
193
+ it('should display the initials in green (shamrock)', async () => {
194
+ (0, _react2.render)(_Avatar12 || (_Avatar12 = /*#__PURE__*/_react.default.createElement(_index.default, {
195
+ name: "Jessica Jones",
196
+ color: "shamrock"
197
+ })));
198
+ const initials = _react2.screen.getByText('JJ');
199
+ expect(getComputedStyle(initials).color).toBe('rgb(11, 135, 75)');
200
+ });
201
+ it('should display the icon in green (shamrock)', async () => {
202
+ const _render13 = (0, _react2.render)(_Avatar13 || (_Avatar13 = /*#__PURE__*/_react.default.createElement(_index.default, {
203
+ name: "Jessica Jones",
204
+ renderIcon: /*#__PURE__*/_react.default.createElement(_IconGroupLine3.IconGroupLine, null),
205
+ color: "fire"
206
+ }, "Hello World"))),
207
+ container = _render13.container;
208
+ const avatarSvg = container.querySelector('svg');
209
+ expect(avatarSvg).toHaveStyle({
210
+ fill: '#FC5E13'
211
+ });
212
+ });
213
+ });
214
+ describe('when "hasInverseColor" is set', () => {
215
+ describe('with initials', () => {
216
+ it('should display the background in the color', async () => {
217
+ (0, _react2.render)(_Avatar14 || (_Avatar14 = /*#__PURE__*/_react.default.createElement(_index.default, {
218
+ name: "Jessica Jones",
219
+ color: "shamrock",
220
+ hasInverseColor: true
221
+ })));
222
+ const initials = _react2.screen.getByText('JJ');
223
+ expect(initials.parentNode).toHaveStyle({
224
+ backgroundColor: 'rgb(11, 135, 75)'
225
+ });
226
+ });
227
+ it('should display the initials in white', async () => {
228
+ (0, _react2.render)(_Avatar15 || (_Avatar15 = /*#__PURE__*/_react.default.createElement(_index.default, {
229
+ name: "Jessica Jones",
230
+ color: "shamrock",
231
+ hasInverseColor: true
232
+ })));
233
+ const initials = _react2.screen.getByText('JJ');
234
+ expect(initials).toHaveStyle({
235
+ color: 'rgb(255, 255, 255)'
236
+ });
237
+ });
238
+ });
239
+ describe('with icon', () => {
240
+ it('should display the background in the color', async () => {
241
+ const _render14 = (0, _react2.render)(_Avatar16 || (_Avatar16 = /*#__PURE__*/_react.default.createElement(_index.default, {
242
+ name: "Jessica Jones",
243
+ color: "shamrock",
244
+ hasInverseColor: true,
245
+ renderIcon: /*#__PURE__*/_react.default.createElement(_IconGroupLine3.IconGroupLine, null)
246
+ }))),
247
+ container = _render14.container;
248
+ const element = container.querySelector('span');
249
+ expect(element).toHaveStyle({
250
+ backgroundColor: 'rgb(11, 135, 75)'
251
+ });
252
+ });
253
+ it('should display the icon in white', async () => {
254
+ const _render15 = (0, _react2.render)(_Avatar17 || (_Avatar17 = /*#__PURE__*/_react.default.createElement(_index.default, {
255
+ name: "Jessica Jones",
256
+ renderIcon: /*#__PURE__*/_react.default.createElement(_IconGroupLine3.IconGroupLine, null),
257
+ hasInverseColor: true,
258
+ color: "fire"
259
+ }, "Hello World"))),
260
+ container = _render15.container;
261
+ const avatarSvg = container.querySelector('svg');
262
+ expect(avatarSvg).toHaveStyle({
263
+ fill: '#FFFFFF'
264
+ });
265
+ });
266
+ });
267
+ });
268
+ describe('when the user name has no spaces', () => {
269
+ it('should render a single initial', async () => {
270
+ (0, _react2.render)(_Avatar18 || (_Avatar18 = /*#__PURE__*/_react.default.createElement(_index.default, {
271
+ name: "Jessica"
272
+ })));
273
+ const initials = _react2.screen.getByText('J');
274
+ expect(initials).toBeInTheDocument();
275
+ });
276
+ });
277
+ describe('when the user name has leading spaces', () => {
278
+ it('should skip them', async () => {
279
+ (0, _react2.render)(_Avatar19 || (_Avatar19 = /*#__PURE__*/_react.default.createElement(_index.default, {
280
+ name: " Jessica Jones"
281
+ })));
282
+ const initials = _react2.screen.getByText('JJ');
283
+ expect(initials).toBeInTheDocument();
284
+ });
285
+ });
286
+ describe('when the user name is empty', () => {
287
+ it('should render', async () => {
288
+ const _render16 = (0, _react2.render)(_Avatar20 || (_Avatar20 = /*#__PURE__*/_react.default.createElement(_index.default, {
289
+ name: ""
290
+ }))),
291
+ container = _render16.container;
292
+ const initials = container.querySelector('[class$="-avatar__initials"]');
293
+ expect(initials).toBeInTheDocument();
294
+ expect(initials).toHaveTextContent('');
295
+ });
296
+ });
297
+ describe('when alt text is provided', () => {
298
+ it('should render the text as an aria-label attribute', async () => {
299
+ (0, _react2.render)(_Avatar21 || (_Avatar21 = /*#__PURE__*/_react.default.createElement(_index.default, {
300
+ name: "Jessica Jones",
301
+ alt: "This is a test"
302
+ })));
303
+ const initials = _react2.screen.getByText('JJ');
304
+ expect(initials.parentNode).toHaveAttribute('aria-label', 'This is a test');
305
+ });
306
+ it('should set the role attribute to img', async () => {
307
+ (0, _react2.render)(_Avatar22 || (_Avatar22 = /*#__PURE__*/_react.default.createElement(_index.default, {
308
+ name: "Jessica Jones",
309
+ alt: "This is a test"
310
+ })));
311
+ const initials = _react2.screen.getByText('JJ');
312
+ expect(initials.parentNode).toHaveAttribute('role', 'img');
313
+ });
314
+ });
315
+ });