@object-ui/core 3.3.0 → 3.3.2

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +20 -1
  3. package/dist/actions/ActionRunner.d.ts +9 -0
  4. package/dist/actions/ActionRunner.js +41 -4
  5. package/dist/adapters/ValueDataSource.js +3 -1
  6. package/dist/registry/Registry.d.ts +47 -0
  7. package/dist/registry/Registry.js +92 -0
  8. package/dist/utils/filter-converter.js +25 -5
  9. package/package.json +32 -8
  10. package/.turbo/turbo-build.log +0 -4
  11. package/src/__benchmarks__/core.bench.ts +0 -64
  12. package/src/__tests__/protocols/DndProtocol.test.ts +0 -186
  13. package/src/__tests__/protocols/KeyboardProtocol.test.ts +0 -177
  14. package/src/__tests__/protocols/NotificationProtocol.test.ts +0 -142
  15. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +0 -176
  16. package/src/__tests__/protocols/SharingProtocol.test.ts +0 -188
  17. package/src/actions/ActionEngine.ts +0 -268
  18. package/src/actions/ActionRunner.ts +0 -717
  19. package/src/actions/TransactionManager.ts +0 -521
  20. package/src/actions/UndoManager.ts +0 -215
  21. package/src/actions/__tests__/ActionEngine.test.ts +0 -206
  22. package/src/actions/__tests__/ActionRunner.params.test.ts +0 -134
  23. package/src/actions/__tests__/ActionRunner.test.ts +0 -711
  24. package/src/actions/__tests__/TransactionManager.test.ts +0 -447
  25. package/src/actions/__tests__/UndoManager.test.ts +0 -320
  26. package/src/actions/index.ts +0 -12
  27. package/src/adapters/ApiDataSource.ts +0 -376
  28. package/src/adapters/README.md +0 -180
  29. package/src/adapters/ValueDataSource.ts +0 -459
  30. package/src/adapters/__tests__/ApiDataSource.test.ts +0 -418
  31. package/src/adapters/__tests__/ValueDataSource.test.ts +0 -571
  32. package/src/adapters/__tests__/resolveDataSource.test.ts +0 -144
  33. package/src/adapters/index.ts +0 -15
  34. package/src/adapters/resolveDataSource.ts +0 -79
  35. package/src/builder/__tests__/schema-builder.test.ts +0 -235
  36. package/src/builder/schema-builder.ts +0 -584
  37. package/src/data-scope/DataScopeManager.ts +0 -269
  38. package/src/data-scope/ViewDataProvider.ts +0 -282
  39. package/src/data-scope/__tests__/DataScopeManager.test.ts +0 -211
  40. package/src/data-scope/__tests__/ViewDataProvider.test.ts +0 -270
  41. package/src/data-scope/index.ts +0 -24
  42. package/src/errors/__tests__/errors.test.ts +0 -292
  43. package/src/errors/index.ts +0 -269
  44. package/src/evaluator/ExpressionCache.ts +0 -206
  45. package/src/evaluator/ExpressionContext.ts +0 -118
  46. package/src/evaluator/ExpressionEvaluator.ts +0 -315
  47. package/src/evaluator/FormulaFunctions.ts +0 -398
  48. package/src/evaluator/SafeExpressionParser.ts +0 -893
  49. package/src/evaluator/__tests__/ExpressionCache.test.ts +0 -135
  50. package/src/evaluator/__tests__/ExpressionContext.test.ts +0 -110
  51. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +0 -558
  52. package/src/evaluator/__tests__/FormulaFunctions.test.ts +0 -447
  53. package/src/evaluator/index.ts +0 -13
  54. package/src/index.ts +0 -38
  55. package/src/protocols/DndProtocol.ts +0 -168
  56. package/src/protocols/KeyboardProtocol.ts +0 -181
  57. package/src/protocols/NotificationProtocol.ts +0 -150
  58. package/src/protocols/ResponsiveProtocol.ts +0 -210
  59. package/src/protocols/SharingProtocol.ts +0 -185
  60. package/src/protocols/index.ts +0 -13
  61. package/src/query/__tests__/query-ast.test.ts +0 -211
  62. package/src/query/__tests__/window-functions.test.ts +0 -275
  63. package/src/query/index.ts +0 -7
  64. package/src/query/query-ast.ts +0 -341
  65. package/src/registry/PluginScopeImpl.ts +0 -259
  66. package/src/registry/PluginSystem.ts +0 -206
  67. package/src/registry/Registry.ts +0 -219
  68. package/src/registry/WidgetRegistry.ts +0 -316
  69. package/src/registry/__tests__/PluginSystem.test.ts +0 -309
  70. package/src/registry/__tests__/Registry.test.ts +0 -293
  71. package/src/registry/__tests__/WidgetRegistry.test.ts +0 -321
  72. package/src/registry/__tests__/plugin-scope-integration.test.ts +0 -283
  73. package/src/theme/ThemeEngine.ts +0 -530
  74. package/src/theme/__tests__/ThemeEngine.test.ts +0 -668
  75. package/src/theme/index.ts +0 -24
  76. package/src/types/index.ts +0 -21
  77. package/src/utils/__tests__/debug-collector.test.ts +0 -102
  78. package/src/utils/__tests__/debug.test.ts +0 -134
  79. package/src/utils/__tests__/expand-fields.test.ts +0 -120
  80. package/src/utils/__tests__/extract-records.test.ts +0 -50
  81. package/src/utils/__tests__/filter-converter.test.ts +0 -118
  82. package/src/utils/__tests__/merge-views-into-objects.test.ts +0 -110
  83. package/src/utils/__tests__/normalize-quick-filter.test.ts +0 -123
  84. package/src/utils/debug-collector.ts +0 -100
  85. package/src/utils/debug.ts +0 -148
  86. package/src/utils/expand-fields.ts +0 -76
  87. package/src/utils/extract-records.ts +0 -33
  88. package/src/utils/filter-converter.ts +0 -133
  89. package/src/utils/merge-views-into-objects.ts +0 -36
  90. package/src/utils/normalize-quick-filter.ts +0 -78
  91. package/src/validation/__tests__/object-validation-engine.test.ts +0 -567
  92. package/src/validation/__tests__/schema-validator.test.ts +0 -118
  93. package/src/validation/__tests__/validation-engine.test.ts +0 -102
  94. package/src/validation/index.ts +0 -10
  95. package/src/validation/schema-validator.ts +0 -344
  96. package/src/validation/validation-engine.ts +0 -528
  97. package/src/validation/validators/index.ts +0 -25
  98. package/src/validation/validators/object-validation-engine.ts +0 -722
  99. package/tsconfig.json +0 -15
  100. package/tsconfig.tsbuildinfo +0 -1
  101. package/vitest.config.ts +0 -2
@@ -1,186 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type { DndConfig, DragItem, DropZone, DragConstraint } from '@object-ui/types';
3
- import {
4
- resolveDndConfig,
5
- createDragItemProps,
6
- createDropZoneProps,
7
- resolveDragConstraints,
8
- } from '../../protocols/DndProtocol';
9
-
10
- describe('DndProtocol', () => {
11
- // ==========================================================================
12
- // resolveDndConfig
13
- // ==========================================================================
14
- describe('resolveDndConfig', () => {
15
- it('should apply all defaults for minimal config', () => {
16
- const config = {} as DndConfig;
17
- const resolved = resolveDndConfig(config);
18
-
19
- expect(resolved.enabled).toBe(false);
20
- expect(resolved.sortable).toBe(false);
21
- expect(resolved.autoScroll).toBe(true);
22
- expect(resolved.touchDelay).toBe(200);
23
- expect(resolved.dragItem).toBeUndefined();
24
- expect(resolved.dropZone).toBeUndefined();
25
- });
26
-
27
- it('should preserve explicit values', () => {
28
- const config = {
29
- enabled: true,
30
- sortable: true,
31
- autoScroll: false,
32
- touchDelay: 500,
33
- } as DndConfig;
34
- const resolved = resolveDndConfig(config);
35
-
36
- expect(resolved.enabled).toBe(true);
37
- expect(resolved.sortable).toBe(true);
38
- expect(resolved.autoScroll).toBe(false);
39
- expect(resolved.touchDelay).toBe(500);
40
- });
41
-
42
- it('should pass through dragItem and dropZone', () => {
43
- const dragItem = { type: 'card' } as DragItem;
44
- const dropZone = { accept: ['card'] } as DropZone;
45
- const config = { dragItem, dropZone } as DndConfig;
46
- const resolved = resolveDndConfig(config);
47
-
48
- expect(resolved.dragItem).toBe(dragItem);
49
- expect(resolved.dropZone).toBe(dropZone);
50
- });
51
- });
52
-
53
- // ==========================================================================
54
- // createDragItemProps
55
- // ==========================================================================
56
- describe('createDragItemProps', () => {
57
- it('should return correct props for a basic drag item', () => {
58
- const item = { type: 'card', label: 'Task card' } as DragItem;
59
- const props = createDragItemProps(item);
60
-
61
- expect(props.draggable).toBe(true);
62
- expect(props['aria-roledescription']).toBe('draggable');
63
- expect(props['aria-label']).toBe('Task card');
64
- expect(props.role).toBe('listitem');
65
- expect(props['data-drag-type']).toBe('card');
66
- expect(props['data-drag-handle']).toBe('element');
67
- expect(props['data-drag-disabled']).toBe('false');
68
- });
69
-
70
- it('should set draggable false when disabled', () => {
71
- const item = { type: 'card', disabled: true } as DragItem;
72
- const props = createDragItemProps(item);
73
-
74
- expect(props.draggable).toBe(false);
75
- expect(props['data-drag-disabled']).toBe('true');
76
- });
77
-
78
- it('should use ariaLabel over label when both provided', () => {
79
- const item = { type: 'card', label: 'Label', ariaLabel: 'Aria Label' } as DragItem;
80
- const props = createDragItemProps(item);
81
-
82
- expect(props['aria-label']).toBe('Aria Label');
83
- });
84
-
85
- it('should use ariaLabel when provided as string', () => {
86
- const item = {
87
- type: 'card',
88
- ariaLabel: 'Translated label',
89
- } as unknown as DragItem;
90
- const props = createDragItemProps(item);
91
-
92
- expect(props['aria-label']).toBe('Translated label');
93
- });
94
-
95
- it('should use custom role and handle when provided', () => {
96
- const item = { type: 'row', role: 'option', handle: 'grip' } as DragItem;
97
- const props = createDragItemProps(item);
98
-
99
- expect(props.role).toBe('option');
100
- expect(props['data-drag-handle']).toBe('grip');
101
- });
102
- });
103
-
104
- // ==========================================================================
105
- // createDropZoneProps
106
- // ==========================================================================
107
- describe('createDropZoneProps', () => {
108
- it('should return correct props for a basic drop zone', () => {
109
- const zone = { accept: ['card', 'task'], label: 'Column' } as unknown as DropZone;
110
- const props = createDropZoneProps(zone);
111
-
112
- expect(props['aria-dropeffect']).toBe('move');
113
- expect(props['aria-label']).toBe('Column');
114
- expect(props.role).toBe('list');
115
- expect(props['data-drop-accept']).toBe('card,task');
116
- expect(props['data-drop-highlight']).toBe('true');
117
- });
118
-
119
- it('should use explicit dropEffect and role', () => {
120
- const zone = { accept: ['item'], dropEffect: 'copy', role: 'region' } as unknown as DropZone;
121
- const props = createDropZoneProps(zone);
122
-
123
- expect(props['aria-dropeffect']).toBe('copy');
124
- expect(props.role).toBe('region');
125
- });
126
-
127
- it('should set maxItems when provided', () => {
128
- const zone = { accept: ['card'], maxItems: 10 } as unknown as DropZone;
129
- const props = createDropZoneProps(zone);
130
-
131
- expect(props['data-drop-max-items']).toBe(10);
132
- });
133
-
134
- it('should use ariaLabel string when provided', () => {
135
- const zone = {
136
- accept: ['card'],
137
- ariaLabel: 'Drop here',
138
- } as unknown as DropZone;
139
- const props = createDropZoneProps(zone);
140
-
141
- expect(props['aria-label']).toBe('Drop here');
142
- });
143
- });
144
-
145
- // ==========================================================================
146
- // resolveDragConstraints
147
- // ==========================================================================
148
- describe('resolveDragConstraints', () => {
149
- it('should return base styles for default axis (both)', () => {
150
- const constraint = {} as DragConstraint;
151
- const styles = resolveDragConstraints(constraint);
152
-
153
- expect(styles.position).toBe('relative');
154
- expect(styles.touchAction).toBe('none');
155
- });
156
-
157
- it('should set touchAction to pan-y for x axis', () => {
158
- const constraint = { axis: 'x' } as DragConstraint;
159
- const styles = resolveDragConstraints(constraint);
160
-
161
- expect(styles.touchAction).toBe('pan-y');
162
- });
163
-
164
- it('should set touchAction to pan-x for y axis', () => {
165
- const constraint = { axis: 'y' } as DragConstraint;
166
- const styles = resolveDragConstraints(constraint);
167
-
168
- expect(styles.touchAction).toBe('pan-x');
169
- });
170
-
171
- it('should set overflow hidden for parent bounds', () => {
172
- const constraint = { bounds: 'parent' } as DragConstraint;
173
- const styles = resolveDragConstraints(constraint);
174
-
175
- expect(styles.overflow).toBe('hidden');
176
- });
177
-
178
- it('should set grid CSS custom properties', () => {
179
- const constraint = { grid: [20, 30] } as unknown as DragConstraint;
180
- const styles = resolveDragConstraints(constraint);
181
-
182
- expect(styles['--drag-grid-x']).toBe('20px');
183
- expect(styles['--drag-grid-y']).toBe('30px');
184
- });
185
- });
186
- });
@@ -1,177 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type { KeyboardNavigationConfig, FocusTrapConfig } from '@object-ui/types';
3
- import {
4
- resolveKeyboardConfig,
5
- parseShortcutKey,
6
- matchesShortcut,
7
- createFocusTrapConfig,
8
- } from '../../protocols/KeyboardProtocol';
9
-
10
- describe('KeyboardProtocol', () => {
11
- // ==========================================================================
12
- // resolveKeyboardConfig
13
- // ==========================================================================
14
- describe('resolveKeyboardConfig', () => {
15
- it('should apply defaults for empty config', () => {
16
- const config = {} as KeyboardNavigationConfig;
17
- const resolved = resolveKeyboardConfig(config);
18
-
19
- expect(resolved.shortcuts).toEqual([]);
20
- expect(resolved.rovingTabindex).toBe(false);
21
- expect(resolved.focusManagement.tabOrder).toBe('auto');
22
- expect(resolved.focusManagement.skipLinks).toBe(false);
23
- expect(resolved.focusManagement.focusVisible).toBe(true);
24
- expect(resolved.focusManagement.arrowNavigation).toBe(false);
25
- expect(resolved.focusManagement.focusTrap).toBeUndefined();
26
- });
27
-
28
- it('should resolve ariaLabel from string', () => {
29
- const config = { ariaLabel: 'Navigation' } as KeyboardNavigationConfig;
30
- const resolved = resolveKeyboardConfig(config);
31
-
32
- expect(resolved.ariaLabel).toBe('Navigation');
33
- });
34
-
35
- it('should resolve ariaLabel from string', () => {
36
- const config = {
37
- ariaLabel: 'Nav panel',
38
- } as unknown as KeyboardNavigationConfig;
39
- const resolved = resolveKeyboardConfig(config);
40
-
41
- expect(resolved.ariaLabel).toBe('Nav panel');
42
- });
43
-
44
- it('should preserve explicit values', () => {
45
- const config = {
46
- rovingTabindex: true,
47
- role: 'toolbar',
48
- ariaDescribedBy: 'desc-id',
49
- } as KeyboardNavigationConfig;
50
- const resolved = resolveKeyboardConfig(config);
51
-
52
- expect(resolved.rovingTabindex).toBe(true);
53
- expect(resolved.role).toBe('toolbar');
54
- expect(resolved.ariaDescribedBy).toBe('desc-id');
55
- });
56
- });
57
-
58
- // ==========================================================================
59
- // parseShortcutKey
60
- // ==========================================================================
61
- describe('parseShortcutKey', () => {
62
- it('should parse Ctrl+S', () => {
63
- const parsed = parseShortcutKey('Ctrl+S');
64
-
65
- expect(parsed.key).toBe('s');
66
- expect(parsed.ctrlOrMeta).toBe(true);
67
- expect(parsed.shift).toBe(false);
68
- expect(parsed.alt).toBe(false);
69
- });
70
-
71
- it('should parse Alt+Shift+N', () => {
72
- const parsed = parseShortcutKey('Alt+Shift+N');
73
-
74
- expect(parsed.key).toBe('n');
75
- expect(parsed.ctrlOrMeta).toBe(false);
76
- expect(parsed.shift).toBe(true);
77
- expect(parsed.alt).toBe(true);
78
- });
79
-
80
- it('should parse single key Escape', () => {
81
- const parsed = parseShortcutKey('Escape');
82
-
83
- expect(parsed.key).toBe('escape');
84
- expect(parsed.ctrlOrMeta).toBe(false);
85
- expect(parsed.shift).toBe(false);
86
- expect(parsed.alt).toBe(false);
87
- });
88
-
89
- it('should be case insensitive', () => {
90
- const parsed = parseShortcutKey('ctrl+s');
91
-
92
- expect(parsed.key).toBe('s');
93
- expect(parsed.ctrlOrMeta).toBe(true);
94
- });
95
-
96
- it('should parse single key F1', () => {
97
- const parsed = parseShortcutKey('F1');
98
-
99
- expect(parsed.key).toBe('f1');
100
- expect(parsed.ctrlOrMeta).toBe(false);
101
- expect(parsed.shift).toBe(false);
102
- expect(parsed.alt).toBe(false);
103
- });
104
-
105
- it('should recognise Meta as ctrlOrMeta', () => {
106
- const parsed = parseShortcutKey('Meta+K');
107
-
108
- expect(parsed.ctrlOrMeta).toBe(true);
109
- expect(parsed.key).toBe('k');
110
- });
111
- });
112
-
113
- // ==========================================================================
114
- // matchesShortcut
115
- // ==========================================================================
116
- describe('matchesShortcut', () => {
117
- it('should match Ctrl+S event', () => {
118
- const event = { key: 's', ctrlKey: true };
119
- expect(matchesShortcut(event, 'Ctrl+S')).toBe(true);
120
- });
121
-
122
- it('should match Meta+S event (Cmd on Mac)', () => {
123
- const event = { key: 's', metaKey: true };
124
- expect(matchesShortcut(event, 'Ctrl+S')).toBe(true);
125
- });
126
-
127
- it('should not match when key differs', () => {
128
- const event = { key: 'a', ctrlKey: true };
129
- expect(matchesShortcut(event, 'Ctrl+S')).toBe(false);
130
- });
131
-
132
- it('should not match when modifier is missing', () => {
133
- const event = { key: 's' };
134
- expect(matchesShortcut(event, 'Ctrl+S')).toBe(false);
135
- });
136
-
137
- it('should not match when extra modifier is present', () => {
138
- const event = { key: 's', ctrlKey: true, shiftKey: true };
139
- expect(matchesShortcut(event, 'Ctrl+S')).toBe(false);
140
- });
141
-
142
- it('should match Escape without modifiers', () => {
143
- const event = { key: 'Escape' };
144
- expect(matchesShortcut(event, 'Escape')).toBe(true);
145
- });
146
- });
147
-
148
- // ==========================================================================
149
- // createFocusTrapConfig
150
- // ==========================================================================
151
- describe('createFocusTrapConfig', () => {
152
- it('should apply defaults for minimal config', () => {
153
- const config = {} as FocusTrapConfig;
154
- const resolved = createFocusTrapConfig(config);
155
-
156
- expect(resolved.enabled).toBe(false);
157
- expect(resolved.returnFocus).toBe(true);
158
- expect(resolved.escapeDeactivates).toBe(true);
159
- expect(resolved.initialFocus).toBeUndefined();
160
- });
161
-
162
- it('should preserve explicit values', () => {
163
- const config = {
164
- enabled: true,
165
- initialFocus: '#first-input',
166
- returnFocus: false,
167
- escapeDeactivates: false,
168
- } as FocusTrapConfig;
169
- const resolved = createFocusTrapConfig(config);
170
-
171
- expect(resolved.enabled).toBe(true);
172
- expect(resolved.initialFocus).toBe('#first-input');
173
- expect(resolved.returnFocus).toBe(false);
174
- expect(resolved.escapeDeactivates).toBe(false);
175
- });
176
- });
177
- });
@@ -1,142 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type {
3
- Notification as SpecNotification,
4
- NotificationConfig,
5
- } from '@object-ui/types';
6
- import {
7
- specNotificationToToast,
8
- mapSeverityToVariant,
9
- mapPosition,
10
- resolveNotificationConfig,
11
- } from '../../protocols/NotificationProtocol';
12
-
13
- describe('NotificationProtocol', () => {
14
- // ==========================================================================
15
- // mapSeverityToVariant
16
- // ==========================================================================
17
- describe('mapSeverityToVariant', () => {
18
- it.each([
19
- ['info', 'default'],
20
- ['success', 'success'],
21
- ['warning', 'warning'],
22
- ['error', 'destructive'],
23
- ] as const)('should map "%s" to "%s"', (severity, expected) => {
24
- expect(mapSeverityToVariant(severity)).toBe(expected);
25
- });
26
-
27
- it('should fall back to "default" for unknown severity', () => {
28
- expect(mapSeverityToVariant('critical')).toBe('default');
29
- });
30
- });
31
-
32
- // ==========================================================================
33
- // mapPosition
34
- // ==========================================================================
35
- describe('mapPosition', () => {
36
- it.each([
37
- ['top_left', 'top-left'],
38
- ['top_center', 'top-center'],
39
- ['top_right', 'top-right'],
40
- ['bottom_left', 'bottom-left'],
41
- ['bottom_center', 'bottom-center'],
42
- ['bottom_right', 'bottom-right'],
43
- ] as const)('should map "%s" to "%s"', (spec, expected) => {
44
- expect(mapPosition(spec)).toBe(expected);
45
- });
46
-
47
- it('should fall back to "top-right" for unknown position', () => {
48
- expect(mapPosition('center')).toBe('top-right');
49
- });
50
- });
51
-
52
- // ==========================================================================
53
- // resolveNotificationConfig
54
- // ==========================================================================
55
- describe('resolveNotificationConfig', () => {
56
- it('should apply all defaults for empty config', () => {
57
- const config = {} as NotificationConfig;
58
- const resolved = resolveNotificationConfig(config);
59
-
60
- expect(resolved.defaultPosition).toBe('top_right');
61
- expect(resolved.defaultDuration).toBe(5000);
62
- expect(resolved.maxVisible).toBe(5);
63
- expect(resolved.stackDirection).toBe('down');
64
- expect(resolved.pauseOnHover).toBe(true);
65
- });
66
-
67
- it('should preserve explicit values', () => {
68
- const config = {
69
- defaultPosition: 'bottom_left',
70
- defaultDuration: 3000,
71
- maxVisible: 3,
72
- stackDirection: 'up',
73
- pauseOnHover: false,
74
- } as NotificationConfig;
75
- const resolved = resolveNotificationConfig(config);
76
-
77
- expect(resolved.defaultPosition).toBe('bottom_left');
78
- expect(resolved.defaultDuration).toBe(3000);
79
- expect(resolved.maxVisible).toBe(3);
80
- expect(resolved.stackDirection).toBe('up');
81
- expect(resolved.pauseOnHover).toBe(false);
82
- });
83
- });
84
-
85
- // ==========================================================================
86
- // specNotificationToToast
87
- // ==========================================================================
88
- describe('specNotificationToToast', () => {
89
- it('should convert a basic notification to toast', () => {
90
- const notification = {
91
- message: 'Record saved',
92
- severity: 'success',
93
- } as SpecNotification;
94
- const toast = specNotificationToToast(notification);
95
-
96
- expect(toast.description).toBe('Record saved');
97
- expect(toast.variant).toBe('success');
98
- expect(toast.position).toBe('top-right');
99
- expect(toast.duration).toBe(5000);
100
- expect(toast.dismissible).toBe(true);
101
- expect(toast.actions).toEqual([]);
102
- });
103
-
104
- it('should handle string title and message', () => {
105
- const notification = {
106
- title: 'Heads up',
107
- message: 'Something happened',
108
- } as unknown as SpecNotification;
109
- const toast = specNotificationToToast(notification);
110
-
111
- expect(toast.title).toBe('Heads up');
112
- expect(toast.description).toBe('Something happened');
113
- });
114
-
115
- it('should map actions to toast actions', () => {
116
- const notification = {
117
- message: 'Error occurred',
118
- severity: 'error',
119
- actions: [
120
- { label: 'Retry', action: 'retry', variant: 'primary' },
121
- { label: 'Dismiss', action: 'dismiss', variant: 'secondary' },
122
- ],
123
- } as unknown as SpecNotification;
124
- const toast = specNotificationToToast(notification);
125
-
126
- expect(toast.actions).toHaveLength(2);
127
- expect(toast.actions[0]).toEqual({ label: 'Retry', action: 'retry', variant: 'primary' });
128
- expect(toast.actions[1]).toEqual({ label: 'Dismiss', action: 'dismiss', variant: 'secondary' });
129
- });
130
-
131
- it('should apply defaults for missing fields', () => {
132
- const notification = {} as SpecNotification;
133
- const toast = specNotificationToToast(notification);
134
-
135
- expect(toast.description).toBe('');
136
- expect(toast.variant).toBe('default');
137
- expect(toast.position).toBe('top-right');
138
- expect(toast.duration).toBe(5000);
139
- expect(toast.dismissible).toBe(true);
140
- });
141
- });
142
- });
@@ -1,176 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type { SpecResponsiveConfig } from '@object-ui/types';
3
- import {
4
- getVisibilityClasses,
5
- getColumnClasses,
6
- getOrderClasses,
7
- shouldHideAtBreakpoint,
8
- resolveResponsiveConfig,
9
- BREAKPOINT_VALUES,
10
- } from '../../protocols/ResponsiveProtocol';
11
-
12
- describe('ResponsiveProtocol', () => {
13
- // ==========================================================================
14
- // BREAKPOINT_VALUES
15
- // ==========================================================================
16
- describe('BREAKPOINT_VALUES', () => {
17
- it('should export correct pixel values for all breakpoints', () => {
18
- expect(BREAKPOINT_VALUES.xs).toBe(0);
19
- expect(BREAKPOINT_VALUES.sm).toBe(640);
20
- expect(BREAKPOINT_VALUES.md).toBe(768);
21
- expect(BREAKPOINT_VALUES.lg).toBe(1024);
22
- expect(BREAKPOINT_VALUES.xl).toBe(1280);
23
- expect(BREAKPOINT_VALUES['2xl']).toBe(1536);
24
- });
25
- });
26
-
27
- // ==========================================================================
28
- // resolveResponsiveConfig
29
- // ==========================================================================
30
- describe('resolveResponsiveConfig', () => {
31
- it('should apply defaults for empty config', () => {
32
- const config = {} as SpecResponsiveConfig;
33
- const resolved = resolveResponsiveConfig(config);
34
-
35
- expect(resolved.breakpoint).toBeUndefined();
36
- expect(resolved.hiddenOn).toEqual([]);
37
- expect(resolved.columns).toEqual({});
38
- expect(resolved.order).toEqual({});
39
- });
40
-
41
- it('should preserve explicit values', () => {
42
- const config = {
43
- breakpoint: 'md',
44
- hiddenOn: ['sm'],
45
- columns: { xs: 1, md: 2 },
46
- order: { xs: 2, md: 1 },
47
- } as SpecResponsiveConfig;
48
- const resolved = resolveResponsiveConfig(config);
49
-
50
- expect(resolved.breakpoint).toBe('md');
51
- expect(resolved.hiddenOn).toEqual(['sm']);
52
- expect(resolved.columns).toEqual({ xs: 1, md: 2 });
53
- expect(resolved.order).toEqual({ xs: 2, md: 1 });
54
- });
55
- });
56
-
57
- // ==========================================================================
58
- // getVisibilityClasses
59
- // ==========================================================================
60
- describe('getVisibilityClasses', () => {
61
- it('should return empty array for no visibility config', () => {
62
- const config = {} as SpecResponsiveConfig;
63
- expect(getVisibilityClasses(config)).toEqual([]);
64
- });
65
-
66
- it('should return hidden + breakpoint:block for minimum breakpoint', () => {
67
- const config = { breakpoint: 'md' } as SpecResponsiveConfig;
68
- const classes = getVisibilityClasses(config);
69
-
70
- expect(classes).toContain('hidden');
71
- expect(classes).toContain('md:block');
72
- });
73
-
74
- it('should not add hidden class for xs breakpoint', () => {
75
- const config = { breakpoint: 'xs' } as SpecResponsiveConfig;
76
- const classes = getVisibilityClasses(config);
77
-
78
- expect(classes).not.toContain('hidden');
79
- });
80
-
81
- it('should generate toggle classes for hiddenOn', () => {
82
- const config = { hiddenOn: ['sm'] } as SpecResponsiveConfig;
83
- const classes = getVisibilityClasses(config);
84
-
85
- expect(classes).toContain('sm:hidden');
86
- expect(classes).toContain('md:block');
87
- });
88
-
89
- it('should handle hiddenOn at xs breakpoint', () => {
90
- const config = { hiddenOn: ['xs'] } as SpecResponsiveConfig;
91
- const classes = getVisibilityClasses(config);
92
-
93
- expect(classes).toContain('hidden');
94
- expect(classes).toContain('sm:block');
95
- });
96
- });
97
-
98
- // ==========================================================================
99
- // getColumnClasses
100
- // ==========================================================================
101
- describe('getColumnClasses', () => {
102
- it('should return empty array when no columns set', () => {
103
- const config = {} as SpecResponsiveConfig;
104
- expect(getColumnClasses(config)).toEqual([]);
105
- });
106
-
107
- it('should return grid-cols classes for each breakpoint', () => {
108
- const config = {
109
- columns: { xs: 1, md: 2, xl: 4 },
110
- } as SpecResponsiveConfig;
111
- const classes = getColumnClasses(config);
112
-
113
- expect(classes).toContain('grid-cols-1');
114
- expect(classes).toContain('md:grid-cols-2');
115
- expect(classes).toContain('xl:grid-cols-4');
116
- });
117
-
118
- it('should omit prefix for xs breakpoint', () => {
119
- const config = { columns: { xs: 3 } } as SpecResponsiveConfig;
120
- const classes = getColumnClasses(config);
121
-
122
- expect(classes).toEqual(['grid-cols-3']);
123
- });
124
- });
125
-
126
- // ==========================================================================
127
- // getOrderClasses
128
- // ==========================================================================
129
- describe('getOrderClasses', () => {
130
- it('should return empty array when no order set', () => {
131
- const config = {} as SpecResponsiveConfig;
132
- expect(getOrderClasses(config)).toEqual([]);
133
- });
134
-
135
- it('should return order classes for each breakpoint', () => {
136
- const config = {
137
- order: { xs: 2, lg: 1 },
138
- } as SpecResponsiveConfig;
139
- const classes = getOrderClasses(config);
140
-
141
- expect(classes).toContain('order-2');
142
- expect(classes).toContain('lg:order-1');
143
- });
144
- });
145
-
146
- // ==========================================================================
147
- // shouldHideAtBreakpoint
148
- // ==========================================================================
149
- describe('shouldHideAtBreakpoint', () => {
150
- it('should hide below minimum breakpoint', () => {
151
- const config = { breakpoint: 'md' } as SpecResponsiveConfig;
152
-
153
- expect(shouldHideAtBreakpoint(config, 600)).toBe(true); // below 768
154
- expect(shouldHideAtBreakpoint(config, 768)).toBe(false); // at 768
155
- expect(shouldHideAtBreakpoint(config, 1024)).toBe(false); // above 768
156
- });
157
-
158
- it('should hide at breakpoints in hiddenOn list', () => {
159
- const config = { hiddenOn: ['sm', 'lg'] } as SpecResponsiveConfig;
160
-
161
- expect(shouldHideAtBreakpoint(config, 700)).toBe(true); // sm range
162
- expect(shouldHideAtBreakpoint(config, 800)).toBe(false); // md range
163
- expect(shouldHideAtBreakpoint(config, 1100)).toBe(true); // lg range
164
- });
165
-
166
- it('should return false when no config constraints', () => {
167
- const config = {} as SpecResponsiveConfig;
168
- expect(shouldHideAtBreakpoint(config, 500)).toBe(false);
169
- });
170
-
171
- it('should not hide at xs width when no constraints', () => {
172
- const config = {} as SpecResponsiveConfig;
173
- expect(shouldHideAtBreakpoint(config, 0)).toBe(false);
174
- });
175
- });
176
- });