@rangka/client 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +7 -1
- package/dist/App.js.map +1 -1
- package/dist/components/ui/input-group.d.ts +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/AttachmentWidget-BTTGroHP.js +1 -0
- package/dist/shell/assets/AttachmentsWidget-DZgvmO9P.js +1 -0
- package/dist/shell/assets/BadgeWidget-DN6GsAAG.js +1 -0
- package/dist/shell/assets/CardWidget-qX-UvqJh.js +1 -0
- package/dist/shell/assets/CheckboxWidget-CYPZ85ih.js +1 -0
- package/dist/shell/assets/CodeWidget-DnVtHG1d.js +1 -0
- package/dist/shell/assets/ColumnWidget-CYmFCVOf.js +1 -0
- package/dist/shell/assets/ComputedWidget-BQApkfir.js +1 -0
- package/dist/shell/assets/DatePickerWidget-pEusSy9D.js +1 -0
- package/dist/shell/assets/DatetimeWidget-M0fEGDTD.js +1 -0
- package/dist/shell/assets/DividerWidget-hXVGhIKC.js +1 -0
- package/dist/shell/assets/DrawerWidget-DynL7EIy.js +1 -0
- package/dist/shell/assets/DynamicLinkWidget-ChMJ5DAf.js +1 -0
- package/dist/shell/assets/IconWidget-Cgo9txq1.js +1 -0
- package/dist/shell/assets/ImageWidget-YUv1_OQK.js +1 -0
- package/dist/shell/assets/JsonWidget-RHUHhXHJ.js +1 -0
- package/dist/shell/assets/LinkWidget-CIu7qmb2.js +1 -0
- package/dist/shell/assets/ManyToManyWidget-DCQnygvZ.js +1 -0
- package/dist/shell/assets/ModalWidget-FggzYaS2.js +1 -0
- package/dist/shell/assets/MoneyWidget-CKjOSucD.js +1 -0
- package/dist/shell/assets/RepeatWidget-Dfp4zW4d.js +1 -0
- package/dist/shell/assets/ScrollAreaWidget-CdFdf4rv.js +1 -0
- package/dist/shell/assets/SequenceWidget-DIXHZslz.js +1 -0
- package/dist/shell/assets/SpacerWidget-BgM4dC6x.js +1 -0
- package/dist/shell/assets/SplitWidget-_mcQkjQk.js +1 -0
- package/dist/shell/assets/StackWidget-BI_VIreo.js +1 -0
- package/dist/shell/assets/TableWidget-DuIvd6qR.js +1 -0
- package/dist/shell/assets/TextareaWidget-CATua7Ls.js +1 -0
- package/dist/shell/assets/TreeWidget-BoHlhfza.js +1 -0
- package/dist/shell/assets/calendar-DqckiKt1.js +1 -0
- package/dist/shell/assets/index-63v1sBS3.css +1 -0
- package/dist/shell/assets/index-D1wStSrO.js +8635 -0
- package/dist/shell/assets/popover-DywIKFaQ.js +1 -0
- package/dist/shell/assets/textarea-BVCZevA6.js +1 -0
- package/dist/shell/assets/useSurfaceContext-kzu9770H.js +1 -0
- package/dist/shell/assets/vendor-query-dRdWN_eK.js +1 -0
- package/dist/shell/assets/vendor-radix-D-Trh8JA.js +69 -0
- package/dist/shell/assets/vendor-router-B1WM9yRc.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.d.ts.map +1 -1
- package/dist/widgets/components/register.js +0 -58
- 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 +99 -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 -18
- 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,249 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { describe, test, expect } from 'vitest';
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import { WidgetContextProvider, useWidgetContext } from '../hooks/useWidgetContext.js';
|
|
5
|
-
import { PageStateProvider } from '../hooks/usePageState.js';
|
|
6
|
-
import { StateStore } from '../state/store.js';
|
|
7
|
-
import { createRootContext } from '../context/builder.js';
|
|
8
|
-
import { useBind } from '../hooks/useBind.js';
|
|
9
|
-
import { useExpression } from '../hooks/useExpression.js';
|
|
10
|
-
import { useCondition } from '../hooks/useCondition.js';
|
|
11
|
-
import { usePageState } from '../hooks/usePageState.js';
|
|
12
|
-
import type { WidgetContext } from '../context/types.js';
|
|
13
|
-
|
|
14
|
-
function TestWrapper({ ctx, children }: { ctx: WidgetContext; children: React.ReactNode }) {
|
|
15
|
-
const state = new StateStore();
|
|
16
|
-
return (
|
|
17
|
-
<PageStateProvider value={state}>
|
|
18
|
-
<WidgetContextProvider value={ctx}>{children}</WidgetContextProvider>
|
|
19
|
-
</PageStateProvider>
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe('useBind hook', () => {
|
|
24
|
-
test('returns null for undefined bind', () => {
|
|
25
|
-
function TestComp() {
|
|
26
|
-
const result = useBind(undefined);
|
|
27
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
28
|
-
}
|
|
29
|
-
const ctx = createRootContext({}, 'test', 'view');
|
|
30
|
-
render(
|
|
31
|
-
<TestWrapper ctx={ctx}>
|
|
32
|
-
<TestComp />
|
|
33
|
-
</TestWrapper>,
|
|
34
|
-
);
|
|
35
|
-
expect(screen.getByTestId('result')).toHaveTextContent('null');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('returns field value from context', () => {
|
|
39
|
-
function TestComp() {
|
|
40
|
-
const result = useBind({ field: 'name' });
|
|
41
|
-
return <div data-testid="result">{String(result?.value)}</div>;
|
|
42
|
-
}
|
|
43
|
-
const ctx = createRootContext({ name: 'Test' }, 'test', 'view');
|
|
44
|
-
render(
|
|
45
|
-
<TestWrapper ctx={ctx}>
|
|
46
|
-
<TestComp />
|
|
47
|
-
</TestWrapper>,
|
|
48
|
-
);
|
|
49
|
-
expect(screen.getByTestId('result')).toHaveTextContent('Test');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('evaluates expression binding', () => {
|
|
53
|
-
function TestComp() {
|
|
54
|
-
const result = useBind({ expression: '{{a + b}}' });
|
|
55
|
-
return <div data-testid="result">{String(result?.value)}</div>;
|
|
56
|
-
}
|
|
57
|
-
const ctx = createRootContext({ a: 3, b: 7 }, 'test', 'view');
|
|
58
|
-
render(
|
|
59
|
-
<TestWrapper ctx={ctx}>
|
|
60
|
-
<TestComp />
|
|
61
|
-
</TestWrapper>,
|
|
62
|
-
);
|
|
63
|
-
expect(screen.getByTestId('result')).toHaveTextContent('10');
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('useExpression hook', () => {
|
|
68
|
-
test('returns undefined for no expression', () => {
|
|
69
|
-
function TestComp() {
|
|
70
|
-
const result = useExpression(undefined);
|
|
71
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
72
|
-
}
|
|
73
|
-
const ctx = createRootContext({}, 'test', 'view');
|
|
74
|
-
render(
|
|
75
|
-
<TestWrapper ctx={ctx}>
|
|
76
|
-
<TestComp />
|
|
77
|
-
</TestWrapper>,
|
|
78
|
-
);
|
|
79
|
-
expect(screen.getByTestId('result')).toHaveTextContent('undefined');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('evaluates expression against context', () => {
|
|
83
|
-
function TestComp() {
|
|
84
|
-
const result = useExpression('{{qty * rate}}');
|
|
85
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
86
|
-
}
|
|
87
|
-
const ctx = createRootContext({ qty: 4, rate: 25 }, 'test', 'view');
|
|
88
|
-
render(
|
|
89
|
-
<TestWrapper ctx={ctx}>
|
|
90
|
-
<TestComp />
|
|
91
|
-
</TestWrapper>,
|
|
92
|
-
);
|
|
93
|
-
expect(screen.getByTestId('result')).toHaveTextContent('100');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('handles function calls in expressions', () => {
|
|
97
|
-
function TestComp() {
|
|
98
|
-
const result = useExpression('{{upper("hello")}}');
|
|
99
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
100
|
-
}
|
|
101
|
-
const ctx = createRootContext({}, 'test', 'view');
|
|
102
|
-
render(
|
|
103
|
-
<TestWrapper ctx={ctx}>
|
|
104
|
-
<TestComp />
|
|
105
|
-
</TestWrapper>,
|
|
106
|
-
);
|
|
107
|
-
expect(screen.getByTestId('result')).toHaveTextContent('HELLO');
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe('useCondition hook', () => {
|
|
112
|
-
test('returns true when no conditions', () => {
|
|
113
|
-
function TestComp() {
|
|
114
|
-
const result = useCondition(undefined);
|
|
115
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
116
|
-
}
|
|
117
|
-
const ctx = createRootContext({}, 'test', 'view');
|
|
118
|
-
render(
|
|
119
|
-
<TestWrapper ctx={ctx}>
|
|
120
|
-
<TestComp />
|
|
121
|
-
</TestWrapper>,
|
|
122
|
-
);
|
|
123
|
-
expect(screen.getByTestId('result')).toHaveTextContent('true');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('evaluates single condition', () => {
|
|
127
|
-
function TestComp() {
|
|
128
|
-
const result = useCondition({ field: 'status', operator: 'eq', value: 'draft' });
|
|
129
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
130
|
-
}
|
|
131
|
-
const ctx = createRootContext({ status: 'draft' }, 'test', 'view');
|
|
132
|
-
render(
|
|
133
|
-
<TestWrapper ctx={ctx}>
|
|
134
|
-
<TestComp />
|
|
135
|
-
</TestWrapper>,
|
|
136
|
-
);
|
|
137
|
-
expect(screen.getByTestId('result')).toHaveTextContent('true');
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test('evaluates failing condition', () => {
|
|
141
|
-
function TestComp() {
|
|
142
|
-
const result = useCondition({ field: 'status', operator: 'eq', value: 'draft' });
|
|
143
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
144
|
-
}
|
|
145
|
-
const ctx = createRootContext({ status: 'submitted' }, 'test', 'view');
|
|
146
|
-
render(
|
|
147
|
-
<TestWrapper ctx={ctx}>
|
|
148
|
-
<TestComp />
|
|
149
|
-
</TestWrapper>,
|
|
150
|
-
);
|
|
151
|
-
expect(screen.getByTestId('result')).toHaveTextContent('false');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test('evaluates multiple AND conditions', () => {
|
|
155
|
-
function TestComp() {
|
|
156
|
-
const result = useCondition([
|
|
157
|
-
{ field: 'a', operator: 'gt', value: 0 },
|
|
158
|
-
{ field: 'b', operator: 'notEmpty' },
|
|
159
|
-
]);
|
|
160
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
161
|
-
}
|
|
162
|
-
const ctx = createRootContext({ a: 5, b: 'yes' }, 'test', 'view');
|
|
163
|
-
render(
|
|
164
|
-
<TestWrapper ctx={ctx}>
|
|
165
|
-
<TestComp />
|
|
166
|
-
</TestWrapper>,
|
|
167
|
-
);
|
|
168
|
-
expect(screen.getByTestId('result')).toHaveTextContent('true');
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
describe('usePageState hook', () => {
|
|
173
|
-
test('throws outside provider', () => {
|
|
174
|
-
function TestComp() {
|
|
175
|
-
usePageState();
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
expect(() => render(<TestComp />)).toThrow(
|
|
179
|
-
'usePageState must be used within a PageStateProvider',
|
|
180
|
-
);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
test('returns the state store', () => {
|
|
184
|
-
const store = new StateStore();
|
|
185
|
-
store.set('test', 42);
|
|
186
|
-
function TestComp() {
|
|
187
|
-
const state = usePageState();
|
|
188
|
-
return <div data-testid="result">{String(state.get('test'))}</div>;
|
|
189
|
-
}
|
|
190
|
-
render(
|
|
191
|
-
<PageStateProvider value={store}>
|
|
192
|
-
<TestComp />
|
|
193
|
-
</PageStateProvider>,
|
|
194
|
-
);
|
|
195
|
-
expect(screen.getByTestId('result')).toHaveTextContent('42');
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
describe('Hook Edge Cases', () => {
|
|
200
|
-
test('useBind with missing field returns undefined value', () => {
|
|
201
|
-
function TestComp() {
|
|
202
|
-
const result = useBind({ field: 'nonexistent' });
|
|
203
|
-
return <div data-testid="result">{result?.value === undefined ? 'undef' : 'has'}</div>;
|
|
204
|
-
}
|
|
205
|
-
const ctx = createRootContext({}, 'test', 'view');
|
|
206
|
-
render(
|
|
207
|
-
<TestWrapper ctx={ctx}>
|
|
208
|
-
<TestComp />
|
|
209
|
-
</TestWrapper>,
|
|
210
|
-
);
|
|
211
|
-
expect(screen.getByTestId('result')).toHaveTextContent('undef');
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test('useExpression with complex nested expression', () => {
|
|
215
|
-
function TestComp() {
|
|
216
|
-
const result = useExpression('{{if(qty > 0, qty * rate, 0)}}');
|
|
217
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
218
|
-
}
|
|
219
|
-
const ctx = createRootContext({ qty: 3, rate: 10 }, 'test', 'view');
|
|
220
|
-
render(
|
|
221
|
-
<TestWrapper ctx={ctx}>
|
|
222
|
-
<TestComp />
|
|
223
|
-
</TestWrapper>,
|
|
224
|
-
);
|
|
225
|
-
expect(screen.getByTestId('result')).toHaveTextContent('30');
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
test('useExpression returns 0 when qty is 0', () => {
|
|
229
|
-
function TestComp() {
|
|
230
|
-
const result = useExpression('{{if(qty > 0, qty * rate, 0)}}');
|
|
231
|
-
return <div data-testid="result">{String(result)}</div>;
|
|
232
|
-
}
|
|
233
|
-
const ctx = createRootContext({ qty: 0, rate: 10 }, 'test', 'view');
|
|
234
|
-
render(
|
|
235
|
-
<TestWrapper ctx={ctx}>
|
|
236
|
-
<TestComp />
|
|
237
|
-
</TestWrapper>,
|
|
238
|
-
);
|
|
239
|
-
expect(screen.getByTestId('result')).toHaveTextContent('0');
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
test('useWidgetContext throws outside provider', () => {
|
|
243
|
-
function TestComp() {
|
|
244
|
-
const ctx = useWidgetContext();
|
|
245
|
-
return <div>{ctx.model}</div>;
|
|
246
|
-
}
|
|
247
|
-
expect(() => render(<TestComp />)).toThrow();
|
|
248
|
-
});
|
|
249
|
-
});
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { render, fireEvent, cleanup } from '@testing-library/react';
|
|
4
|
-
import { IconWidget } from '../components/IconWidget.js';
|
|
5
|
-
|
|
6
|
-
afterEach(() => {
|
|
7
|
-
cleanup();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
describe('IconWidget', () => {
|
|
11
|
-
it('renders default circle icon when no name provided', () => {
|
|
12
|
-
const { container } = render(
|
|
13
|
-
<IconWidget
|
|
14
|
-
props={{}}
|
|
15
|
-
bind={{ value: undefined }}
|
|
16
|
-
on={{}}
|
|
17
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
18
|
-
/>,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const svg = container.querySelector('svg');
|
|
22
|
-
expect(svg).toBeInTheDocument();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('passes custom icon name to Icon component', () => {
|
|
26
|
-
const { container } = render(
|
|
27
|
-
<IconWidget
|
|
28
|
-
props={{ name: 'arrow-right' }}
|
|
29
|
-
bind={{ value: undefined }}
|
|
30
|
-
on={{}}
|
|
31
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
32
|
-
/>,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const svg = container.querySelector('svg');
|
|
36
|
-
expect(svg).toBeInTheDocument();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('renders with default size of 14', () => {
|
|
40
|
-
const { container } = render(
|
|
41
|
-
<IconWidget
|
|
42
|
-
props={{}}
|
|
43
|
-
bind={{ value: undefined }}
|
|
44
|
-
on={{}}
|
|
45
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
46
|
-
/>,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const svg = container.querySelector('svg');
|
|
50
|
-
expect(svg).toHaveAttribute('width', '14');
|
|
51
|
-
expect(svg).toHaveAttribute('height', '14');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('passes custom size prop through to SVG', () => {
|
|
55
|
-
const { container } = render(
|
|
56
|
-
<IconWidget
|
|
57
|
-
props={{ size: 24 }}
|
|
58
|
-
bind={{ value: undefined }}
|
|
59
|
-
on={{}}
|
|
60
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
61
|
-
/>,
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const svg = container.querySelector('svg');
|
|
65
|
-
expect(svg).toHaveAttribute('width', '24');
|
|
66
|
-
expect(svg).toHaveAttribute('height', '24');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('passes color prop through to SVG', () => {
|
|
70
|
-
const { container } = render(
|
|
71
|
-
<IconWidget
|
|
72
|
-
props={{ color: 'red' }}
|
|
73
|
-
bind={{ value: undefined }}
|
|
74
|
-
on={{}}
|
|
75
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
76
|
-
/>,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const svg = container.querySelector('svg');
|
|
80
|
-
expect(svg).toHaveAttribute('stroke', 'red');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('fires on.click when clicked', () => {
|
|
84
|
-
const handleClick = vi.fn();
|
|
85
|
-
|
|
86
|
-
const { container } = render(
|
|
87
|
-
<IconWidget
|
|
88
|
-
props={{ name: 'circle' }}
|
|
89
|
-
bind={{ value: undefined }}
|
|
90
|
-
on={{ click: handleClick }}
|
|
91
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
92
|
-
/>,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const span = container.firstElementChild as HTMLElement;
|
|
96
|
-
fireEvent.click(span);
|
|
97
|
-
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('adds cursor-pointer class when on.click exists', () => {
|
|
101
|
-
const handleClick = vi.fn();
|
|
102
|
-
|
|
103
|
-
const { container } = render(
|
|
104
|
-
<IconWidget
|
|
105
|
-
props={{ name: 'circle' }}
|
|
106
|
-
bind={{ value: undefined }}
|
|
107
|
-
on={{ click: handleClick }}
|
|
108
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
109
|
-
/>,
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const span = container.firstElementChild as HTMLElement;
|
|
113
|
-
expect(span.className).toContain('cursor-pointer');
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('does not add cursor-pointer class when on.click is not provided', () => {
|
|
117
|
-
const { container } = render(
|
|
118
|
-
<IconWidget
|
|
119
|
-
props={{ name: 'circle' }}
|
|
120
|
-
bind={{ value: undefined }}
|
|
121
|
-
on={{}}
|
|
122
|
-
context={{ record: {}, model: '', mode: 'view' }}
|
|
123
|
-
/>,
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const span = container.firstElementChild as HTMLElement;
|
|
127
|
-
expect(span.className).not.toContain('cursor-pointer');
|
|
128
|
-
});
|
|
129
|
-
});
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { render, screen, fireEvent } from '@testing-library/react';
|
|
4
|
-
import { InputWidget } from '../components/InputWidget.js';
|
|
5
|
-
|
|
6
|
-
describe('InputWidget', () => {
|
|
7
|
-
const defaultProps = {
|
|
8
|
-
props: {},
|
|
9
|
-
bind: { value: undefined },
|
|
10
|
-
on: {},
|
|
11
|
-
context: { record: {}, model: '', mode: 'view' as const },
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
describe('label rendering', () => {
|
|
15
|
-
it('renders label from props', () => {
|
|
16
|
-
render(<InputWidget {...defaultProps} props={{ label: 'Email Address' }} />);
|
|
17
|
-
expect(screen.getByText('Email Address')).toBeDefined();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('renders label from bind.meta.label as fallback', () => {
|
|
21
|
-
render(
|
|
22
|
-
<InputWidget
|
|
23
|
-
{...defaultProps}
|
|
24
|
-
bind={{
|
|
25
|
-
value: '',
|
|
26
|
-
meta: { type: 'string', label: 'Username', required: false, readOnly: false },
|
|
27
|
-
}}
|
|
28
|
-
/>,
|
|
29
|
-
);
|
|
30
|
-
expect(screen.getByText('Username')).toBeDefined();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('prefers props.label over bind.meta.label', () => {
|
|
34
|
-
render(
|
|
35
|
-
<InputWidget
|
|
36
|
-
{...defaultProps}
|
|
37
|
-
props={{ label: 'Override Label' }}
|
|
38
|
-
bind={{
|
|
39
|
-
value: '',
|
|
40
|
-
meta: { type: 'string', label: 'Meta Label', required: false, readOnly: false },
|
|
41
|
-
}}
|
|
42
|
-
/>,
|
|
43
|
-
);
|
|
44
|
-
expect(screen.getByText('Override Label')).toBeDefined();
|
|
45
|
-
expect(screen.queryByText('Meta Label')).toBeNull();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('does not render label element when no label provided', () => {
|
|
49
|
-
const { container } = render(<InputWidget {...defaultProps} />);
|
|
50
|
-
expect(container.querySelector('label')).toBeNull();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('input type mapping', () => {
|
|
55
|
-
it('maps int field type to number input', () => {
|
|
56
|
-
const { container } = render(
|
|
57
|
-
<InputWidget
|
|
58
|
-
{...defaultProps}
|
|
59
|
-
bind={{
|
|
60
|
-
value: '',
|
|
61
|
-
meta: { type: 'int', label: 'Qty', required: false, readOnly: false },
|
|
62
|
-
}}
|
|
63
|
-
/>,
|
|
64
|
-
);
|
|
65
|
-
expect(container.querySelector('input')?.type).toBe('number');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('maps decimal field type to number input', () => {
|
|
69
|
-
const { container } = render(
|
|
70
|
-
<InputWidget
|
|
71
|
-
{...defaultProps}
|
|
72
|
-
bind={{
|
|
73
|
-
value: '',
|
|
74
|
-
meta: { type: 'decimal', label: 'Price', required: false, readOnly: false },
|
|
75
|
-
}}
|
|
76
|
-
/>,
|
|
77
|
-
);
|
|
78
|
-
expect(container.querySelector('input')?.type).toBe('number');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('maps money field type to number input', () => {
|
|
82
|
-
const { container } = render(
|
|
83
|
-
<InputWidget
|
|
84
|
-
{...defaultProps}
|
|
85
|
-
bind={{
|
|
86
|
-
value: '',
|
|
87
|
-
meta: { type: 'money', label: 'Amount', required: false, readOnly: false },
|
|
88
|
-
}}
|
|
89
|
-
/>,
|
|
90
|
-
);
|
|
91
|
-
expect(container.querySelector('input')?.type).toBe('number');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('maps date field type to date input', () => {
|
|
95
|
-
const { container } = render(
|
|
96
|
-
<InputWidget
|
|
97
|
-
{...defaultProps}
|
|
98
|
-
bind={{
|
|
99
|
-
value: '',
|
|
100
|
-
meta: { type: 'date', label: 'Date', required: false, readOnly: false },
|
|
101
|
-
}}
|
|
102
|
-
/>,
|
|
103
|
-
);
|
|
104
|
-
expect(container.querySelector('input')?.type).toBe('date');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('defaults to text input for string field type', () => {
|
|
108
|
-
const { container } = render(
|
|
109
|
-
<InputWidget
|
|
110
|
-
{...defaultProps}
|
|
111
|
-
bind={{
|
|
112
|
-
value: '',
|
|
113
|
-
meta: { type: 'string', label: 'Name', required: false, readOnly: false },
|
|
114
|
-
}}
|
|
115
|
-
/>,
|
|
116
|
-
);
|
|
117
|
-
expect(container.querySelector('input')?.type).toBe('text');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('defaults to text input when no meta type provided', () => {
|
|
121
|
-
const { container } = render(<InputWidget {...defaultProps} bind={{ value: '' }} />);
|
|
122
|
-
expect(container.querySelector('input')?.type).toBe('text');
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
describe('props passthrough', () => {
|
|
127
|
-
it('sets placeholder from props', () => {
|
|
128
|
-
const { container } = render(
|
|
129
|
-
<InputWidget {...defaultProps} props={{ placeholder: 'Enter value...' }} />,
|
|
130
|
-
);
|
|
131
|
-
expect(container.querySelector('input')?.placeholder).toBe('Enter value...');
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('sets readOnly from props', () => {
|
|
135
|
-
const { container } = render(<InputWidget {...defaultProps} props={{ readOnly: true }} />);
|
|
136
|
-
expect(container.querySelector('input')?.readOnly).toBe(true);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('sets readOnly from bind.meta as fallback', () => {
|
|
140
|
-
const { container } = render(
|
|
141
|
-
<InputWidget
|
|
142
|
-
{...defaultProps}
|
|
143
|
-
bind={{
|
|
144
|
-
value: '',
|
|
145
|
-
meta: { type: 'string', label: 'Field', required: false, readOnly: true },
|
|
146
|
-
}}
|
|
147
|
-
/>,
|
|
148
|
-
);
|
|
149
|
-
expect(container.querySelector('input')?.readOnly).toBe(true);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('sets disabled from props', () => {
|
|
153
|
-
const { container } = render(<InputWidget {...defaultProps} props={{ disabled: true }} />);
|
|
154
|
-
expect(container.querySelector('input')?.disabled).toBe(true);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('passes min, max, step, and pattern as HTML attributes', () => {
|
|
158
|
-
const { container } = render(
|
|
159
|
-
<InputWidget
|
|
160
|
-
{...defaultProps}
|
|
161
|
-
props={{ min: 0, max: 100, step: 5, pattern: '[0-9]+' }}
|
|
162
|
-
bind={{
|
|
163
|
-
value: '',
|
|
164
|
-
meta: { type: 'int', label: 'Score', required: false, readOnly: false },
|
|
165
|
-
}}
|
|
166
|
-
/>,
|
|
167
|
-
);
|
|
168
|
-
const input = container.querySelector('input')!;
|
|
169
|
-
expect(input.min).toBe('0');
|
|
170
|
-
expect(input.max).toBe('100');
|
|
171
|
-
expect(input.step).toBe('5');
|
|
172
|
-
expect(input.pattern).toBe('[0-9]+');
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('value binding', () => {
|
|
177
|
-
it('displays bind.value in the input', () => {
|
|
178
|
-
const { container } = render(
|
|
179
|
-
<InputWidget {...defaultProps} bind={{ value: 'Hello World' }} />,
|
|
180
|
-
);
|
|
181
|
-
expect(container.querySelector('input')?.value).toBe('Hello World');
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('displays empty string when bind.value is null', () => {
|
|
185
|
-
const { container } = render(<InputWidget {...defaultProps} bind={{ value: null }} />);
|
|
186
|
-
expect(container.querySelector('input')?.value).toBe('');
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('displays empty string when bind.value is undefined', () => {
|
|
190
|
-
const { container } = render(<InputWidget {...defaultProps} bind={{ value: undefined }} />);
|
|
191
|
-
expect(container.querySelector('input')?.value).toBe('');
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
describe('event triggers', () => {
|
|
196
|
-
it('calls bind.setValue and on.change on input change', () => {
|
|
197
|
-
const setValue = vi.fn();
|
|
198
|
-
const onChange = vi.fn();
|
|
199
|
-
|
|
200
|
-
const { container } = render(
|
|
201
|
-
<InputWidget {...defaultProps} bind={{ value: '', setValue }} on={{ change: onChange }} />,
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
fireEvent.change(container.querySelector('input')!, { target: { value: 'new value' } });
|
|
205
|
-
|
|
206
|
-
expect(setValue).toHaveBeenCalledWith('new value');
|
|
207
|
-
expect(onChange).toHaveBeenCalledWith('new value');
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('calls on.focus on input focus', () => {
|
|
211
|
-
const onFocus = vi.fn();
|
|
212
|
-
|
|
213
|
-
const { container } = render(<InputWidget {...defaultProps} on={{ focus: onFocus }} />);
|
|
214
|
-
|
|
215
|
-
fireEvent.focus(container.querySelector('input')!);
|
|
216
|
-
|
|
217
|
-
expect(onFocus).toHaveBeenCalledTimes(1);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('calls on.blur on input blur', () => {
|
|
221
|
-
const onBlur = vi.fn();
|
|
222
|
-
|
|
223
|
-
const { container } = render(<InputWidget {...defaultProps} on={{ blur: onBlur }} />);
|
|
224
|
-
|
|
225
|
-
fireEvent.blur(container.querySelector('input')!);
|
|
226
|
-
|
|
227
|
-
expect(onBlur).toHaveBeenCalledTimes(1);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('does not throw when on.change is not provided', () => {
|
|
231
|
-
const setValue = vi.fn();
|
|
232
|
-
const { container } = render(
|
|
233
|
-
<InputWidget {...defaultProps} bind={{ value: '', setValue }} on={{}} />,
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
expect(() => {
|
|
237
|
-
fireEvent.change(container.querySelector('input')!, { target: { value: 'x' } });
|
|
238
|
-
}).not.toThrow();
|
|
239
|
-
expect(setValue).toHaveBeenCalledWith('x');
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('does not throw when bind.setValue is not provided', () => {
|
|
243
|
-
const onChange = vi.fn();
|
|
244
|
-
const { container } = render(
|
|
245
|
-
<InputWidget {...defaultProps} bind={{ value: '' }} on={{ change: onChange }} />,
|
|
246
|
-
);
|
|
247
|
-
|
|
248
|
-
expect(() => {
|
|
249
|
-
fireEvent.change(container.querySelector('input')!, { target: { value: 'x' } });
|
|
250
|
-
}).not.toThrow();
|
|
251
|
-
expect(onChange).toHaveBeenCalledWith('x');
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
describe('widgetMeta', () => {
|
|
256
|
-
it('has correct metadata', () => {
|
|
257
|
-
expect(InputWidget.widgetMeta.name).toBe('input');
|
|
258
|
-
expect(InputWidget.widgetMeta.category).toBe('input');
|
|
259
|
-
expect(InputWidget.widgetMeta.binding).toBe('field');
|
|
260
|
-
expect(InputWidget.widgetMeta.container).toBe(false);
|
|
261
|
-
expect(InputWidget.widgetMeta.triggers).toEqual(['change', 'focus', 'blur']);
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
});
|