@rangka/client 0.1.1 → 0.1.3
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/dist/App.d.ts.map +1 -1
- package/dist/App.js +7 -1
- package/dist/App.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +20 -0
- package/dist/main.js.map +1 -1
- package/dist/shell/assets/index-63v1sBS3.css +1 -0
- package/dist/shell/assets/index-Dh7K40cQ.js +8634 -0
- package/dist/shell/assets/vendor-query-B2cydN5j.js +1 -0
- package/dist/shell/assets/vendor-radix-BJxYPxPb.js +69 -0
- package/dist/shell/assets/vendor-router-ET_myMt5.js +17 -0
- package/dist/shell/index.html +5 -2
- package/dist/theme.css +82 -0
- package/dist/widgets/components/lazy-manifest.d.ts +11 -0
- package/dist/widgets/components/lazy-manifest.d.ts.map +1 -0
- package/dist/widgets/components/lazy-manifest.js +32 -0
- package/dist/widgets/components/lazy-manifest.js.map +1 -0
- package/dist/widgets/components/register.js +12 -12
- package/dist/widgets/components/register.js.map +1 -1
- package/dist/widgets/loader.d.ts +3 -0
- package/dist/widgets/loader.d.ts.map +1 -0
- package/dist/widgets/loader.js +73 -0
- package/dist/widgets/loader.js.map +1 -0
- package/dist/widgets/renderer/LazyWidget.d.ts +8 -0
- package/dist/widgets/renderer/LazyWidget.d.ts.map +1 -0
- package/dist/widgets/renderer/LazyWidget.js +31 -0
- package/dist/widgets/renderer/LazyWidget.js.map +1 -0
- package/dist/widgets/renderer/WidgetErrorBoundary.d.ts +17 -0
- package/dist/widgets/renderer/WidgetErrorBoundary.d.ts.map +1 -0
- package/dist/widgets/renderer/WidgetErrorBoundary.js +18 -0
- package/dist/widgets/renderer/WidgetErrorBoundary.js.map +1 -0
- package/dist/widgets/renderer/WidgetRenderer.d.ts.map +1 -1
- package/dist/widgets/renderer/WidgetRenderer.js +8 -6
- package/dist/widgets/renderer/WidgetRenderer.js.map +1 -1
- package/package.json +7 -4
- package/.claude/skills/add-widget/SKILL.md +0 -101
- package/.turbo/turbo-build.log +0 -29
- package/CHANGELOG.md +0 -25
- package/CLAUDE.md +0 -236
- package/components.json +0 -25
- package/dist/components/ui/chart.d.ts +0 -45
- package/dist/components/ui/chart.d.ts.map +0 -1
- package/dist/components/ui/chart.js +0 -119
- package/dist/components/ui/chart.js.map +0 -1
- package/dist/shell/assets/index--35CAvcP.js +0 -8715
- package/dist/shell/assets/index-COLmoPYo.css +0 -1
- package/index.html +0 -12
- package/src/App.tsx +0 -44
- package/src/__tests__/setup.ts +0 -1
- package/src/api/auth.ts +0 -41
- package/src/api/boot.ts +0 -10
- package/src/api/client.ts +0 -26
- package/src/api/paths.ts +0 -3
- package/src/api/token.ts +0 -13
- package/src/auth/LoginForm.tsx +0 -67
- package/src/auth/SessionExpired.tsx +0 -24
- package/src/auth/SetupForm.tsx +0 -76
- package/src/boot/BootGate.tsx +0 -35
- package/src/boot/BootProvider.tsx +0 -28
- package/src/boot/types.ts +0 -9
- package/src/boot/useBoot.ts +0 -111
- package/src/components/Icon.tsx +0 -17
- package/src/components/ui/accordion.tsx +0 -82
- package/src/components/ui/alert-dialog.tsx +0 -180
- package/src/components/ui/alert.tsx +0 -76
- package/src/components/ui/aspect-ratio.tsx +0 -9
- package/src/components/ui/avatar.tsx +0 -94
- package/src/components/ui/badge.tsx +0 -45
- package/src/components/ui/breadcrumb.tsx +0 -104
- package/src/components/ui/button-group.tsx +0 -78
- package/src/components/ui/button.tsx +0 -65
- package/src/components/ui/calendar.tsx +0 -187
- package/src/components/ui/card.tsx +0 -85
- package/src/components/ui/carousel.tsx +0 -229
- package/src/components/ui/chart.tsx +0 -339
- package/src/components/ui/checkbox.tsx +0 -27
- package/src/components/ui/collapsible.tsx +0 -21
- package/src/components/ui/combobox.tsx +0 -275
- package/src/components/ui/command.tsx +0 -178
- package/src/components/ui/context-menu.tsx +0 -242
- package/src/components/ui/dialog.tsx +0 -146
- package/src/components/ui/direction.tsx +0 -20
- package/src/components/ui/drawer.tsx +0 -118
- package/src/components/ui/dropdown-menu.tsx +0 -247
- package/src/components/ui/empty.tsx +0 -94
- package/src/components/ui/field.tsx +0 -224
- package/src/components/ui/hover-card.tsx +0 -36
- package/src/components/ui/input-group.tsx +0 -142
- package/src/components/ui/input-otp.tsx +0 -86
- package/src/components/ui/input.tsx +0 -19
- package/src/components/ui/item.tsx +0 -182
- package/src/components/ui/kbd.tsx +0 -26
- package/src/components/ui/label.tsx +0 -19
- package/src/components/ui/menubar.tsx +0 -260
- package/src/components/ui/native-select.tsx +0 -55
- package/src/components/ui/navigation-menu.tsx +0 -160
- package/src/components/ui/pagination.tsx +0 -112
- package/src/components/ui/popover.tsx +0 -74
- package/src/components/ui/progress.tsx +0 -31
- package/src/components/ui/radio-group.tsx +0 -42
- package/src/components/ui/resizable.tsx +0 -42
- package/src/components/ui/scroll-area.tsx +0 -53
- package/src/components/ui/select.tsx +0 -185
- package/src/components/ui/separator.tsx +0 -26
- package/src/components/ui/sheet.tsx +0 -128
- package/src/components/ui/sidebar.tsx +0 -669
- package/src/components/ui/skeleton.tsx +0 -13
- package/src/components/ui/slider.tsx +0 -54
- package/src/components/ui/sonner.tsx +0 -43
- package/src/components/ui/spinner.tsx +0 -16
- package/src/components/ui/switch.tsx +0 -33
- package/src/components/ui/table.tsx +0 -87
- package/src/components/ui/tabs.tsx +0 -80
- package/src/components/ui/textarea.tsx +0 -18
- package/src/components/ui/toggle-group.tsx +0 -86
- package/src/components/ui/toggle.tsx +0 -44
- package/src/components/ui/tooltip.tsx +0 -53
- package/src/context/MetaContext.tsx +0 -22
- package/src/context/ModuleContext.tsx +0 -62
- package/src/context/PermissionsContext.tsx +0 -39
- package/src/context/ShellProviders.tsx +0 -33
- package/src/context/UserContext.tsx +0 -16
- package/src/data/QueryProvider.tsx +0 -7
- package/src/data/queryClient.ts +0 -18
- package/src/data/useModelMeta.ts +0 -17
- package/src/data/useMutation.ts +0 -60
- package/src/data/useRecord.ts +0 -29
- package/src/data/useSource.ts +0 -112
- package/src/hooks/use-mobile.ts +0 -19
- package/src/index.css +0 -260
- package/src/index.ts +0 -16
- package/src/lib/utils.ts +0 -6
- package/src/main.tsx +0 -17
- package/src/router/NotFound.tsx +0 -8
- package/src/router/RouterProvider.tsx +0 -7
- package/src/router/buildRouteTree.tsx +0 -63
- package/src/router/createShellRouter.ts +0 -9
- package/src/router/hooks.ts +0 -43
- package/src/shell/CommandPalette.tsx +0 -76
- package/src/shell/ConfirmDialog.tsx +0 -34
- package/src/shell/ConfirmProvider.tsx +0 -56
- package/src/shell/DrawerContext.tsx +0 -44
- package/src/shell/HeaderActions.tsx +0 -31
- package/src/shell/ModuleSelectorPage.tsx +0 -149
- package/src/shell/PageOutlet.tsx +0 -21
- package/src/shell/ShellContext.tsx +0 -45
- package/src/shell/ShellDevTools.tsx +0 -153
- package/src/shell/ShellLayout.tsx +0 -231
- package/src/shell/Toast.tsx +0 -58
- package/src/shell/ToastProvider.tsx +0 -60
- package/src/shell/app-sidebar/AppSidebar.tsx +0 -44
- package/src/shell/app-sidebar/ModuleSwitcher.tsx +0 -87
- package/src/shell/app-sidebar/NavMain.tsx +0 -64
- package/src/shell/app-sidebar/NavUser.tsx +0 -97
- package/src/shell/app-sidebar/SearchMenu.tsx +0 -22
- package/src/shell/app-sidebar/index.ts +0 -8
- package/src/shell/app-sidebar/types.ts +0 -38
- package/src/shell/types.ts +0 -6
- package/src/shell/useBreadcrumbs.ts +0 -42
- package/src/studio/bridge.ts +0 -125
- package/src/studio/index.ts +0 -3
- package/src/studio/overlay.ts +0 -47
- package/src/studio/types.ts +0 -32
- package/src/studio/walker.ts +0 -48
- package/src/vite-env.d.ts +0 -1
- package/src/widgets/__tests__/action-edge-cases.test.ts +0 -281
- package/src/widgets/__tests__/action.test.ts +0 -236
- package/src/widgets/__tests__/attachment-widget.test.tsx +0 -85
- package/src/widgets/__tests__/attachments-widget.test.tsx +0 -109
- package/src/widgets/__tests__/binding.test.ts +0 -76
- package/src/widgets/__tests__/button-widget.test.tsx +0 -145
- package/src/widgets/__tests__/checkbox-widget.test.tsx +0 -158
- package/src/widgets/__tests__/code-widget.test.tsx +0 -64
- package/src/widgets/__tests__/computed-widget.test.tsx +0 -62
- package/src/widgets/__tests__/condition-edge-cases.test.ts +0 -120
- package/src/widgets/__tests__/condition.test.ts +0 -221
- package/src/widgets/__tests__/context.test.ts +0 -99
- package/src/widgets/__tests__/data-widget.test.tsx +0 -204
- package/src/widgets/__tests__/datepicker-widget.test.tsx +0 -66
- package/src/widgets/__tests__/datetime-widget.test.tsx +0 -67
- package/src/widgets/__tests__/drawer-widget.test.tsx +0 -149
- package/src/widgets/__tests__/dynamic-link-widget.test.tsx +0 -52
- package/src/widgets/__tests__/edge-cases.test.ts +0 -232
- package/src/widgets/__tests__/evaluator.test.ts +0 -107
- package/src/widgets/__tests__/functions.test.ts +0 -147
- package/src/widgets/__tests__/grid-widget.test.tsx +0 -137
- package/src/widgets/__tests__/hooks.test.tsx +0 -249
- package/src/widgets/__tests__/icon-widget.test.tsx +0 -129
- package/src/widgets/__tests__/input-widget.test.tsx +0 -264
- package/src/widgets/__tests__/integration.test.ts +0 -116
- package/src/widgets/__tests__/json-widget.test.tsx +0 -70
- package/src/widgets/__tests__/link-widget.test.tsx +0 -92
- package/src/widgets/__tests__/many-to-many-widget.test.tsx +0 -93
- package/src/widgets/__tests__/modal-widget.test.tsx +0 -148
- package/src/widgets/__tests__/money-widget.test.tsx +0 -97
- package/src/widgets/__tests__/parser.test.ts +0 -171
- package/src/widgets/__tests__/reactive-variables.test.ts +0 -383
- package/src/widgets/__tests__/renderer.test.tsx +0 -300
- package/src/widgets/__tests__/repeat-widget.test.tsx +0 -229
- package/src/widgets/__tests__/select-widget.test.tsx +0 -231
- package/src/widgets/__tests__/sequence-widget.test.tsx +0 -58
- package/src/widgets/__tests__/shell-integration.test.tsx +0 -1343
- package/src/widgets/__tests__/split-widget.test.tsx +0 -133
- package/src/widgets/__tests__/state-edge-cases.test.ts +0 -118
- package/src/widgets/__tests__/state.test.ts +0 -106
- package/src/widgets/__tests__/table-data-binding.test.tsx +0 -482
- package/src/widgets/__tests__/table-filter-popover.test.tsx +0 -486
- package/src/widgets/__tests__/table-search.test.tsx +0 -305
- package/src/widgets/__tests__/table-widget.test.tsx +0 -509
- package/src/widgets/__tests__/textarea-widget.test.tsx +0 -105
- package/src/widgets/__tests__/tracker-validator-edge-cases.test.ts +0 -242
- package/src/widgets/__tests__/tracker.test.ts +0 -133
- package/src/widgets/__tests__/tree-widget.test.tsx +0 -97
- package/src/widgets/__tests__/use-model-source.test.ts +0 -67
- package/src/widgets/__tests__/validator.test.ts +0 -208
- package/src/widgets/action/dispatcher.ts +0 -334
- package/src/widgets/action/index.ts +0 -2
- package/src/widgets/binding/index.ts +0 -2
- package/src/widgets/binding/resolver.ts +0 -61
- package/src/widgets/components/AttachmentWidget.tsx +0 -111
- package/src/widgets/components/AttachmentsWidget.tsx +0 -121
- package/src/widgets/components/BadgeWidget.tsx +0 -35
- package/src/widgets/components/ButtonWidget.tsx +0 -43
- package/src/widgets/components/CardWidget.tsx +0 -68
- package/src/widgets/components/CheckboxWidget.tsx +0 -39
- package/src/widgets/components/CodeWidget.tsx +0 -44
- package/src/widgets/components/ColumnWidget.tsx +0 -22
- package/src/widgets/components/ComputedWidget.tsx +0 -49
- package/src/widgets/components/DataWidget.tsx +0 -189
- package/src/widgets/components/DatePickerWidget.tsx +0 -73
- package/src/widgets/components/DatetimeWidget.tsx +0 -160
- package/src/widgets/components/DividerWidget.tsx +0 -37
- package/src/widgets/components/DrawerWidget.tsx +0 -52
- package/src/widgets/components/DynamicLinkWidget.tsx +0 -130
- package/src/widgets/components/GridWidget.tsx +0 -134
- package/src/widgets/components/GroupWidget.tsx +0 -111
- package/src/widgets/components/IconWidget.tsx +0 -29
- package/src/widgets/components/ImageWidget.tsx +0 -28
- package/src/widgets/components/InputWidget.tsx +0 -70
- package/src/widgets/components/JsonWidget.tsx +0 -78
- package/src/widgets/components/LinkWidget.tsx +0 -99
- package/src/widgets/components/ManyToManyWidget.tsx +0 -125
- package/src/widgets/components/ModalWidget.tsx +0 -52
- package/src/widgets/components/MoneyWidget.tsx +0 -80
- package/src/widgets/components/RepeatWidget.tsx +0 -66
- package/src/widgets/components/ScrollAreaWidget.tsx +0 -40
- package/src/widgets/components/SectionWidget.tsx +0 -78
- package/src/widgets/components/SelectWidget.tsx +0 -63
- package/src/widgets/components/SequenceWidget.tsx +0 -32
- package/src/widgets/components/SpacerWidget.tsx +0 -29
- package/src/widgets/components/SplitWidget.tsx +0 -60
- package/src/widgets/components/StackWidget.tsx +0 -44
- package/src/widgets/components/TableWidget.tsx +0 -366
- package/src/widgets/components/TextWidget.tsx +0 -44
- package/src/widgets/components/TextareaWidget.tsx +0 -49
- package/src/widgets/components/TreeWidget.tsx +0 -109
- package/src/widgets/components/index.ts +0 -30
- package/src/widgets/components/register.ts +0 -93
- package/src/widgets/components/table/CellRenderers.tsx +0 -83
- package/src/widgets/components/table/TablePagination.tsx +0 -45
- package/src/widgets/components/table/TableToolbar.tsx +0 -285
- package/src/widgets/components/table/filter-operators.ts +0 -134
- package/src/widgets/components/table/index.ts +0 -11
- package/src/widgets/condition/evaluator.ts +0 -57
- package/src/widgets/condition/index.ts +0 -1
- package/src/widgets/context/builder.ts +0 -99
- package/src/widgets/context/index.ts +0 -8
- package/src/widgets/context/types.ts +0 -37
- package/src/widgets/data/index.ts +0 -5
- package/src/widgets/data/useModelQuery.ts +0 -116
- package/src/widgets/data/useModelRecord.ts +0 -37
- package/src/widgets/expression/evaluator.ts +0 -100
- package/src/widgets/expression/functions.ts +0 -131
- package/src/widgets/expression/index.ts +0 -13
- package/src/widgets/expression/parser.ts +0 -229
- package/src/widgets/expression/types.ts +0 -45
- package/src/widgets/form/FormContext.ts +0 -29
- package/src/widgets/form/FormProvider.tsx +0 -84
- package/src/widgets/form/FormWidget.tsx +0 -42
- package/src/widgets/form/index.ts +0 -4
- package/src/widgets/form/useFormState.ts +0 -127
- package/src/widgets/form/useFormSubmit.ts +0 -90
- package/src/widgets/form/useFormValidation.ts +0 -62
- package/src/widgets/hooks/index.ts +0 -8
- package/src/widgets/hooks/useAction.ts +0 -83
- package/src/widgets/hooks/useBind.ts +0 -34
- package/src/widgets/hooks/useCondition.ts +0 -21
- package/src/widgets/hooks/useDataQuery.ts +0 -48
- package/src/widgets/hooks/useExpression.ts +0 -14
- package/src/widgets/hooks/usePageState.ts +0 -21
- package/src/widgets/hooks/useSurfaceContext.ts +0 -11
- package/src/widgets/hooks/useWidgetContext.ts +0 -14
- package/src/widgets/index.ts +0 -80
- package/src/widgets/lib/layout-props.ts +0 -135
- package/src/widgets/reactivity/index.ts +0 -11
- package/src/widgets/reactivity/tracker.ts +0 -139
- package/src/widgets/reactivity/variables.ts +0 -213
- package/src/widgets/registry.ts +0 -41
- package/src/widgets/renderer/SlotRenderer.tsx +0 -47
- package/src/widgets/renderer/WidgetRenderer.tsx +0 -191
- package/src/widgets/renderer/index.ts +0 -4
- package/src/widgets/shell/WidgetSlotRenderer.tsx +0 -73
- package/src/widgets/shell/index.ts +0 -4
- package/src/widgets/shell/useActionHandlers.ts +0 -170
- package/src/widgets/state/index.ts +0 -2
- package/src/widgets/state/store.ts +0 -96
- package/src/widgets/types.ts +0 -28
- package/src/widgets/validation/index.ts +0 -2
- package/src/widgets/validation/validator.ts +0 -140
- package/tsconfig.json +0 -27
- package/tsconfig.tsbuildinfo +0 -1
- package/vite.config.ts +0 -21
- package/vitest.config.ts +0 -16
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'vitest';
|
|
2
|
-
import { parse } from '../expression/parser.js';
|
|
3
|
-
import { evaluate } from '../expression/evaluator.js';
|
|
4
|
-
|
|
5
|
-
describe('Expression Edge Cases', () => {
|
|
6
|
-
describe('Parser edge cases', () => {
|
|
7
|
-
test('deeply nested parentheses', () => {
|
|
8
|
-
const ast = parse('{{((((a))))}}');
|
|
9
|
-
expect(ast).toEqual({ type: 'field', path: ['a'] });
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('multiple unary operators', () => {
|
|
13
|
-
const result = evaluate(parse('{{!!true}}'), {});
|
|
14
|
-
expect(result).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('double negation', () => {
|
|
18
|
-
expect(evaluate(parse('{{- -5}}'), {})).toBe(5);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('empty string literal', () => {
|
|
22
|
-
expect(evaluate(parse('{{""}}'), {})).toBe('');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('string with escaped quotes', () => {
|
|
26
|
-
expect(evaluate(parse('{{"hello \\"world\\""}}'), {})).toBe('hello "world"');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('string with escaped newline', () => {
|
|
30
|
-
expect(evaluate(parse('{{"line1\\nline2"}}'), {})).toBe('line1\nline2');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('whitespace around expression', () => {
|
|
34
|
-
expect(evaluate(parse('{{ 42 }}'), {})).toBe(42);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('complex chained comparisons', () => {
|
|
38
|
-
const result = evaluate(parse('{{a > 0 && a < 100}}'), { a: 50 });
|
|
39
|
-
expect(result).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('function call with expression arguments', () => {
|
|
43
|
-
const result = evaluate(parse('{{round(a * b / 100, 2)}}'), { a: 33, b: 7 });
|
|
44
|
-
expect(result).toBe(2.31);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('identifier starting with $', () => {
|
|
48
|
-
expect(parse('{{$state.loading}}')).toEqual({ type: 'field', path: ['$state', 'loading'] });
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('identifier with underscores and numbers', () => {
|
|
52
|
-
expect(parse('{{field_name_2}}')).toEqual({ type: 'field', path: ['field_name_2'] });
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('throws on unclosed string', () => {
|
|
56
|
-
expect(() => parse('{{"unclosed}}')).toThrow();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('throws on unclosed parenthesis', () => {
|
|
60
|
-
expect(() => parse('{{(a + b}}')).toThrow();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('throws on empty input', () => {
|
|
64
|
-
expect(() => parse('{{}}')).toThrow();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('throws on trailing operator', () => {
|
|
68
|
-
expect(() => parse('{{a +}}')).toThrow();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('Evaluator edge cases', () => {
|
|
73
|
-
test('null arithmetic yields 0', () => {
|
|
74
|
-
expect(evaluate(parse('{{a + b}}'), { a: null, b: null })).toBe(0);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('undefined field in arithmetic', () => {
|
|
78
|
-
expect(evaluate(parse('{{a * 5}}'), {})).toBeNaN();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('string + number concatenates', () => {
|
|
82
|
-
expect(evaluate(parse('{{prefix + 42}}'), { prefix: 'item-' })).toBe('item-42');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('number + string concatenates', () => {
|
|
86
|
-
expect(evaluate(parse('{{42 + suffix}}'), { suffix: '-end' })).toBe('42-end');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('null == null is true', () => {
|
|
90
|
-
expect(evaluate(parse('{{a == b}}'), { a: null, b: null })).toBe(true);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('undefined == null is true (loose equality)', () => {
|
|
94
|
-
expect(evaluate(parse('{{a == b}}'), { a: undefined, b: null })).toBe(true);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('0 == false is true (loose equality)', () => {
|
|
98
|
-
expect(evaluate(parse('{{a == b}}'), { a: 0, b: false })).toBe(true);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('deeply nested field access', () => {
|
|
102
|
-
const ctx = { a: { b: { c: { d: 42 } } } };
|
|
103
|
-
expect(evaluate(parse('{{a.b.c.d}}'), ctx)).toBe(42);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('field access on null returns undefined', () => {
|
|
107
|
-
expect(evaluate(parse('{{a.b.c}}'), { a: null })).toBeUndefined();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('field access on missing intermediate returns undefined', () => {
|
|
111
|
-
expect(evaluate(parse('{{a.b.c}}'), {})).toBeUndefined();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('logical AND short-circuits (no error on null access)', () => {
|
|
115
|
-
const result = evaluate(parse('{{a && a.b}}'), { a: null });
|
|
116
|
-
expect(result).toBe(null);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('logical OR short-circuits', () => {
|
|
120
|
-
const result = evaluate(parse('{{a || "default"}}'), { a: 'value' });
|
|
121
|
-
expect(result).toBe('value');
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('division by zero returns 0', () => {
|
|
125
|
-
expect(evaluate(parse('{{100 / 0}}'), {})).toBe(0);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test('modulo by zero returns NaN', () => {
|
|
129
|
-
expect(evaluate(parse('{{10 % 0}}'), {})).toBeNaN();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('not on null is true', () => {
|
|
133
|
-
expect(evaluate(parse('{{!a}}'), { a: null })).toBe(true);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test('not on 0 is true', () => {
|
|
137
|
-
expect(evaluate(parse('{{!a}}'), { a: 0 })).toBe(true);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test('not on empty string is true', () => {
|
|
141
|
-
expect(evaluate(parse('{{!a}}'), { a: '' })).toBe(true);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test('complex real-world: order total with discount', () => {
|
|
145
|
-
const ctx = { qty: 10, rate: 50, discount: 15, tax_rate: 0.1 };
|
|
146
|
-
const expr = '{{(qty * rate * (100 - discount) / 100) * (1 + tax_rate)}}';
|
|
147
|
-
expect(evaluate(parse(expr), ctx)).toBeCloseTo(467.5);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('Function edge cases', () => {
|
|
152
|
-
test('sum with non-array returns 0', () => {
|
|
153
|
-
expect(evaluate(parse('{{sum(items)}}'), { items: null })).toBe(0);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test('sum with mixed types coerces to numbers', () => {
|
|
157
|
-
expect(evaluate(parse('{{sum(items)}}'), { items: ['10', 20, null, '30'] })).toBe(60);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
test('count of non-array returns 0', () => {
|
|
161
|
-
expect(evaluate(parse('{{count(items)}}'), { items: undefined })).toBe(0);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test('min of single element', () => {
|
|
165
|
-
expect(evaluate(parse('{{min(items)}}'), { items: [42] })).toBe(42);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test('max of negative numbers', () => {
|
|
169
|
-
expect(evaluate(parse('{{max(items)}}'), { items: [-5, -2, -10] })).toBe(-2);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('round negative number', () => {
|
|
173
|
-
expect(evaluate(parse('{{round(-3.7)}}'), {})).toBe(-4);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
test('round with many decimals', () => {
|
|
177
|
-
expect(evaluate(parse('{{round(1.005, 2)}}'), {})).toBeCloseTo(1.01, 1);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test('concat with null values', () => {
|
|
181
|
-
expect(evaluate(parse('{{concat(a, "-", b)}}'), { a: null, b: null })).toBe('-');
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test('upper of number coerces to string', () => {
|
|
185
|
-
expect(evaluate(parse('{{upper(val)}}'), { val: 123 })).toBe('123');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
test('format_currency with zero', () => {
|
|
189
|
-
const result = evaluate(parse('{{format_currency(0, "USD")}}'), {}) as string;
|
|
190
|
-
expect(result).toContain('0.00');
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test('format_number with large number', () => {
|
|
194
|
-
const result = evaluate(parse('{{format_number(1000000000, 0)}}'), {}) as string;
|
|
195
|
-
expect(result).toBe('1,000,000,000');
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('coalesce with 0 (not null) returns 0', () => {
|
|
199
|
-
expect(evaluate(parse('{{coalesce(a, 99)}}'), { a: 0 })).toBe(0);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test('coalesce with empty string (not null) returns empty string', () => {
|
|
203
|
-
expect(evaluate(parse('{{coalesce(a, "default")}}'), { a: '' })).toBe('');
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test('if with falsy 0 takes else branch', () => {
|
|
207
|
-
expect(evaluate(parse('{{if(count, "has items", "empty")}}'), { count: 0 })).toBe('empty');
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
test('if with truthy non-zero takes then branch', () => {
|
|
211
|
-
expect(evaluate(parse('{{if(count, "has items", "empty")}}'), { count: 5 })).toBe(
|
|
212
|
-
'has items',
|
|
213
|
-
);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test('add_days crossing month boundary', () => {
|
|
217
|
-
expect(evaluate(parse('{{add_days("2024-01-30", 5)}}'), {})).toBe('2024-02-04');
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
test('add_days negative days', () => {
|
|
221
|
-
expect(evaluate(parse('{{add_days("2024-03-01", -1)}}'), {})).toBe('2024-02-29');
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test('diff_days same date is 0', () => {
|
|
225
|
-
expect(evaluate(parse('{{diff_days("2024-01-01", "2024-01-01")}}'), {})).toBe(0);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
test('diff_days negative result', () => {
|
|
229
|
-
expect(evaluate(parse('{{diff_days("2024-01-01", "2024-01-10")}}'), {})).toBe(-9);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'vitest';
|
|
2
|
-
import { parse } from '../expression/parser.js';
|
|
3
|
-
import { evaluate } from '../expression/evaluator.js';
|
|
4
|
-
|
|
5
|
-
describe('Expression Evaluator', () => {
|
|
6
|
-
test('evaluates number literal', () => {
|
|
7
|
-
expect(evaluate(parse('{{42}}'), {})).toBe(42);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('evaluates string literal', () => {
|
|
11
|
-
expect(evaluate(parse('{{"hello"}}'), {})).toBe('hello');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('evaluates boolean literal', () => {
|
|
15
|
-
expect(evaluate(parse('{{true}}'), {})).toBe(true);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('evaluates null literal', () => {
|
|
19
|
-
expect(evaluate(parse('{{null}}'), {})).toBe(null);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('evaluates field reference', () => {
|
|
23
|
-
expect(evaluate(parse('{{qty}}'), { qty: 5 })).toBe(5);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('evaluates dotted field reference', () => {
|
|
27
|
-
expect(evaluate(parse('{{$parent.currency}}'), { $parent: { currency: 'USD' } })).toBe('USD');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('returns undefined for missing field', () => {
|
|
31
|
-
expect(evaluate(parse('{{missing}}'), {})).toBeUndefined();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('evaluates addition', () => {
|
|
35
|
-
expect(evaluate(parse('{{a + b}}'), { a: 3, b: 7 })).toBe(10);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('evaluates subtraction', () => {
|
|
39
|
-
expect(evaluate(parse('{{a - b}}'), { a: 10, b: 3 })).toBe(7);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('evaluates multiplication', () => {
|
|
43
|
-
expect(evaluate(parse('{{qty * rate}}'), { qty: 5, rate: 100 })).toBe(500);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('evaluates division', () => {
|
|
47
|
-
expect(evaluate(parse('{{a / b}}'), { a: 10, b: 2 })).toBe(5);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('division by zero returns 0', () => {
|
|
51
|
-
expect(evaluate(parse('{{a / b}}'), { a: 10, b: 0 })).toBe(0);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('evaluates modulo', () => {
|
|
55
|
-
expect(evaluate(parse('{{a % b}}'), { a: 10, b: 3 })).toBe(1);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('string concatenation with +', () => {
|
|
59
|
-
expect(evaluate(parse('{{name + " " + suffix}}'), { name: 'Order', suffix: '#1' })).toBe(
|
|
60
|
-
'Order #1',
|
|
61
|
-
);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('evaluates equality', () => {
|
|
65
|
-
expect(evaluate(parse('{{status == "draft"}}'), { status: 'draft' })).toBe(true);
|
|
66
|
-
expect(evaluate(parse('{{status == "draft"}}'), { status: 'submitted' })).toBe(false);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('evaluates inequality', () => {
|
|
70
|
-
expect(evaluate(parse('{{status != "draft"}}'), { status: 'submitted' })).toBe(true);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('evaluates comparison operators', () => {
|
|
74
|
-
expect(evaluate(parse('{{a > b}}'), { a: 5, b: 3 })).toBe(true);
|
|
75
|
-
expect(evaluate(parse('{{a < b}}'), { a: 5, b: 3 })).toBe(false);
|
|
76
|
-
expect(evaluate(parse('{{a >= b}}'), { a: 5, b: 5 })).toBe(true);
|
|
77
|
-
expect(evaluate(parse('{{a <= b}}'), { a: 3, b: 5 })).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('evaluates logical AND (short-circuit)', () => {
|
|
81
|
-
expect(evaluate(parse('{{a && b}}'), { a: true, b: 'yes' })).toBe('yes');
|
|
82
|
-
expect(evaluate(parse('{{a && b}}'), { a: false, b: 'yes' })).toBe(false);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('evaluates logical OR (short-circuit)', () => {
|
|
86
|
-
expect(evaluate(parse('{{a || b}}'), { a: null, b: 'fallback' })).toBe('fallback');
|
|
87
|
-
expect(evaluate(parse('{{a || b}}'), { a: 'first', b: 'second' })).toBe('first');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test('evaluates unary not', () => {
|
|
91
|
-
expect(evaluate(parse('{{!active}}'), { active: true })).toBe(false);
|
|
92
|
-
expect(evaluate(parse('{{!active}}'), { active: false })).toBe(true);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('evaluates unary negation', () => {
|
|
96
|
-
expect(evaluate(parse('{{-amount}}'), { amount: 50 })).toBe(-50);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('evaluates nested expressions', () => {
|
|
100
|
-
expect(evaluate(parse('{{(qty * rate) + tax}}'), { qty: 5, rate: 100, tax: 25 })).toBe(525);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('evaluates complex expression', () => {
|
|
104
|
-
const expr = '{{qty * rate * (1 - discount / 100)}}';
|
|
105
|
-
expect(evaluate(parse(expr), { qty: 10, rate: 50, discount: 10 })).toBe(450);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'vitest';
|
|
2
|
-
import { parse } from '../expression/parser.js';
|
|
3
|
-
import { evaluate } from '../expression/evaluator.js';
|
|
4
|
-
|
|
5
|
-
describe('Expression Functions', () => {
|
|
6
|
-
describe('Aggregate', () => {
|
|
7
|
-
test('sum', () => {
|
|
8
|
-
expect(evaluate(parse('{{sum(items)}}'), { items: [10, 20, 30] })).toBe(60);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('sum of empty array', () => {
|
|
12
|
-
expect(evaluate(parse('{{sum(items)}}'), { items: [] })).toBe(0);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('count', () => {
|
|
16
|
-
expect(evaluate(parse('{{count(items)}}'), { items: [1, 2, 3] })).toBe(3);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('avg', () => {
|
|
20
|
-
expect(evaluate(parse('{{avg(items)}}'), { items: [10, 20, 30] })).toBe(20);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('avg of empty array', () => {
|
|
24
|
-
expect(evaluate(parse('{{avg(items)}}'), { items: [] })).toBe(0);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('min', () => {
|
|
28
|
-
expect(evaluate(parse('{{min(items)}}'), { items: [5, 2, 8, 1] })).toBe(1);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('max', () => {
|
|
32
|
-
expect(evaluate(parse('{{max(items)}}'), { items: [5, 2, 8, 1] })).toBe(8);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('Math', () => {
|
|
37
|
-
test('round without decimals', () => {
|
|
38
|
-
expect(evaluate(parse('{{round(3.7)}}'), {})).toBe(4);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('round with decimals', () => {
|
|
42
|
-
expect(evaluate(parse('{{round(3.14159, 2)}}'), {})).toBe(3.14);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('abs', () => {
|
|
46
|
-
expect(evaluate(parse('{{abs(-5)}}'), {})).toBe(5);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('ceil', () => {
|
|
50
|
-
expect(evaluate(parse('{{ceil(3.2)}}'), {})).toBe(4);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('floor', () => {
|
|
54
|
-
expect(evaluate(parse('{{floor(3.9)}}'), {})).toBe(3);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('String', () => {
|
|
59
|
-
test('upper', () => {
|
|
60
|
-
expect(evaluate(parse('{{upper("hello")}}'), {})).toBe('HELLO');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('lower', () => {
|
|
64
|
-
expect(evaluate(parse('{{lower("HELLO")}}'), {})).toBe('hello');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('concat', () => {
|
|
68
|
-
expect(evaluate(parse('{{concat("a", "b", "c")}}'), {})).toBe('abc');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('trim', () => {
|
|
72
|
-
expect(evaluate(parse('{{trim(" hello ")}}'), {})).toBe('hello');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('upper with null', () => {
|
|
76
|
-
expect(evaluate(parse('{{upper(val)}}'), { val: null })).toBe('');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('Date', () => {
|
|
81
|
-
test('today returns date string', () => {
|
|
82
|
-
const result = evaluate(parse('{{today()}}'), {}) as string;
|
|
83
|
-
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('now returns ISO string', () => {
|
|
87
|
-
const result = evaluate(parse('{{now()}}'), {}) as string;
|
|
88
|
-
expect(result).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('add_days', () => {
|
|
92
|
-
expect(evaluate(parse('{{add_days("2024-01-01", 5)}}'), {})).toBe('2024-01-06');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('diff_days', () => {
|
|
96
|
-
expect(evaluate(parse('{{diff_days("2024-01-10", "2024-01-01")}}'), {})).toBe(9);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('format_date', () => {
|
|
100
|
-
expect(evaluate(parse('{{format_date("2024-03-15", "YYYY-MM-DD")}}'), {})).toBe('2024-03-15');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('Format', () => {
|
|
105
|
-
test('format_currency', () => {
|
|
106
|
-
const result = evaluate(parse('{{format_currency(1234.5, "USD")}}'), {}) as string;
|
|
107
|
-
expect(result).toContain('1,234.50');
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('format_number', () => {
|
|
111
|
-
const result = evaluate(parse('{{format_number(1234567, 2)}}'), {}) as string;
|
|
112
|
-
expect(result).toBe('1,234,567.00');
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('Logic', () => {
|
|
117
|
-
test('if true branch', () => {
|
|
118
|
-
expect(evaluate(parse('{{if(true, "yes", "no")}}'), {})).toBe('yes');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('if false branch', () => {
|
|
122
|
-
expect(evaluate(parse('{{if(false, "yes", "no")}}'), {})).toBe('no');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test('if with expression condition', () => {
|
|
126
|
-
expect(
|
|
127
|
-
evaluate(parse('{{if(status == "draft", "Pending", "Done")}}'), { status: 'draft' }),
|
|
128
|
-
).toBe('Pending');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('coalesce returns first non-null', () => {
|
|
132
|
-
expect(evaluate(parse('{{coalesce(a, b, c)}}'), { a: null, b: undefined, c: 'found' })).toBe(
|
|
133
|
-
'found',
|
|
134
|
-
);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('coalesce all null returns null', () => {
|
|
138
|
-
expect(evaluate(parse('{{coalesce(a, b)}}'), { a: null, b: null })).toBe(null);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe('Error handling', () => {
|
|
143
|
-
test('unknown function throws', () => {
|
|
144
|
-
expect(() => evaluate(parse('{{unknown_fn()}}'), {})).toThrow('Unknown function: unknown_fn');
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { render, cleanup } from '@testing-library/react';
|
|
4
|
-
import { registerWidget, clearWidgetRegistry } from '../registry.js';
|
|
5
|
-
import { GridWidget } from '../components/GridWidget.js';
|
|
6
|
-
import type { WidgetProps } from '../types.js';
|
|
7
|
-
import type { ComponentType } from 'react';
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
clearWidgetRegistry();
|
|
11
|
-
registerWidget(
|
|
12
|
-
{
|
|
13
|
-
name: 'grid',
|
|
14
|
-
label: 'Grid',
|
|
15
|
-
category: 'layout',
|
|
16
|
-
schema: {},
|
|
17
|
-
binding: 'none',
|
|
18
|
-
triggers: [],
|
|
19
|
-
container: true,
|
|
20
|
-
},
|
|
21
|
-
GridWidget as unknown as ComponentType<WidgetProps>,
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
cleanup();
|
|
27
|
-
clearWidgetRegistry();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('GridWidget', () => {
|
|
31
|
-
it('renders with default 3 columns and md gap', () => {
|
|
32
|
-
const { container } = render(
|
|
33
|
-
<GridWidget
|
|
34
|
-
props={{}}
|
|
35
|
-
bind={{ value: undefined }}
|
|
36
|
-
on={{}}
|
|
37
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
38
|
-
>
|
|
39
|
-
<div>1</div>
|
|
40
|
-
<div>2</div>
|
|
41
|
-
<div>3</div>
|
|
42
|
-
</GridWidget>,
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const grid = container.firstElementChild as HTMLElement;
|
|
46
|
-
expect(grid.className).toContain('grid');
|
|
47
|
-
expect(grid.className).toContain('grid-cols-3');
|
|
48
|
-
expect(grid.className).toContain('gap-4');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('renders with custom columns', () => {
|
|
52
|
-
const { container } = render(
|
|
53
|
-
<GridWidget
|
|
54
|
-
props={{ columns: 4 }}
|
|
55
|
-
bind={{ value: undefined }}
|
|
56
|
-
on={{}}
|
|
57
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
58
|
-
>
|
|
59
|
-
<div>1</div>
|
|
60
|
-
<div>2</div>
|
|
61
|
-
<div>3</div>
|
|
62
|
-
<div>4</div>
|
|
63
|
-
</GridWidget>,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const grid = container.firstElementChild as HTMLElement;
|
|
67
|
-
expect(grid.className).toContain('grid-cols-4');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('renders with sm gap', () => {
|
|
71
|
-
const { container } = render(
|
|
72
|
-
<GridWidget
|
|
73
|
-
props={{ gap: 'sm' }}
|
|
74
|
-
bind={{ value: undefined }}
|
|
75
|
-
on={{}}
|
|
76
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
77
|
-
>
|
|
78
|
-
<div>1</div>
|
|
79
|
-
</GridWidget>,
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const grid = container.firstElementChild as HTMLElement;
|
|
83
|
-
expect(grid.className).toContain('gap-2');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('renders with lg gap', () => {
|
|
87
|
-
const { container } = render(
|
|
88
|
-
<GridWidget
|
|
89
|
-
props={{ gap: 'lg' }}
|
|
90
|
-
bind={{ value: undefined }}
|
|
91
|
-
on={{}}
|
|
92
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
93
|
-
>
|
|
94
|
-
<div>1</div>
|
|
95
|
-
</GridWidget>,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const grid = container.firstElementChild as HTMLElement;
|
|
99
|
-
expect(grid.className).toContain('gap-6');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('renders children inside the grid', () => {
|
|
103
|
-
const { container } = render(
|
|
104
|
-
<GridWidget
|
|
105
|
-
props={{ columns: 2, gap: 'md' }}
|
|
106
|
-
bind={{ value: undefined }}
|
|
107
|
-
on={{}}
|
|
108
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
109
|
-
>
|
|
110
|
-
<div data-testid="item-1">Item 1</div>
|
|
111
|
-
<div data-testid="item-2">Item 2</div>
|
|
112
|
-
</GridWidget>,
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const grid = container.firstElementChild as HTMLElement;
|
|
116
|
-
expect(grid.children).toHaveLength(2);
|
|
117
|
-
expect(grid.children[0].textContent).toBe('Item 1');
|
|
118
|
-
expect(grid.children[1].textContent).toBe('Item 2');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('applies default responsive classes', () => {
|
|
122
|
-
const { container } = render(
|
|
123
|
-
<GridWidget
|
|
124
|
-
props={{ columns: 3 }}
|
|
125
|
-
bind={{ value: undefined }}
|
|
126
|
-
on={{}}
|
|
127
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
128
|
-
>
|
|
129
|
-
<div>1</div>
|
|
130
|
-
</GridWidget>,
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
const grid = container.firstElementChild as HTMLElement;
|
|
134
|
-
expect(grid.className).toContain('max-md:grid-cols-2');
|
|
135
|
-
expect(grid.className).toContain('max-sm:grid-cols-1');
|
|
136
|
-
});
|
|
137
|
-
});
|