@object-ui/components 0.5.0 → 3.0.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/.turbo/turbo-build.log +12 -25
- package/CHANGELOG.md +32 -0
- package/dist/index.css +1 -1
- package/dist/index.js +23987 -22576
- package/dist/index.umd.cjs +30 -30
- package/dist/src/custom/action-param-dialog.d.ts +21 -0
- package/dist/src/custom/index.d.ts +4 -0
- package/dist/src/custom/navigation-overlay.d.ts +50 -0
- package/dist/src/custom/view-skeleton.d.ts +37 -0
- package/dist/src/custom/view-states.d.ts +33 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/renderers/action/action-button.d.ts +11 -0
- package/dist/src/renderers/action/action-group.d.ts +25 -0
- package/dist/src/renderers/action/action-icon.d.ts +10 -0
- package/dist/src/renderers/action/action-menu.d.ts +19 -0
- package/dist/src/renderers/action/index.d.ts +0 -0
- package/dist/src/renderers/action/resolve-icon.d.ts +6 -0
- package/package.json +20 -19
- package/src/__tests__/PageRendererRegions.test.tsx +664 -55
- package/src/__tests__/__snapshots__/snapshot-critical.test.tsx.snap +811 -0
- package/src/__tests__/__snapshots__/snapshot.test.tsx.snap +327 -0
- package/src/__tests__/accessibility.test.tsx +137 -0
- package/src/__tests__/api-consistency.test.tsx +596 -0
- package/src/__tests__/color-contrast.test.tsx +212 -0
- package/src/__tests__/compliance.test.tsx +72 -0
- package/src/__tests__/edge-cases.test.tsx +285 -0
- package/src/__tests__/navigation-overlay.test.tsx +273 -0
- package/src/__tests__/snapshot-critical.test.tsx +317 -0
- package/src/__tests__/snapshot.test.tsx +205 -0
- package/src/__tests__/view-compliance.test.tsx +153 -0
- package/src/__tests__/wcag-audit.test.tsx +493 -0
- package/src/custom/action-param-dialog.tsx +264 -0
- package/src/custom/index.ts +4 -0
- package/src/custom/navigation-overlay.tsx +296 -0
- package/src/custom/view-skeleton.tsx +243 -0
- package/src/custom/view-states.tsx +153 -0
- package/src/index.ts +1 -0
- package/src/renderers/action/action-button.tsx +147 -0
- package/src/renderers/action/action-group.tsx +270 -0
- package/src/renderers/action/action-icon.tsx +150 -0
- package/src/renderers/action/action-menu.tsx +203 -0
- package/src/renderers/action/index.ts +18 -0
- package/src/renderers/action/resolve-icon.ts +35 -0
- package/src/renderers/complex/__tests__/data-table-batch-editing.test.tsx +275 -0
- package/src/renderers/complex/__tests__/data-table-cell-renderer.test.tsx +120 -0
- package/src/renderers/complex/__tests__/data-table-editing.test.tsx +221 -0
- package/src/renderers/complex/data-table.tsx +269 -33
- package/src/renderers/complex/resizable.tsx +20 -17
- package/src/renderers/data-display/list.tsx +1 -1
- package/src/renderers/data-display/table.tsx +1 -1
- package/src/renderers/data-display/tree-view.tsx +2 -1
- package/src/renderers/form/form.tsx +33 -10
- package/src/renderers/index.ts +1 -0
- package/src/renderers/layout/aspect-ratio.tsx +1 -1
- package/src/renderers/layout/page.tsx +416 -52
- package/src/renderers/navigation/sidebar.tsx +6 -0
- package/src/renderers/placeholders.tsx +2 -2
- package/src/stories/MockedData.stories.tsx +87 -37
- package/src/stories-json/Accessibility.mdx +297 -0
- package/src/stories-json/EdgeCases.stories.tsx +160 -0
- package/src/stories-json/GettingStarted.mdx +89 -0
- package/src/stories-json/Introduction.mdx +127 -0
- package/src/stories-json/accordion.stories.tsx +1 -1
- package/src/stories-json/aggrid.stories.tsx +1 -1
- package/src/stories-json/alert.stories.tsx +1 -1
- package/src/stories-json/aspect-ratio.stories.tsx +1 -1
- package/src/stories-json/avatar.stories.tsx +1 -1
- package/src/stories-json/badge.stories.tsx +1 -1
- package/src/stories-json/breadcrumb.stories.tsx +1 -1
- package/src/stories-json/button-group.stories.tsx +1 -1
- package/src/stories-json/button.stories.tsx +1 -1
- package/src/stories-json/calendar.stories.tsx +1 -1
- package/src/stories-json/card.stories.tsx +1 -1
- package/src/stories-json/carousel.stories.tsx +1 -1
- package/src/stories-json/charts.stories.tsx +1 -1
- package/src/stories-json/chatbot.stories.tsx +1 -1
- package/src/stories-json/code-editor.stories.tsx +1 -1
- package/src/stories-json/collapsible.stories.tsx +1 -1
- package/src/stories-json/controls.stories.tsx +1 -1
- package/src/stories-json/crm-live-data.stories.tsx +154 -0
- package/src/stories-json/data-table.stories.tsx +80 -4
- package/src/stories-json/data_display_extras.stories.tsx +1 -1
- package/src/stories-json/date-picker.stories.tsx +1 -1
- package/src/stories-json/detail-view.stories.tsx +1 -1
- package/src/stories-json/dialog.stories.tsx +1 -1
- package/src/stories-json/feedback_extras.stories.tsx +1 -1
- package/src/stories-json/feedback_others.stories.tsx +1 -1
- package/src/stories-json/form-variants.stories.tsx +210 -0
- package/src/stories-json/form_advanced.stories.tsx +1 -1
- package/src/stories-json/form_extras.stories.tsx +1 -1
- package/src/stories-json/grid.stories.tsx +1 -1
- package/src/stories-json/icon.stories.tsx +1 -1
- package/src/stories-json/input.stories.tsx +1 -1
- package/src/stories-json/kanban.stories.tsx +1 -1
- package/src/stories-json/layout_extended.stories.tsx +1 -1
- package/src/stories-json/layout_flex.stories.tsx +1 -1
- package/src/stories-json/list-view.stories.tsx +1 -1
- package/src/stories-json/markdown.stories.tsx +1 -1
- package/src/stories-json/menus.stories.tsx +1 -1
- package/src/stories-json/metric-card.stories.tsx +1 -1
- package/src/stories-json/navigation-menu.stories.tsx +1 -1
- package/src/stories-json/object-aggrid-advanced.stories.tsx +389 -0
- package/src/stories-json/object-aggrid.stories.tsx +1 -1
- package/src/stories-json/object-form.stories.tsx +1 -1
- package/src/stories-json/object-gantt.stories.tsx +1 -1
- package/src/stories-json/object-grid.stories.tsx +159 -1
- package/src/stories-json/object-map.stories.tsx +1 -1
- package/src/stories-json/object-view.stories.tsx +1 -1
- package/src/stories-json/overlay_extras.stories.tsx +1 -1
- package/src/stories-json/overlay_others.stories.tsx +1 -1
- package/src/stories-json/resizable.stories.tsx +1 -1
- package/src/stories-json/select.stories.tsx +1 -1
- package/src/stories-json/separator.stories.tsx +1 -1
- package/src/stories-json/statistic.stories.tsx +1 -1
- package/src/stories-json/tabs.stories.tsx +1 -1
- package/src/stories-json/timeline.stories.tsx +1 -1
- package/src/stories-json/typography.stories.tsx +1 -1
- package/src/ui/slider.tsx +6 -2
- package/src/stories/Introduction.mdx +0 -34
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* WCAG 2.1 AA Color Contrast Tests.
|
|
11
|
+
*
|
|
12
|
+
* Verifies that key color combinations used in ObjectUI meet WCAG AA
|
|
13
|
+
* contrast ratio requirements:
|
|
14
|
+
* - 4.5:1 for normal text (< 18pt or < 14pt bold)
|
|
15
|
+
* - 3:1 for large text (≥ 18pt or ≥ 14pt bold)
|
|
16
|
+
*
|
|
17
|
+
* Tests both light and dark theme color values.
|
|
18
|
+
* Part of P2.3 Accessibility & Inclusive Design roadmap.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { describe, it, expect } from 'vitest';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Calculate relative luminance per WCAG 2.1.
|
|
25
|
+
* https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
|
|
26
|
+
*/
|
|
27
|
+
function relativeLuminance(r: number, g: number, b: number): number {
|
|
28
|
+
const [rs, gs, bs] = [r, g, b].map((c) => {
|
|
29
|
+
const sRGB = c / 255;
|
|
30
|
+
return sRGB <= 0.03928 ? sRGB / 12.92 : Math.pow((sRGB + 0.055) / 1.055, 2.4);
|
|
31
|
+
});
|
|
32
|
+
return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Calculate contrast ratio between two colors.
|
|
37
|
+
* https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio
|
|
38
|
+
*/
|
|
39
|
+
function contrastRatio(
|
|
40
|
+
fg: [number, number, number],
|
|
41
|
+
bg: [number, number, number]
|
|
42
|
+
): number {
|
|
43
|
+
const l1 = relativeLuminance(...fg);
|
|
44
|
+
const l2 = relativeLuminance(...bg);
|
|
45
|
+
const lighter = Math.max(l1, l2);
|
|
46
|
+
const darker = Math.min(l1, l2);
|
|
47
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// WCAG AA thresholds
|
|
51
|
+
const AA_NORMAL_TEXT = 4.5;
|
|
52
|
+
const AA_LARGE_TEXT = 3.0;
|
|
53
|
+
|
|
54
|
+
// ── Light Theme Colors (based on Shadcn/Tailwind defaults) ──
|
|
55
|
+
|
|
56
|
+
const light = {
|
|
57
|
+
background: [255, 255, 255] as [number, number, number], // hsl(0 0% 100%)
|
|
58
|
+
foreground: [10, 10, 10] as [number, number, number], // hsl(0 0% 3.9%)
|
|
59
|
+
muted: [245, 245, 245] as [number, number, number], // hsl(0 0% 96.1%)
|
|
60
|
+
mutedForeground: [115, 115, 115] as [number, number, number], // hsl(0 0% 45.1%)
|
|
61
|
+
primary: [24, 24, 27] as [number, number, number], // hsl(240 5.9% 10%)
|
|
62
|
+
primaryForeground: [250, 250, 250] as [number, number, number], // hsl(0 0% 98%)
|
|
63
|
+
destructive: [239, 68, 68] as [number, number, number], // hsl(0 84.2% 60.2%) — red-500
|
|
64
|
+
destructiveForeground: [255, 255, 255] as [number, number, number],
|
|
65
|
+
card: [255, 255, 255] as [number, number, number],
|
|
66
|
+
cardForeground: [10, 10, 10] as [number, number, number],
|
|
67
|
+
border: [229, 229, 229] as [number, number, number], // hsl(0 0% 89.8%)
|
|
68
|
+
accent: [245, 245, 245] as [number, number, number],
|
|
69
|
+
accentForeground: [24, 24, 27] as [number, number, number],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// ── Dark Theme Colors (based on Shadcn/Tailwind defaults) ──
|
|
73
|
+
|
|
74
|
+
const dark = {
|
|
75
|
+
background: [10, 10, 10] as [number, number, number], // hsl(0 0% 3.9%)
|
|
76
|
+
foreground: [250, 250, 250] as [number, number, number], // hsl(0 0% 98%)
|
|
77
|
+
muted: [38, 38, 38] as [number, number, number], // hsl(0 0% 14.9%)
|
|
78
|
+
mutedForeground: [163, 163, 163] as [number, number, number], // hsl(0 0% 63.9%)
|
|
79
|
+
primary: [250, 250, 250] as [number, number, number], // hsl(0 0% 98%)
|
|
80
|
+
primaryForeground: [24, 24, 27] as [number, number, number], // hsl(240 5.9% 10%)
|
|
81
|
+
destructive: [239, 68, 68] as [number, number, number], // hsl(0 84.2% 60.2%) — red-500 (same in dark)
|
|
82
|
+
destructiveForeground: [250, 250, 250] as [number, number, number],
|
|
83
|
+
card: [10, 10, 10] as [number, number, number],
|
|
84
|
+
cardForeground: [250, 250, 250] as [number, number, number],
|
|
85
|
+
border: [38, 38, 38] as [number, number, number],
|
|
86
|
+
accent: [38, 38, 38] as [number, number, number],
|
|
87
|
+
accentForeground: [250, 250, 250] as [number, number, number],
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
describe('WCAG 2.1 AA Color Contrast — Light Theme', () => {
|
|
91
|
+
it('foreground on background meets AA for normal text (4.5:1)', () => {
|
|
92
|
+
const ratio = contrastRatio(light.foreground, light.background);
|
|
93
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('primary foreground on primary meets AA for normal text', () => {
|
|
97
|
+
const ratio = contrastRatio(light.primaryForeground, light.primary);
|
|
98
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('destructive foreground on destructive meets AA for large text (3:1)', () => {
|
|
102
|
+
const ratio = contrastRatio(light.destructiveForeground, light.destructive);
|
|
103
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('muted foreground on background meets AA for large text (3:1)', () => {
|
|
107
|
+
const ratio = contrastRatio(light.mutedForeground, light.background);
|
|
108
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('muted foreground on muted background meets AA for large text (3:1)', () => {
|
|
112
|
+
const ratio = contrastRatio(light.mutedForeground, light.muted);
|
|
113
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('card foreground on card background meets AA for normal text', () => {
|
|
117
|
+
const ratio = contrastRatio(light.cardForeground, light.card);
|
|
118
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('accent foreground on accent background meets AA for normal text', () => {
|
|
122
|
+
const ratio = contrastRatio(light.accentForeground, light.accent);
|
|
123
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('foreground on muted background meets AA for normal text', () => {
|
|
127
|
+
const ratio = contrastRatio(light.foreground, light.muted);
|
|
128
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('primary on background meets AA for normal text', () => {
|
|
132
|
+
const ratio = contrastRatio(light.primary, light.background);
|
|
133
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('destructive on background meets AA for large text', () => {
|
|
137
|
+
const ratio = contrastRatio(light.destructive, light.background);
|
|
138
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('WCAG 2.1 AA Color Contrast — Dark Theme', () => {
|
|
143
|
+
it('foreground on background meets AA for normal text (4.5:1)', () => {
|
|
144
|
+
const ratio = contrastRatio(dark.foreground, dark.background);
|
|
145
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('primary foreground on primary meets AA for normal text', () => {
|
|
149
|
+
const ratio = contrastRatio(dark.primaryForeground, dark.primary);
|
|
150
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('destructive foreground on destructive meets AA for large text (3:1)', () => {
|
|
154
|
+
const ratio = contrastRatio(dark.destructiveForeground, dark.destructive);
|
|
155
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('muted foreground on background meets AA for large text (3:1)', () => {
|
|
159
|
+
const ratio = contrastRatio(dark.mutedForeground, dark.background);
|
|
160
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('muted foreground on muted background meets AA for large text (3:1)', () => {
|
|
164
|
+
const ratio = contrastRatio(dark.mutedForeground, dark.muted);
|
|
165
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('card foreground on card background meets AA for normal text', () => {
|
|
169
|
+
const ratio = contrastRatio(dark.cardForeground, dark.card);
|
|
170
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('accent foreground on accent background meets AA for normal text', () => {
|
|
174
|
+
const ratio = contrastRatio(dark.accentForeground, dark.accent);
|
|
175
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('foreground on muted background meets AA for normal text', () => {
|
|
179
|
+
const ratio = contrastRatio(dark.foreground, dark.muted);
|
|
180
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('primary on background meets AA for normal text', () => {
|
|
184
|
+
const ratio = contrastRatio(dark.primary, dark.background);
|
|
185
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('destructive on background meets AA for large text', () => {
|
|
189
|
+
const ratio = contrastRatio(dark.destructive, dark.background);
|
|
190
|
+
expect(ratio).toBeGreaterThanOrEqual(AA_LARGE_TEXT);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('WCAG 2.1 AA Color Contrast — Utility Validation', () => {
|
|
195
|
+
it('contrastRatio returns 21:1 for black on white', () => {
|
|
196
|
+
const ratio = contrastRatio([0, 0, 0], [255, 255, 255]);
|
|
197
|
+
expect(ratio).toBeCloseTo(21, 0);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('contrastRatio returns 1:1 for same color', () => {
|
|
201
|
+
const ratio = contrastRatio([128, 128, 128], [128, 128, 128]);
|
|
202
|
+
expect(ratio).toBeCloseTo(1, 1);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('relativeLuminance returns 0 for black', () => {
|
|
206
|
+
expect(relativeLuminance(0, 0, 0)).toBe(0);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('relativeLuminance returns 1 for white', () => {
|
|
210
|
+
expect(relativeLuminance(255, 255, 255)).toBeCloseTo(1, 4);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { ComponentRegistry } from '@object-ui/core';
|
|
5
|
+
|
|
6
|
+
// Ensure all components are registered
|
|
7
|
+
import '../index';
|
|
8
|
+
|
|
9
|
+
describe('Component Compliance', () => {
|
|
10
|
+
const components = ComponentRegistry.getAllConfigs();
|
|
11
|
+
|
|
12
|
+
it('should have components registered', () => {
|
|
13
|
+
expect(components.length).toBeGreaterThan(0);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
components.forEach((config) => {
|
|
17
|
+
describe(`Component: ${config.type}`, () => {
|
|
18
|
+
it('should have valid metadata', () => {
|
|
19
|
+
expect(config.type).toBeDefined();
|
|
20
|
+
expect(config.component).toBeDefined();
|
|
21
|
+
// namespace is optional but good practice
|
|
22
|
+
// expect(config.namespace).toBeDefined();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should define inputs if it has any', () => {
|
|
26
|
+
if (config.inputs) {
|
|
27
|
+
expect(Array.isArray(config.inputs)).toBe(true);
|
|
28
|
+
config.inputs?.forEach((input) => {
|
|
29
|
+
expect(input.name).toBeDefined();
|
|
30
|
+
expect(input.type).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should render generic component without crashing', () => {
|
|
36
|
+
const Cmp = config.component as React.ComponentType<any>;
|
|
37
|
+
|
|
38
|
+
// Skip components that are known to require specific parents or context
|
|
39
|
+
// for now, we just try to render them with a basic schema
|
|
40
|
+
const schema = {
|
|
41
|
+
type: config.type,
|
|
42
|
+
id: 'test-id',
|
|
43
|
+
className: 'test-class',
|
|
44
|
+
props: {
|
|
45
|
+
...config.defaultProps
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
// We wrap in a try-catch for now because some components might strictly require context
|
|
51
|
+
// But ideally, renderers should be robust.
|
|
52
|
+
// For now, we prefer to shallow render or just check it is a valid function/class
|
|
53
|
+
expect(Cmp).toBeDefined();
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
Full rendering is risky because of dependencies (e.g. Hooks, Context).
|
|
57
|
+
So we will just verify the sanity of the registration for now.
|
|
58
|
+
If we want to render, we need a wrapper provider.
|
|
59
|
+
*/
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// console.warn(`Render failed for ${config.type}`, e);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should accept className prop if rendered', () => {
|
|
66
|
+
// This is a static check on the 'inputs' metadata to ensure className is exposed?
|
|
67
|
+
// No, className is on the BaseSchema, not necessarily in 'inputs' array (which is for Designer).
|
|
68
|
+
// But checks that component implementation uses 'cn' are hard to do at runtime without rendering.
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* P3.1 Component Quality Audit - Edge Cases
|
|
11
|
+
*
|
|
12
|
+
* Tests key components with edge-case data: null/undefined children,
|
|
13
|
+
* overflow text, empty content, large datasets, and special characters.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, it, expect } from 'vitest';
|
|
17
|
+
import React from 'react';
|
|
18
|
+
import { render, screen } from '@testing-library/react';
|
|
19
|
+
import '@testing-library/jest-dom';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
Badge,
|
|
23
|
+
Button,
|
|
24
|
+
Card,
|
|
25
|
+
CardHeader,
|
|
26
|
+
CardTitle,
|
|
27
|
+
CardContent,
|
|
28
|
+
Input,
|
|
29
|
+
Separator,
|
|
30
|
+
Skeleton,
|
|
31
|
+
Progress,
|
|
32
|
+
Alert,
|
|
33
|
+
AlertTitle,
|
|
34
|
+
AlertDescription,
|
|
35
|
+
Label,
|
|
36
|
+
} from '../index';
|
|
37
|
+
|
|
38
|
+
describe('P3.1 Edge Cases', () => {
|
|
39
|
+
// ---------------------------------------------------------------
|
|
40
|
+
// Null / undefined / empty children
|
|
41
|
+
// ---------------------------------------------------------------
|
|
42
|
+
describe('null and empty children', () => {
|
|
43
|
+
it('Badge renders with empty string', () => {
|
|
44
|
+
const { container } = render(<Badge>{''}</Badge>);
|
|
45
|
+
expect(container.firstElementChild).toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('Badge renders with null child', () => {
|
|
49
|
+
const { container } = render(<Badge>{null}</Badge>);
|
|
50
|
+
expect(container.firstElementChild).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('Badge renders with undefined child', () => {
|
|
54
|
+
const { container } = render(<Badge>{undefined}</Badge>);
|
|
55
|
+
expect(container.firstElementChild).toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('Button renders with empty string', () => {
|
|
59
|
+
render(<Button>{''}</Button>);
|
|
60
|
+
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('Card renders with no children', () => {
|
|
64
|
+
const { container } = render(<Card />);
|
|
65
|
+
expect(container.firstElementChild).toBeInTheDocument();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('CardTitle renders empty', () => {
|
|
69
|
+
const { container } = render(<CardTitle />);
|
|
70
|
+
expect(container.firstElementChild).toBeInTheDocument();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('Alert renders with no children', () => {
|
|
74
|
+
render(<Alert />);
|
|
75
|
+
expect(screen.getByRole('alert')).toBeInTheDocument();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('AlertTitle renders with empty string', () => {
|
|
79
|
+
const { container } = render(<AlertTitle>{''}</AlertTitle>);
|
|
80
|
+
expect(container.firstElementChild).toBeInTheDocument();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('AlertDescription renders with no children', () => {
|
|
84
|
+
const { container } = render(<AlertDescription />);
|
|
85
|
+
expect(container.firstElementChild).toBeInTheDocument();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// ---------------------------------------------------------------
|
|
90
|
+
// Very long text / overflow
|
|
91
|
+
// ---------------------------------------------------------------
|
|
92
|
+
describe('overflow and long text', () => {
|
|
93
|
+
const longText = 'A'.repeat(10000);
|
|
94
|
+
|
|
95
|
+
it('Badge handles very long text without crashing', () => {
|
|
96
|
+
const { container } = render(<Badge>{longText}</Badge>);
|
|
97
|
+
expect(container.textContent).toHaveLength(10000);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('Button handles very long text without crashing', () => {
|
|
101
|
+
render(<Button>{longText}</Button>);
|
|
102
|
+
expect(screen.getByRole('button').textContent).toHaveLength(10000);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('CardTitle handles very long text', () => {
|
|
106
|
+
const { container } = render(<CardTitle>{longText}</CardTitle>);
|
|
107
|
+
expect(container.textContent).toHaveLength(10000);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('Input handles very long value', () => {
|
|
111
|
+
render(<Input defaultValue={longText} data-testid="inp" />);
|
|
112
|
+
expect(screen.getByTestId('inp')).toHaveValue(longText);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('Label handles very long text', () => {
|
|
116
|
+
const { container } = render(<Label>{longText}</Label>);
|
|
117
|
+
expect(container.textContent).toHaveLength(10000);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// ---------------------------------------------------------------
|
|
122
|
+
// Special characters / unicode / emoji
|
|
123
|
+
// ---------------------------------------------------------------
|
|
124
|
+
describe('special characters and unicode', () => {
|
|
125
|
+
it('Badge renders emoji', () => {
|
|
126
|
+
const { container } = render(<Badge>🚀🎉✨</Badge>);
|
|
127
|
+
expect(container.textContent).toBe('🚀🎉✨');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('Button renders RTL text', () => {
|
|
131
|
+
render(<Button>مرحبا</Button>);
|
|
132
|
+
expect(screen.getByRole('button').textContent).toBe('مرحبا');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('CardTitle renders HTML entities as text', () => {
|
|
136
|
+
const { container } = render(<CardTitle>{'<script>alert("xss")</script>'}</CardTitle>);
|
|
137
|
+
expect(container.textContent).toBe('<script>alert("xss")</script>');
|
|
138
|
+
expect(container.querySelector('script')).toBeNull();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('Input handles emoji value', () => {
|
|
142
|
+
render(<Input defaultValue="Hello 🌍" data-testid="inp" />);
|
|
143
|
+
expect(screen.getByTestId('inp')).toHaveValue('Hello 🌍');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('Alert handles multi-language text', () => {
|
|
147
|
+
render(
|
|
148
|
+
<Alert>
|
|
149
|
+
<AlertTitle>日本語タイトル</AlertTitle>
|
|
150
|
+
<AlertDescription>中文描述 и русский текст</AlertDescription>
|
|
151
|
+
</Alert>
|
|
152
|
+
);
|
|
153
|
+
expect(screen.getByText('日本語タイトル')).toBeInTheDocument();
|
|
154
|
+
expect(screen.getByText('中文描述 и русский текст')).toBeInTheDocument();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// ---------------------------------------------------------------
|
|
159
|
+
// Numeric edge cases
|
|
160
|
+
// ---------------------------------------------------------------
|
|
161
|
+
describe('numeric edge cases', () => {
|
|
162
|
+
it('Progress handles value of 0', () => {
|
|
163
|
+
render(<Progress value={0} data-testid="prog" />);
|
|
164
|
+
expect(screen.getByTestId('prog')).toBeInTheDocument();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('Progress handles value of 100', () => {
|
|
168
|
+
render(<Progress value={100} data-testid="prog" />);
|
|
169
|
+
expect(screen.getByTestId('prog')).toBeInTheDocument();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('Progress handles negative value gracefully', () => {
|
|
173
|
+
render(<Progress value={-10} data-testid="prog" />);
|
|
174
|
+
expect(screen.getByTestId('prog')).toBeInTheDocument();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('Progress handles value > 100 gracefully', () => {
|
|
178
|
+
render(<Progress value={200} data-testid="prog" />);
|
|
179
|
+
expect(screen.getByTestId('prog')).toBeInTheDocument();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('Progress handles undefined value', () => {
|
|
183
|
+
render(<Progress value={undefined} data-testid="prog" />);
|
|
184
|
+
expect(screen.getByTestId('prog')).toBeInTheDocument();
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// ---------------------------------------------------------------
|
|
189
|
+
// Multiple instances
|
|
190
|
+
// ---------------------------------------------------------------
|
|
191
|
+
describe('multiple component instances', () => {
|
|
192
|
+
it('renders many Badges without interference', () => {
|
|
193
|
+
const { container } = render(
|
|
194
|
+
<div>
|
|
195
|
+
{Array.from({ length: 100 }, (_, i) => (
|
|
196
|
+
<Badge key={i}>Badge {i}</Badge>
|
|
197
|
+
))}
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
const badges = container.querySelectorAll('[class*="inline-flex"]');
|
|
201
|
+
expect(badges.length).toBe(100);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('renders many Buttons without interference', () => {
|
|
205
|
+
render(
|
|
206
|
+
<div>
|
|
207
|
+
{Array.from({ length: 50 }, (_, i) => (
|
|
208
|
+
<Button key={i}>Btn {i}</Button>
|
|
209
|
+
))}
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
expect(screen.getAllByRole('button')).toHaveLength(50);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('renders many Inputs without interference', () => {
|
|
216
|
+
render(
|
|
217
|
+
<div>
|
|
218
|
+
{Array.from({ length: 50 }, (_, i) => (
|
|
219
|
+
<Input key={i} data-testid={`inp-${i}`} defaultValue={`val-${i}`} />
|
|
220
|
+
))}
|
|
221
|
+
</div>
|
|
222
|
+
);
|
|
223
|
+
expect(screen.getByTestId('inp-0')).toHaveValue('val-0');
|
|
224
|
+
expect(screen.getByTestId('inp-49')).toHaveValue('val-49');
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// ---------------------------------------------------------------
|
|
229
|
+
// Separator edge cases
|
|
230
|
+
// ---------------------------------------------------------------
|
|
231
|
+
describe('Separator edge cases', () => {
|
|
232
|
+
it('renders multiple separators', () => {
|
|
233
|
+
const { container } = render(
|
|
234
|
+
<div>
|
|
235
|
+
<Separator />
|
|
236
|
+
<Separator />
|
|
237
|
+
<Separator />
|
|
238
|
+
</div>
|
|
239
|
+
);
|
|
240
|
+
expect(container.querySelectorAll('[data-orientation]')).toHaveLength(3);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// ---------------------------------------------------------------
|
|
245
|
+
// Skeleton edge cases
|
|
246
|
+
// ---------------------------------------------------------------
|
|
247
|
+
describe('Skeleton edge cases', () => {
|
|
248
|
+
it('renders with custom dimensions via className', () => {
|
|
249
|
+
const { container } = render(<Skeleton className="w-[200px] h-[20px]" />);
|
|
250
|
+
expect(container.firstElementChild!.className).toContain('w-[200px]');
|
|
251
|
+
expect(container.firstElementChild!.className).toContain('h-[20px]');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('renders with children', () => {
|
|
255
|
+
const { container } = render(<Skeleton>Loading...</Skeleton>);
|
|
256
|
+
expect(container.textContent).toBe('Loading...');
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// ---------------------------------------------------------------
|
|
261
|
+
// Card with complex nested content
|
|
262
|
+
// ---------------------------------------------------------------
|
|
263
|
+
describe('Card with complex nested content', () => {
|
|
264
|
+
it('renders deeply nested structure', () => {
|
|
265
|
+
const { container } = render(
|
|
266
|
+
<Card>
|
|
267
|
+
<CardHeader>
|
|
268
|
+
<CardTitle>
|
|
269
|
+
<Badge>New</Badge> Dashboard
|
|
270
|
+
</CardTitle>
|
|
271
|
+
</CardHeader>
|
|
272
|
+
<CardContent>
|
|
273
|
+
<div>
|
|
274
|
+
<Button>Action 1</Button>
|
|
275
|
+
<Button>Action 2</Button>
|
|
276
|
+
</div>
|
|
277
|
+
</CardContent>
|
|
278
|
+
</Card>
|
|
279
|
+
);
|
|
280
|
+
expect(container.textContent).toContain('New');
|
|
281
|
+
expect(container.textContent).toContain('Dashboard');
|
|
282
|
+
expect(screen.getAllByRole('button')).toHaveLength(2);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|