@pingux/astro 2.184.0-alpha.0 → 2.185.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 +1 -1
- package/lib/cjs/components/Avatar/Avatar.test.js +21 -17
- package/lib/cjs/components/PanelHeader/PanelHeader.js +0 -1
- package/lib/components/Avatar/Avatar.js +1 -1
- package/lib/components/Avatar/Avatar.test.js +21 -17
- package/lib/components/PanelHeader/PanelHeader.js +0 -1
- package/package.json +1 -1
|
@@ -44,7 +44,7 @@ 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
|
-
var safeColorId = colorId || '_INTERNAL_DEFAULT_ID_';
|
|
47
|
+
var safeColorId = colorId || (defaultText && defaultText !== 'AA' ? defaultText : '_INTERNAL_DEFAULT_ID_');
|
|
48
48
|
if (process.env.NODE_ENV !== 'production') {
|
|
49
49
|
if (!src && !color && !colorId) {
|
|
50
50
|
console.warn("[Astro] Avatar: No 'src', 'color', or 'colorId' provided. " + 'The component is falling back to a default generated color.');
|
|
@@ -25,7 +25,6 @@ var getComponent = function getComponent() {
|
|
|
25
25
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
26
26
|
return (0, _testWrapper.render)((0, _react2.jsx)(_["default"], (0, _extends2["default"])({}, defaultProps, props)));
|
|
27
27
|
};
|
|
28
|
-
// Needs to be added to each components test file
|
|
29
28
|
(0, _universalComponentTest.universalComponentTests)({
|
|
30
29
|
renderComponent: function renderComponent(props) {
|
|
31
30
|
return (0, _react2.jsx)(_["default"], (0, _extends2["default"])({}, defaultProps, props));
|
|
@@ -45,7 +44,7 @@ test('an avatar is rendered with custom alt', function () {
|
|
|
45
44
|
var img = _testWrapper.screen.getByRole('img');
|
|
46
45
|
expect(img).toHaveAttribute('alt', 'Custom Alt');
|
|
47
46
|
});
|
|
48
|
-
test('an avatar is rendered with
|
|
47
|
+
test('an avatar is rendered with initials', function () {
|
|
49
48
|
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
50
49
|
getComponent({
|
|
51
50
|
src: undefined,
|
|
@@ -70,9 +69,6 @@ describe('getColorFromUUID', function () {
|
|
|
70
69
|
test('distributes colors differently for different UUIDs', function () {
|
|
71
70
|
var colorA = (0, _getColorFromUuid["default"])('id-1', _constants.avatarColors);
|
|
72
71
|
var colorB = (0, _getColorFromUuid["default"])('id-2', _constants.avatarColors);
|
|
73
|
-
|
|
74
|
-
// While collisions are mathematically possible, for 2 items in a 10-item list,
|
|
75
|
-
// these specific IDs yield different results in FNV-1a.
|
|
76
72
|
expect(colorA).not.toBe(colorB);
|
|
77
73
|
});
|
|
78
74
|
test('throws error if color array is empty', function () {
|
|
@@ -86,8 +82,6 @@ describe('getColorFromUUID', function () {
|
|
|
86
82
|
colorId: 'some-id'
|
|
87
83
|
});
|
|
88
84
|
var avatar = _testWrapper.screen.getByTestId(datatestId);
|
|
89
|
-
|
|
90
|
-
// Checking for 'is-blue'
|
|
91
85
|
expect(avatar).toHaveClass('is-blue');
|
|
92
86
|
});
|
|
93
87
|
test('applies a hashed color class from colorId', function () {
|
|
@@ -96,9 +90,6 @@ describe('getColorFromUUID', function () {
|
|
|
96
90
|
colorId: uuid
|
|
97
91
|
});
|
|
98
92
|
var avatar = _testWrapper.screen.getByTestId(datatestId);
|
|
99
|
-
|
|
100
|
-
// We check that it has *a* class starting with 'is-'
|
|
101
|
-
// and specifically isn't the default 'is-green'
|
|
102
93
|
var classList = (0, _from["default"])(avatar.classList);
|
|
103
94
|
var colorClass = (0, _find["default"])(classList).call(classList, function (cls) {
|
|
104
95
|
return (0, _startsWith["default"])(cls).call(cls, 'is-');
|
|
@@ -171,27 +162,40 @@ describe('getColorFromUUID Distribution', function () {
|
|
|
171
162
|
test('distributes 10,000 UUIDs evenly across 10 colors', function () {
|
|
172
163
|
var iterations = 10000;
|
|
173
164
|
var distribution = {};
|
|
174
|
-
|
|
175
|
-
// Initialize counts
|
|
176
165
|
(0, _forEach["default"])(_constants.avatarColors).call(_constants.avatarColors, function (c) {
|
|
177
166
|
distribution[c] = 0;
|
|
178
167
|
});
|
|
179
|
-
|
|
180
|
-
// Generate and hash
|
|
181
168
|
for (var i = 0; i < iterations; i += 1) {
|
|
182
|
-
// Use the imported randomUUID function directly
|
|
183
169
|
var uuid = (0, _nodeCrypto.randomUUID)();
|
|
184
170
|
var selectedColor = (0, _getColorFromUuid["default"])(uuid, _constants.avatarColors);
|
|
185
171
|
distribution[selectedColor] += 1;
|
|
186
172
|
}
|
|
187
173
|
var expectedMean = iterations / _constants.avatarColors.length;
|
|
188
|
-
// 15% variance is a safe threshold for 10k iterations
|
|
189
174
|
var allowedVariance = 0.15;
|
|
190
175
|
(0, _forEach["default"])(_constants.avatarColors).call(_constants.avatarColors, function (color) {
|
|
191
176
|
var count = distribution[color];
|
|
192
|
-
// Assert that each color is roughly 10% of the total
|
|
193
177
|
expect(count).toBeGreaterThan(expectedMean * (1 - allowedVariance));
|
|
194
178
|
expect(count).toBeLessThan(expectedMean * (1 + allowedVariance));
|
|
195
179
|
});
|
|
196
180
|
});
|
|
181
|
+
});
|
|
182
|
+
describe('Color Selection Logic', function () {
|
|
183
|
+
var getResolvedId = function getResolvedId(colorId, defaultText) {
|
|
184
|
+
return colorId || (defaultText && defaultText !== 'AA' ? defaultText : '_INTERNAL_DEFAULT_ID_');
|
|
185
|
+
};
|
|
186
|
+
test('should use colorId if it is provided', function () {
|
|
187
|
+
expect(getResolvedId('custom-id', 'BB')).toBe('custom-id');
|
|
188
|
+
});
|
|
189
|
+
test('should use defaultText if colorId is missing and text is not "AA"', function () {
|
|
190
|
+
expect(getResolvedId(null, 'BB')).toBe('BB');
|
|
191
|
+
});
|
|
192
|
+
test('should use hardcoded string if colorId is missing and text is "AA"', function () {
|
|
193
|
+
expect(getResolvedId(undefined, 'AA')).toBe('_INTERNAL_DEFAULT_ID_');
|
|
194
|
+
});
|
|
195
|
+
test('should use hardcoded string if both colorId and defaultText are null', function () {
|
|
196
|
+
expect(getResolvedId(null, null)).toBe('_INTERNAL_DEFAULT_ID_');
|
|
197
|
+
});
|
|
198
|
+
test('should use hardcoded string if colorId is missing and defaultText is empty string', function () {
|
|
199
|
+
expect(getResolvedId(null, '')).toBe('_INTERNAL_DEFAULT_ID_');
|
|
200
|
+
});
|
|
197
201
|
});
|
|
@@ -61,7 +61,6 @@ var PanelHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
61
61
|
}
|
|
62
62
|
}));
|
|
63
63
|
var renderAvatar = (0, _react2.jsx)(_index.Avatar, (0, _extends2["default"])({
|
|
64
|
-
color: image !== null && image !== void 0 && image.src ? false : 'green',
|
|
65
64
|
src: image === null || image === void 0 ? void 0 : image.src,
|
|
66
65
|
isSquare: !!(image !== null && image !== void 0 && image.src),
|
|
67
66
|
size: "avatar.lg",
|
|
@@ -34,7 +34,7 @@ var Avatar = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
34
34
|
isSquare = props.isSquare,
|
|
35
35
|
isLogo = props.isLogo,
|
|
36
36
|
others = _objectWithoutProperties(props, _excluded);
|
|
37
|
-
var safeColorId = colorId || '_INTERNAL_DEFAULT_ID_';
|
|
37
|
+
var safeColorId = colorId || (defaultText && defaultText !== 'AA' ? defaultText : '_INTERNAL_DEFAULT_ID_');
|
|
38
38
|
if (process.env.NODE_ENV !== 'production') {
|
|
39
39
|
if (!src && !color && !colorId) {
|
|
40
40
|
console.warn("[Astro] Avatar: No 'src', 'color', or 'colorId' provided. " + 'The component is falling back to a default generated color.');
|
|
@@ -22,7 +22,6 @@ var getComponent = function getComponent() {
|
|
|
22
22
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
23
23
|
return render(___EmotionJSX(Avatar, _extends({}, defaultProps, props)));
|
|
24
24
|
};
|
|
25
|
-
// Needs to be added to each components test file
|
|
26
25
|
universalComponentTests({
|
|
27
26
|
renderComponent: function renderComponent(props) {
|
|
28
27
|
return ___EmotionJSX(Avatar, _extends({}, defaultProps, props));
|
|
@@ -42,7 +41,7 @@ test('an avatar is rendered with custom alt', function () {
|
|
|
42
41
|
var img = screen.getByRole('img');
|
|
43
42
|
expect(img).toHaveAttribute('alt', 'Custom Alt');
|
|
44
43
|
});
|
|
45
|
-
test('an avatar is rendered with
|
|
44
|
+
test('an avatar is rendered with initials', function () {
|
|
46
45
|
var warnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
47
46
|
getComponent({
|
|
48
47
|
src: undefined,
|
|
@@ -67,9 +66,6 @@ describe('getColorFromUUID', function () {
|
|
|
67
66
|
test('distributes colors differently for different UUIDs', function () {
|
|
68
67
|
var colorA = getColorFromUUID('id-1', colors);
|
|
69
68
|
var colorB = getColorFromUUID('id-2', colors);
|
|
70
|
-
|
|
71
|
-
// While collisions are mathematically possible, for 2 items in a 10-item list,
|
|
72
|
-
// these specific IDs yield different results in FNV-1a.
|
|
73
69
|
expect(colorA).not.toBe(colorB);
|
|
74
70
|
});
|
|
75
71
|
test('throws error if color array is empty', function () {
|
|
@@ -83,8 +79,6 @@ describe('getColorFromUUID', function () {
|
|
|
83
79
|
colorId: 'some-id'
|
|
84
80
|
});
|
|
85
81
|
var avatar = screen.getByTestId(datatestId);
|
|
86
|
-
|
|
87
|
-
// Checking for 'is-blue'
|
|
88
82
|
expect(avatar).toHaveClass('is-blue');
|
|
89
83
|
});
|
|
90
84
|
test('applies a hashed color class from colorId', function () {
|
|
@@ -93,9 +87,6 @@ describe('getColorFromUUID', function () {
|
|
|
93
87
|
colorId: uuid
|
|
94
88
|
});
|
|
95
89
|
var avatar = screen.getByTestId(datatestId);
|
|
96
|
-
|
|
97
|
-
// We check that it has *a* class starting with 'is-'
|
|
98
|
-
// and specifically isn't the default 'is-green'
|
|
99
90
|
var classList = _Array$from(avatar.classList);
|
|
100
91
|
var colorClass = _findInstanceProperty(classList).call(classList, function (cls) {
|
|
101
92
|
return _startsWithInstanceProperty(cls).call(cls, 'is-');
|
|
@@ -168,27 +159,40 @@ describe('getColorFromUUID Distribution', function () {
|
|
|
168
159
|
test('distributes 10,000 UUIDs evenly across 10 colors', function () {
|
|
169
160
|
var iterations = 10000;
|
|
170
161
|
var distribution = {};
|
|
171
|
-
|
|
172
|
-
// Initialize counts
|
|
173
162
|
_forEachInstanceProperty(colors).call(colors, function (c) {
|
|
174
163
|
distribution[c] = 0;
|
|
175
164
|
});
|
|
176
|
-
|
|
177
|
-
// Generate and hash
|
|
178
165
|
for (var i = 0; i < iterations; i += 1) {
|
|
179
|
-
// Use the imported randomUUID function directly
|
|
180
166
|
var uuid = randomUUID();
|
|
181
167
|
var selectedColor = getColorFromUUID(uuid, colors);
|
|
182
168
|
distribution[selectedColor] += 1;
|
|
183
169
|
}
|
|
184
170
|
var expectedMean = iterations / colors.length;
|
|
185
|
-
// 15% variance is a safe threshold for 10k iterations
|
|
186
171
|
var allowedVariance = 0.15;
|
|
187
172
|
_forEachInstanceProperty(colors).call(colors, function (color) {
|
|
188
173
|
var count = distribution[color];
|
|
189
|
-
// Assert that each color is roughly 10% of the total
|
|
190
174
|
expect(count).toBeGreaterThan(expectedMean * (1 - allowedVariance));
|
|
191
175
|
expect(count).toBeLessThan(expectedMean * (1 + allowedVariance));
|
|
192
176
|
});
|
|
193
177
|
});
|
|
178
|
+
});
|
|
179
|
+
describe('Color Selection Logic', function () {
|
|
180
|
+
var getResolvedId = function getResolvedId(colorId, defaultText) {
|
|
181
|
+
return colorId || (defaultText && defaultText !== 'AA' ? defaultText : '_INTERNAL_DEFAULT_ID_');
|
|
182
|
+
};
|
|
183
|
+
test('should use colorId if it is provided', function () {
|
|
184
|
+
expect(getResolvedId('custom-id', 'BB')).toBe('custom-id');
|
|
185
|
+
});
|
|
186
|
+
test('should use defaultText if colorId is missing and text is not "AA"', function () {
|
|
187
|
+
expect(getResolvedId(null, 'BB')).toBe('BB');
|
|
188
|
+
});
|
|
189
|
+
test('should use hardcoded string if colorId is missing and text is "AA"', function () {
|
|
190
|
+
expect(getResolvedId(undefined, 'AA')).toBe('_INTERNAL_DEFAULT_ID_');
|
|
191
|
+
});
|
|
192
|
+
test('should use hardcoded string if both colorId and defaultText are null', function () {
|
|
193
|
+
expect(getResolvedId(null, null)).toBe('_INTERNAL_DEFAULT_ID_');
|
|
194
|
+
});
|
|
195
|
+
test('should use hardcoded string if colorId is missing and defaultText is empty string', function () {
|
|
196
|
+
expect(getResolvedId(null, '')).toBe('_INTERNAL_DEFAULT_ID_');
|
|
197
|
+
});
|
|
194
198
|
});
|
|
@@ -51,7 +51,6 @@ var PanelHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
51
51
|
}
|
|
52
52
|
}));
|
|
53
53
|
var renderAvatar = ___EmotionJSX(Avatar, _extends({
|
|
54
|
-
color: image !== null && image !== void 0 && image.src ? false : 'green',
|
|
55
54
|
src: image === null || image === void 0 ? void 0 : image.src,
|
|
56
55
|
isSquare: !!(image !== null && image !== void 0 && image.src),
|
|
57
56
|
size: "avatar.lg",
|