@instructure/ui-avatar 10.19.2-snapshot-2 → 10.19.2-snapshot-4

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