@object-ui/core 3.0.2 → 3.1.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 +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/actions/ActionEngine.d.ts +98 -0
- package/dist/actions/ActionEngine.js +222 -0
- package/dist/actions/UndoManager.d.ts +80 -0
- package/dist/actions/UndoManager.js +193 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +2 -0
- package/dist/adapters/ApiDataSource.d.ts +2 -1
- package/dist/adapters/ApiDataSource.js +25 -0
- package/dist/adapters/ValueDataSource.d.ts +2 -1
- package/dist/adapters/ValueDataSource.js +99 -3
- package/dist/data-scope/ViewDataProvider.d.ts +143 -0
- package/dist/data-scope/ViewDataProvider.js +153 -0
- package/dist/data-scope/index.d.ts +1 -0
- package/dist/data-scope/index.js +1 -0
- package/dist/evaluator/ExpressionEvaluator.d.ts +7 -0
- package/dist/evaluator/ExpressionEvaluator.js +19 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/protocols/DndProtocol.d.ts +84 -0
- package/dist/protocols/DndProtocol.js +113 -0
- package/dist/protocols/KeyboardProtocol.d.ts +93 -0
- package/dist/protocols/KeyboardProtocol.js +108 -0
- package/dist/protocols/NotificationProtocol.d.ts +71 -0
- package/dist/protocols/NotificationProtocol.js +99 -0
- package/dist/protocols/ResponsiveProtocol.d.ts +73 -0
- package/dist/protocols/ResponsiveProtocol.js +158 -0
- package/dist/protocols/SharingProtocol.d.ts +71 -0
- package/dist/protocols/SharingProtocol.js +124 -0
- package/dist/protocols/index.d.ts +12 -0
- package/dist/protocols/index.js +12 -0
- package/dist/utils/debug-collector.d.ts +59 -0
- package/dist/utils/debug-collector.js +73 -0
- package/dist/utils/debug.d.ts +37 -2
- package/dist/utils/debug.js +62 -3
- package/dist/utils/expand-fields.d.ts +40 -0
- package/dist/utils/expand-fields.js +68 -0
- package/dist/utils/extract-records.d.ts +16 -0
- package/dist/utils/extract-records.js +32 -0
- package/dist/utils/normalize-quick-filter.d.ts +29 -0
- package/dist/utils/normalize-quick-filter.js +66 -0
- package/package.json +3 -3
- package/src/__tests__/protocols/DndProtocol.test.ts +186 -0
- package/src/__tests__/protocols/KeyboardProtocol.test.ts +177 -0
- package/src/__tests__/protocols/NotificationProtocol.test.ts +142 -0
- package/src/__tests__/protocols/ResponsiveProtocol.test.ts +176 -0
- package/src/__tests__/protocols/SharingProtocol.test.ts +188 -0
- package/src/actions/ActionEngine.ts +268 -0
- package/src/actions/UndoManager.ts +215 -0
- package/src/actions/__tests__/ActionEngine.test.ts +206 -0
- package/src/actions/__tests__/UndoManager.test.ts +320 -0
- package/src/actions/index.ts +2 -0
- package/src/adapters/ApiDataSource.ts +27 -0
- package/src/adapters/ValueDataSource.ts +109 -3
- package/src/adapters/__tests__/ValueDataSource.test.ts +147 -0
- package/src/data-scope/ViewDataProvider.ts +282 -0
- package/src/data-scope/__tests__/ViewDataProvider.test.ts +270 -0
- package/src/data-scope/index.ts +8 -0
- package/src/evaluator/ExpressionEvaluator.ts +22 -0
- package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +31 -1
- package/src/index.ts +5 -0
- package/src/protocols/DndProtocol.ts +184 -0
- package/src/protocols/KeyboardProtocol.ts +185 -0
- package/src/protocols/NotificationProtocol.ts +159 -0
- package/src/protocols/ResponsiveProtocol.ts +210 -0
- package/src/protocols/SharingProtocol.ts +185 -0
- package/src/{index.test.ts → protocols/index.ts} +5 -7
- package/src/utils/__tests__/debug-collector.test.ts +102 -0
- package/src/utils/__tests__/debug.test.ts +52 -1
- package/src/utils/__tests__/expand-fields.test.ts +120 -0
- package/src/utils/__tests__/extract-records.test.ts +50 -0
- package/src/utils/__tests__/normalize-quick-filter.test.ts +123 -0
- package/src/utils/debug-collector.ts +100 -0
- package/src/utils/debug.ts +87 -6
- package/src/utils/expand-fields.ts +76 -0
- package/src/utils/extract-records.ts +33 -0
- package/src/utils/normalize-quick-filter.ts +78 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
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 translation objects for title and message', () => {
|
|
105
|
+
const notification = {
|
|
106
|
+
title: { key: 'notify.title', defaultValue: 'Heads up' },
|
|
107
|
+
message: { key: 'notify.msg', defaultValue: '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
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
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('<script>');
|
|
117
|
+
expect(html).toContain('"');
|
|
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
|
+
});
|