@object-ui/core 3.3.0 → 3.3.1

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 (99) hide show
  1. package/CHANGELOG.md +6 -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/utils/filter-converter.js +25 -5
  7. package/package.json +32 -8
  8. package/.turbo/turbo-build.log +0 -4
  9. package/src/__benchmarks__/core.bench.ts +0 -64
  10. package/src/__tests__/protocols/DndProtocol.test.ts +0 -186
  11. package/src/__tests__/protocols/KeyboardProtocol.test.ts +0 -177
  12. package/src/__tests__/protocols/NotificationProtocol.test.ts +0 -142
  13. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +0 -176
  14. package/src/__tests__/protocols/SharingProtocol.test.ts +0 -188
  15. package/src/actions/ActionEngine.ts +0 -268
  16. package/src/actions/ActionRunner.ts +0 -717
  17. package/src/actions/TransactionManager.ts +0 -521
  18. package/src/actions/UndoManager.ts +0 -215
  19. package/src/actions/__tests__/ActionEngine.test.ts +0 -206
  20. package/src/actions/__tests__/ActionRunner.params.test.ts +0 -134
  21. package/src/actions/__tests__/ActionRunner.test.ts +0 -711
  22. package/src/actions/__tests__/TransactionManager.test.ts +0 -447
  23. package/src/actions/__tests__/UndoManager.test.ts +0 -320
  24. package/src/actions/index.ts +0 -12
  25. package/src/adapters/ApiDataSource.ts +0 -376
  26. package/src/adapters/README.md +0 -180
  27. package/src/adapters/ValueDataSource.ts +0 -459
  28. package/src/adapters/__tests__/ApiDataSource.test.ts +0 -418
  29. package/src/adapters/__tests__/ValueDataSource.test.ts +0 -571
  30. package/src/adapters/__tests__/resolveDataSource.test.ts +0 -144
  31. package/src/adapters/index.ts +0 -15
  32. package/src/adapters/resolveDataSource.ts +0 -79
  33. package/src/builder/__tests__/schema-builder.test.ts +0 -235
  34. package/src/builder/schema-builder.ts +0 -584
  35. package/src/data-scope/DataScopeManager.ts +0 -269
  36. package/src/data-scope/ViewDataProvider.ts +0 -282
  37. package/src/data-scope/__tests__/DataScopeManager.test.ts +0 -211
  38. package/src/data-scope/__tests__/ViewDataProvider.test.ts +0 -270
  39. package/src/data-scope/index.ts +0 -24
  40. package/src/errors/__tests__/errors.test.ts +0 -292
  41. package/src/errors/index.ts +0 -269
  42. package/src/evaluator/ExpressionCache.ts +0 -206
  43. package/src/evaluator/ExpressionContext.ts +0 -118
  44. package/src/evaluator/ExpressionEvaluator.ts +0 -315
  45. package/src/evaluator/FormulaFunctions.ts +0 -398
  46. package/src/evaluator/SafeExpressionParser.ts +0 -893
  47. package/src/evaluator/__tests__/ExpressionCache.test.ts +0 -135
  48. package/src/evaluator/__tests__/ExpressionContext.test.ts +0 -110
  49. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +0 -558
  50. package/src/evaluator/__tests__/FormulaFunctions.test.ts +0 -447
  51. package/src/evaluator/index.ts +0 -13
  52. package/src/index.ts +0 -38
  53. package/src/protocols/DndProtocol.ts +0 -168
  54. package/src/protocols/KeyboardProtocol.ts +0 -181
  55. package/src/protocols/NotificationProtocol.ts +0 -150
  56. package/src/protocols/ResponsiveProtocol.ts +0 -210
  57. package/src/protocols/SharingProtocol.ts +0 -185
  58. package/src/protocols/index.ts +0 -13
  59. package/src/query/__tests__/query-ast.test.ts +0 -211
  60. package/src/query/__tests__/window-functions.test.ts +0 -275
  61. package/src/query/index.ts +0 -7
  62. package/src/query/query-ast.ts +0 -341
  63. package/src/registry/PluginScopeImpl.ts +0 -259
  64. package/src/registry/PluginSystem.ts +0 -206
  65. package/src/registry/Registry.ts +0 -219
  66. package/src/registry/WidgetRegistry.ts +0 -316
  67. package/src/registry/__tests__/PluginSystem.test.ts +0 -309
  68. package/src/registry/__tests__/Registry.test.ts +0 -293
  69. package/src/registry/__tests__/WidgetRegistry.test.ts +0 -321
  70. package/src/registry/__tests__/plugin-scope-integration.test.ts +0 -283
  71. package/src/theme/ThemeEngine.ts +0 -530
  72. package/src/theme/__tests__/ThemeEngine.test.ts +0 -668
  73. package/src/theme/index.ts +0 -24
  74. package/src/types/index.ts +0 -21
  75. package/src/utils/__tests__/debug-collector.test.ts +0 -102
  76. package/src/utils/__tests__/debug.test.ts +0 -134
  77. package/src/utils/__tests__/expand-fields.test.ts +0 -120
  78. package/src/utils/__tests__/extract-records.test.ts +0 -50
  79. package/src/utils/__tests__/filter-converter.test.ts +0 -118
  80. package/src/utils/__tests__/merge-views-into-objects.test.ts +0 -110
  81. package/src/utils/__tests__/normalize-quick-filter.test.ts +0 -123
  82. package/src/utils/debug-collector.ts +0 -100
  83. package/src/utils/debug.ts +0 -148
  84. package/src/utils/expand-fields.ts +0 -76
  85. package/src/utils/extract-records.ts +0 -33
  86. package/src/utils/filter-converter.ts +0 -133
  87. package/src/utils/merge-views-into-objects.ts +0 -36
  88. package/src/utils/normalize-quick-filter.ts +0 -78
  89. package/src/validation/__tests__/object-validation-engine.test.ts +0 -567
  90. package/src/validation/__tests__/schema-validator.test.ts +0 -118
  91. package/src/validation/__tests__/validation-engine.test.ts +0 -102
  92. package/src/validation/index.ts +0 -10
  93. package/src/validation/schema-validator.ts +0 -344
  94. package/src/validation/validation-engine.ts +0 -528
  95. package/src/validation/validators/index.ts +0 -25
  96. package/src/validation/validators/object-validation-engine.ts +0 -722
  97. package/tsconfig.json +0 -15
  98. package/tsconfig.tsbuildinfo +0 -1
  99. package/vitest.config.ts +0 -2
@@ -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
- });
@@ -1,188 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type { SharingConfig, EmbedConfig } from '@object-ui/types';
3
- import {
4
- resolveSharingConfig,
5
- resolveEmbedConfig,
6
- generateEmbedCode,
7
- validateSharingConfig,
8
- } from '../../protocols/SharingProtocol';
9
-
10
- describe('SharingProtocol', () => {
11
- // ==========================================================================
12
- // resolveSharingConfig
13
- // ==========================================================================
14
- describe('resolveSharingConfig', () => {
15
- it('should apply defaults for empty config', () => {
16
- const resolved = resolveSharingConfig({});
17
-
18
- expect(resolved.enabled).toBe(false);
19
- expect(resolved.allowedDomains).toEqual([]);
20
- expect(resolved.allowAnonymous).toBe(false);
21
- expect(resolved.publicLink).toBeUndefined();
22
- expect(resolved.password).toBeUndefined();
23
- expect(resolved.expiresAt).toBeUndefined();
24
- });
25
-
26
- it('should preserve explicit values', () => {
27
- const config: Partial<SharingConfig> = {
28
- enabled: true,
29
- publicLink: 'https://example.com/share/abc',
30
- password: 'secret',
31
- allowedDomains: ['example.com'],
32
- expiresAt: '2025-12-31T00:00:00Z',
33
- allowAnonymous: true,
34
- };
35
- const resolved = resolveSharingConfig(config);
36
-
37
- expect(resolved.enabled).toBe(true);
38
- expect(resolved.publicLink).toBe('https://example.com/share/abc');
39
- expect(resolved.password).toBe('secret');
40
- expect(resolved.allowedDomains).toEqual(['example.com']);
41
- expect(resolved.expiresAt).toBe('2025-12-31T00:00:00Z');
42
- expect(resolved.allowAnonymous).toBe(true);
43
- });
44
- });
45
-
46
- // ==========================================================================
47
- // resolveEmbedConfig
48
- // ==========================================================================
49
- describe('resolveEmbedConfig', () => {
50
- it('should apply defaults for empty config', () => {
51
- const resolved = resolveEmbedConfig({});
52
-
53
- expect(resolved.enabled).toBe(false);
54
- expect(resolved.allowedOrigins).toEqual([]);
55
- expect(resolved.width).toBe('100%');
56
- expect(resolved.height).toBe('600px');
57
- expect(resolved.showHeader).toBe(true);
58
- expect(resolved.showNavigation).toBe(false);
59
- expect(resolved.responsive).toBe(true);
60
- });
61
-
62
- it('should preserve explicit values', () => {
63
- const config: Partial<EmbedConfig> = {
64
- enabled: true,
65
- width: '800px',
66
- height: '400px',
67
- showHeader: false,
68
- responsive: false,
69
- };
70
- const resolved = resolveEmbedConfig(config);
71
-
72
- expect(resolved.enabled).toBe(true);
73
- expect(resolved.width).toBe('800px');
74
- expect(resolved.height).toBe('400px');
75
- expect(resolved.showHeader).toBe(false);
76
- expect(resolved.responsive).toBe(false);
77
- });
78
- });
79
-
80
- // ==========================================================================
81
- // generateEmbedCode
82
- // ==========================================================================
83
- describe('generateEmbedCode', () => {
84
- it('should return valid iframe HTML', () => {
85
- const config = {} as EmbedConfig;
86
- const html = generateEmbedCode(config, 'https://app.example.com/view/123');
87
-
88
- expect(html).toContain('<iframe');
89
- expect(html).toContain('</iframe>');
90
- expect(html).toContain('src="https://app.example.com/view/123"');
91
- expect(html).toContain('width="100%"');
92
- expect(html).toContain('height="600px"');
93
- expect(html).toContain('allowfullscreen');
94
- });
95
-
96
- it('should include responsive style when responsive is true', () => {
97
- const config = { responsive: true } as EmbedConfig;
98
- const html = generateEmbedCode(config, 'https://example.com');
99
-
100
- expect(html).toContain('max-width: 100%');
101
- });
102
-
103
- it('should not include max-width when responsive is false', () => {
104
- const config = { responsive: false } as EmbedConfig;
105
- const html = generateEmbedCode(config, 'https://example.com');
106
-
107
- expect(html).not.toContain('max-width');
108
- });
109
-
110
- it('should HTML-escape URLs to prevent XSS', () => {
111
- const config = {} as EmbedConfig;
112
- const maliciousUrl = 'https://example.com/"><script>alert("xss")</script>';
113
- const html = generateEmbedCode(config, maliciousUrl);
114
-
115
- expect(html).not.toContain('<script>');
116
- expect(html).toContain('&lt;script&gt;');
117
- expect(html).toContain('&quot;');
118
- });
119
- });
120
-
121
- // ==========================================================================
122
- // validateSharingConfig
123
- // ==========================================================================
124
- describe('validateSharingConfig', () => {
125
- it('should return valid for a well-formed config', () => {
126
- const config = {
127
- enabled: true,
128
- publicLink: 'https://example.com/share/abc',
129
- allowedDomains: ['example.com'],
130
- } as SharingConfig;
131
- const result = validateSharingConfig(config);
132
-
133
- expect(result.valid).toBe(true);
134
- expect(result.errors).toEqual([]);
135
- });
136
-
137
- it('should error when enabled without publicLink', () => {
138
- const config = { enabled: true } as SharingConfig;
139
- const result = validateSharingConfig(config);
140
-
141
- expect(result.valid).toBe(false);
142
- expect(result.errors).toContain('A public link is required when sharing is enabled.');
143
- });
144
-
145
- it('should error for invalid expiresAt date', () => {
146
- const config = {
147
- enabled: false,
148
- expiresAt: 'not-a-date',
149
- } as SharingConfig;
150
- const result = validateSharingConfig(config);
151
-
152
- expect(result.valid).toBe(false);
153
- expect(result.errors).toContain('expiresAt must be a valid ISO 8601 date string.');
154
- });
155
-
156
- it('should error for empty password string', () => {
157
- const config = {
158
- enabled: false,
159
- password: '',
160
- } as SharingConfig;
161
- const result = validateSharingConfig(config);
162
-
163
- expect(result.valid).toBe(false);
164
- expect(result.errors).toContain('Password must not be an empty string when provided.');
165
- });
166
-
167
- it('should error for empty domain entries', () => {
168
- const config = {
169
- enabled: false,
170
- allowedDomains: ['example.com', ' '],
171
- } as SharingConfig;
172
- const result = validateSharingConfig(config);
173
-
174
- expect(result.valid).toBe(false);
175
- expect(result.errors).toContain(
176
- 'allowedDomains contains an empty or whitespace-only entry.'
177
- );
178
- });
179
-
180
- it('should return valid for disabled config with no issues', () => {
181
- const config = { enabled: false } as SharingConfig;
182
- const result = validateSharingConfig(config);
183
-
184
- expect(result.valid).toBe(true);
185
- expect(result.errors).toEqual([]);
186
- });
187
- });
188
- });