@pingux/astro 2.178.4-alpha.0 → 2.179.0-alpha.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/lib/cjs/components/Avatar/Avatar.js +8 -6
- package/lib/cjs/components/Avatar/Avatar.test.js +57 -0
- package/lib/cjs/libs/astro/src/types/avatar.d.ts +1 -1
- package/lib/cjs/libs/astro/tsconfig.lib.tsbuildinfo +1 -1
- package/lib/components/Avatar/Avatar.js +8 -6
- package/lib/components/Avatar/Avatar.test.js +57 -0
- package/package.json +1 -1
|
@@ -44,14 +44,16 @@ var Avatar = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
44
44
|
isSquare = props.isSquare,
|
|
45
45
|
isLogo = props.isLogo,
|
|
46
46
|
others = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
var safeColorId = colorId || '_INTERNAL_DEFAULT_ID_';
|
|
48
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
49
|
+
if (!src && !color && !colorId) {
|
|
50
|
+
console.warn("[Astro] Avatar: No 'src', 'color', or 'colorId' provided. " + 'The component is falling back to a default generated color.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
50
53
|
var finalColor = (0, _react.useMemo)(function () {
|
|
51
54
|
if (color) return color;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}, [color, colorId, _constants.avatarColors]);
|
|
55
|
+
return (0, _getColorFromUuid["default"])(safeColorId, _constants.avatarColors);
|
|
56
|
+
}, [color, safeColorId]);
|
|
55
57
|
var _useStatusClasses = (0, _hooks.useStatusClasses)(className, (0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, "is-".concat(finalColor), finalColor), "size-".concat(size), size), "font-size-".concat(size), src ? false : size), 'is-square', isSquare), 'is-image', src), 'is-logo', isLogo)),
|
|
56
58
|
classNames = _useStatusClasses.classNames;
|
|
57
59
|
if (src) {
|
|
@@ -46,12 +46,14 @@ test('an avatar is rendered with custom alt', function () {
|
|
|
46
46
|
expect(img).toHaveAttribute('alt', 'Custom Alt');
|
|
47
47
|
});
|
|
48
48
|
test('an avatar is rendered with custom alt', function () {
|
|
49
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
49
50
|
getComponent({
|
|
50
51
|
src: undefined,
|
|
51
52
|
defaultText: 'KL'
|
|
52
53
|
});
|
|
53
54
|
var avatar = _testWrapper.screen.getByText('KL');
|
|
54
55
|
expect(avatar).toBeInTheDocument();
|
|
56
|
+
warnSpy.mockRestore();
|
|
55
57
|
});
|
|
56
58
|
describe('getColorFromUUID', function () {
|
|
57
59
|
test('returns a consistent color for the same UUID', function () {
|
|
@@ -110,6 +112,61 @@ describe('getColorFromUUID', function () {
|
|
|
110
112
|
expect(avatar).toHaveClass('is-green');
|
|
111
113
|
});
|
|
112
114
|
});
|
|
115
|
+
describe('Avatar fallback behavior', function () {
|
|
116
|
+
test('warns in development when no src, color, or colorId is provided', function () {
|
|
117
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
118
|
+
getComponent({
|
|
119
|
+
src: undefined
|
|
120
|
+
});
|
|
121
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("No 'src', 'color', or 'colorId' provided"));
|
|
122
|
+
warnSpy.mockRestore();
|
|
123
|
+
});
|
|
124
|
+
test('does not crash when colorId is null', function () {
|
|
125
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
126
|
+
getComponent({
|
|
127
|
+
src: undefined,
|
|
128
|
+
colorId: null
|
|
129
|
+
});
|
|
130
|
+
var avatar = _testWrapper.screen.getByTestId(datatestId);
|
|
131
|
+
var classList = (0, _from["default"])(avatar.classList);
|
|
132
|
+
var colorClass = (0, _find["default"])(classList).call(classList, function (cls) {
|
|
133
|
+
return (0, _startsWith["default"])(cls).call(cls, 'is-');
|
|
134
|
+
});
|
|
135
|
+
expect(colorClass).toBeDefined();
|
|
136
|
+
warnSpy.mockRestore();
|
|
137
|
+
});
|
|
138
|
+
test('two avatars with missing colorId get the same color class', function () {
|
|
139
|
+
var _context, _context2;
|
|
140
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
141
|
+
var _render = (0, _testWrapper.render)((0, _react2.jsx)(_["default"], {
|
|
142
|
+
"data-testid": "avatar-1"
|
|
143
|
+
})),
|
|
144
|
+
unmount = _render.unmount;
|
|
145
|
+
var avatar1 = _testWrapper.screen.getByTestId('avatar-1');
|
|
146
|
+
var colorClass1 = (0, _find["default"])(_context = (0, _from["default"])(avatar1.classList)).call(_context, function (cls) {
|
|
147
|
+
return (0, _startsWith["default"])(cls).call(cls, 'is-');
|
|
148
|
+
});
|
|
149
|
+
unmount();
|
|
150
|
+
(0, _testWrapper.render)((0, _react2.jsx)(_["default"], {
|
|
151
|
+
"data-testid": "avatar-2"
|
|
152
|
+
}));
|
|
153
|
+
var avatar2 = _testWrapper.screen.getByTestId('avatar-2');
|
|
154
|
+
var colorClass2 = (0, _find["default"])(_context2 = (0, _from["default"])(avatar2.classList)).call(_context2, function (cls) {
|
|
155
|
+
return (0, _startsWith["default"])(cls).call(cls, 'is-');
|
|
156
|
+
});
|
|
157
|
+
expect(colorClass1).toBe(colorClass2);
|
|
158
|
+
warnSpy.mockRestore();
|
|
159
|
+
});
|
|
160
|
+
test('does not warn when color prop is provided', function () {
|
|
161
|
+
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
162
|
+
getComponent({
|
|
163
|
+
src: undefined,
|
|
164
|
+
color: 'blue'
|
|
165
|
+
});
|
|
166
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
167
|
+
warnSpy.mockRestore();
|
|
168
|
+
});
|
|
169
|
+
});
|
|
113
170
|
describe('getColorFromUUID Distribution', function () {
|
|
114
171
|
test('distributes 10,000 UUIDs evenly across 10 colors', function () {
|
|
115
172
|
var iterations = 10000;
|