@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,236 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, vi } from 'vitest';
|
|
2
|
-
import { dispatch } from '../action/dispatcher.js';
|
|
3
|
-
import { StateStore } from '../state/store.js';
|
|
4
|
-
import { createRootContext } from '../context/builder.js';
|
|
5
|
-
import type { ActionContext, ActionHandlers } from '../action/dispatcher.js';
|
|
6
|
-
|
|
7
|
-
function makeActionCtx(record: Record<string, unknown> = {}): ActionContext {
|
|
8
|
-
return {
|
|
9
|
-
widgetContext: createRootContext(record, 'sales.order', 'edit'),
|
|
10
|
-
state: new StateStore(),
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
describe('Action Dispatcher', () => {
|
|
15
|
-
describe('setValue', () => {
|
|
16
|
-
test('sets record field via handler', async () => {
|
|
17
|
-
const sets: [string, unknown][] = [];
|
|
18
|
-
const handlers: ActionHandlers = { setRecordValue: (f, v) => sets.push([f, v]) };
|
|
19
|
-
const ctx = makeActionCtx({ qty: 5, rate: 100 });
|
|
20
|
-
await dispatch({ type: 'setValue', field: 'qty', value: 10 }, ctx, handlers);
|
|
21
|
-
expect(sets).toEqual([['qty', 10]]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('sets $state key', async () => {
|
|
25
|
-
const ctx = makeActionCtx();
|
|
26
|
-
await dispatch({ type: 'setValue', field: '$state.step', value: 2 }, ctx, {});
|
|
27
|
-
expect(ctx.state.get('step')).toBe(2);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('resolves expression in value', async () => {
|
|
31
|
-
const sets: [string, unknown][] = [];
|
|
32
|
-
const handlers: ActionHandlers = { setRecordValue: (f, v) => sets.push([f, v]) };
|
|
33
|
-
const ctx = makeActionCtx({ qty: 5, rate: 100 });
|
|
34
|
-
await dispatch({ type: 'setValue', field: 'amount', value: '{{qty * rate}}' }, ctx, handlers);
|
|
35
|
-
expect(sets).toEqual([['amount', 500]]);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('clearValue', () => {
|
|
40
|
-
test('sets field to null', async () => {
|
|
41
|
-
const sets: [string, unknown][] = [];
|
|
42
|
-
const handlers: ActionHandlers = { setRecordValue: (f, v) => sets.push([f, v]) };
|
|
43
|
-
await dispatch({ type: 'clearValue', field: 'name' }, makeActionCtx(), handlers);
|
|
44
|
-
expect(sets).toEqual([['name', null]]);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('setValues', () => {
|
|
49
|
-
test('sets multiple fields', async () => {
|
|
50
|
-
const sets: [string, unknown][] = [];
|
|
51
|
-
const handlers: ActionHandlers = { setRecordValue: (f, v) => sets.push([f, v]) };
|
|
52
|
-
const ctx = makeActionCtx();
|
|
53
|
-
await dispatch(
|
|
54
|
-
{ type: 'setValues', values: { status: 'submitted', '$state.loading': true } },
|
|
55
|
-
ctx,
|
|
56
|
-
handlers,
|
|
57
|
-
);
|
|
58
|
-
expect(sets).toEqual([['status', 'submitted']]);
|
|
59
|
-
expect(ctx.state.get('loading')).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('navigate', () => {
|
|
64
|
-
test('calls navigate handler with resolved path', async () => {
|
|
65
|
-
const paths: string[] = [];
|
|
66
|
-
const handlers: ActionHandlers = { navigate: (p) => paths.push(p) };
|
|
67
|
-
const ctx = makeActionCtx({ id: '42' });
|
|
68
|
-
await dispatch({ type: 'navigate', path: '/orders/{{id}}' }, ctx, handlers);
|
|
69
|
-
expect(paths).toEqual(['/orders/42']);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('service', () => {
|
|
74
|
-
test('calls service and runs onSuccess', async () => {
|
|
75
|
-
const serviceCall = vi.fn().mockResolvedValue({ price: 99 });
|
|
76
|
-
const sets: [string, unknown][] = [];
|
|
77
|
-
const handlers: ActionHandlers = {
|
|
78
|
-
service: serviceCall,
|
|
79
|
-
setRecordValue: (f, v) => sets.push([f, v]),
|
|
80
|
-
};
|
|
81
|
-
const ctx = makeActionCtx({ product_id: 'P1' });
|
|
82
|
-
await dispatch(
|
|
83
|
-
{
|
|
84
|
-
type: 'service',
|
|
85
|
-
name: 'sales.getPrice',
|
|
86
|
-
params: { id: '{{product_id}}' },
|
|
87
|
-
onSuccess: { type: 'setValue', field: 'rate', value: '{{$response.price}}' },
|
|
88
|
-
},
|
|
89
|
-
ctx,
|
|
90
|
-
handlers,
|
|
91
|
-
);
|
|
92
|
-
expect(serviceCall).toHaveBeenCalledWith('sales.getPrice', { id: 'P1' });
|
|
93
|
-
expect(sets).toEqual([['rate', 99]]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('calls onError on failure', async () => {
|
|
97
|
-
const serviceCall = vi.fn().mockRejectedValue(new Error('Network error'));
|
|
98
|
-
const ctx = makeActionCtx();
|
|
99
|
-
const handlers: ActionHandlers = { service: serviceCall };
|
|
100
|
-
await dispatch(
|
|
101
|
-
{
|
|
102
|
-
type: 'service',
|
|
103
|
-
name: 'sales.submit',
|
|
104
|
-
onError: { type: 'setValue', field: '$state.error', value: '{{$response.message}}' },
|
|
105
|
-
},
|
|
106
|
-
ctx,
|
|
107
|
-
handlers,
|
|
108
|
-
);
|
|
109
|
-
expect(ctx.state.get('error')).toBe('Network error');
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('refreshes source by default on success without onSuccess', async () => {
|
|
113
|
-
const serviceCall = vi.fn().mockResolvedValue({});
|
|
114
|
-
const refreshSource = vi.fn();
|
|
115
|
-
const handlers: ActionHandlers = { service: serviceCall, refreshSource };
|
|
116
|
-
await dispatch({ type: 'service', name: 'sales.submit' }, makeActionCtx(), handlers);
|
|
117
|
-
expect(refreshSource).toHaveBeenCalled();
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('model actions', () => {
|
|
122
|
-
test('model.create resolves expressions in data', async () => {
|
|
123
|
-
const modelCreate = vi.fn().mockResolvedValue({});
|
|
124
|
-
const handlers: ActionHandlers = { modelCreate };
|
|
125
|
-
const ctx = makeActionCtx({ customer: 'CUST-001' });
|
|
126
|
-
await dispatch(
|
|
127
|
-
{ type: 'model.create', model: 'sales.order', data: { customer_id: '{{customer}}' } },
|
|
128
|
-
ctx,
|
|
129
|
-
handlers,
|
|
130
|
-
);
|
|
131
|
-
expect(modelCreate).toHaveBeenCalledWith('sales.order', { customer_id: 'CUST-001' });
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('model.update infers model and id from context', async () => {
|
|
135
|
-
const modelUpdate = vi.fn().mockResolvedValue({});
|
|
136
|
-
const handlers: ActionHandlers = { modelUpdate };
|
|
137
|
-
const ctx = makeActionCtx({ id: '42', status: 'draft' });
|
|
138
|
-
await dispatch({ type: 'model.update', data: { status: 'submitted' } }, ctx, handlers);
|
|
139
|
-
expect(modelUpdate).toHaveBeenCalledWith('sales.order', '42', { status: 'submitted' });
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('model.delete infers model and id from context', async () => {
|
|
143
|
-
const modelDelete = vi.fn().mockResolvedValue(undefined);
|
|
144
|
-
const handlers: ActionHandlers = { modelDelete };
|
|
145
|
-
const ctx = makeActionCtx({ id: '42' });
|
|
146
|
-
await dispatch({ type: 'model.delete' }, ctx, handlers);
|
|
147
|
-
expect(modelDelete).toHaveBeenCalledWith('sales.order', '42');
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('sequence', () => {
|
|
152
|
-
test('runs actions in order', async () => {
|
|
153
|
-
const order: string[] = [];
|
|
154
|
-
const handlers: ActionHandlers = {
|
|
155
|
-
setRecordValue: (f) => order.push(f),
|
|
156
|
-
};
|
|
157
|
-
const ctx = makeActionCtx();
|
|
158
|
-
await dispatch(
|
|
159
|
-
{
|
|
160
|
-
type: 'sequence',
|
|
161
|
-
actions: [
|
|
162
|
-
{ type: 'setValue', field: 'a', value: 1 },
|
|
163
|
-
{ type: 'setValue', field: 'b', value: 2 },
|
|
164
|
-
{ type: 'setValue', field: 'c', value: 3 },
|
|
165
|
-
],
|
|
166
|
-
},
|
|
167
|
-
ctx,
|
|
168
|
-
handlers,
|
|
169
|
-
);
|
|
170
|
-
expect(order).toEqual(['a', 'b', 'c']);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
describe('conditional', () => {
|
|
175
|
-
test('runs then branch when condition passes', async () => {
|
|
176
|
-
const ctx = makeActionCtx({ status: 'draft' });
|
|
177
|
-
await dispatch(
|
|
178
|
-
{
|
|
179
|
-
type: 'conditional',
|
|
180
|
-
condition: { field: 'status', operator: 'eq', value: 'draft' },
|
|
181
|
-
then: { type: 'setValue', field: '$state.canEdit', value: true },
|
|
182
|
-
},
|
|
183
|
-
ctx,
|
|
184
|
-
{},
|
|
185
|
-
);
|
|
186
|
-
expect(ctx.state.get('canEdit')).toBe(true);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('runs else branch when condition fails', async () => {
|
|
190
|
-
const ctx = makeActionCtx({ status: 'submitted' });
|
|
191
|
-
await dispatch(
|
|
192
|
-
{
|
|
193
|
-
type: 'conditional',
|
|
194
|
-
condition: { field: 'status', operator: 'eq', value: 'draft' },
|
|
195
|
-
then: { type: 'setValue', field: '$state.canEdit', value: true },
|
|
196
|
-
else: { type: 'setValue', field: '$state.canEdit', value: false },
|
|
197
|
-
},
|
|
198
|
-
ctx,
|
|
199
|
-
{},
|
|
200
|
-
);
|
|
201
|
-
expect(ctx.state.get('canEdit')).toBe(false);
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe('simple handlers', () => {
|
|
206
|
-
test('refreshSource calls handler', async () => {
|
|
207
|
-
const refreshSource = vi.fn();
|
|
208
|
-
await dispatch({ type: 'refreshSource' }, makeActionCtx(), { refreshSource });
|
|
209
|
-
expect(refreshSource).toHaveBeenCalled();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test('focus calls handler', async () => {
|
|
213
|
-
const focus = vi.fn();
|
|
214
|
-
await dispatch({ type: 'focus', field: 'name' }, makeActionCtx(), { focus });
|
|
215
|
-
expect(focus).toHaveBeenCalledWith('name');
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test('addRow calls handler', async () => {
|
|
219
|
-
const addRow = vi.fn();
|
|
220
|
-
await dispatch({ type: 'addRow', field: 'items' }, makeActionCtx(), { addRow });
|
|
221
|
-
expect(addRow).toHaveBeenCalledWith('items');
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test('removeRow calls handler', async () => {
|
|
225
|
-
const removeRow = vi.fn();
|
|
226
|
-
await dispatch({ type: 'removeRow', field: 'items' }, makeActionCtx(), { removeRow });
|
|
227
|
-
expect(removeRow).toHaveBeenCalledWith('items');
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
test('duplicateRow calls handler', async () => {
|
|
231
|
-
const duplicateRow = vi.fn();
|
|
232
|
-
await dispatch({ type: 'duplicateRow', field: 'items' }, makeActionCtx(), { duplicateRow });
|
|
233
|
-
expect(duplicateRow).toHaveBeenCalledWith('items');
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
});
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
|
|
4
|
-
import { AttachmentWidget } from '../components/AttachmentWidget.js';
|
|
5
|
-
|
|
6
|
-
const defaultProps = {
|
|
7
|
-
props: {},
|
|
8
|
-
bind: { value: null },
|
|
9
|
-
on: {},
|
|
10
|
-
context: { record: {}, model: '', mode: 'view' as const },
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
afterEach(() => cleanup());
|
|
14
|
-
|
|
15
|
-
describe('AttachmentWidget', () => {
|
|
16
|
-
it('renders upload zone when no file', () => {
|
|
17
|
-
render(<AttachmentWidget {...defaultProps} />);
|
|
18
|
-
expect(screen.getByText('Drop a file here or click to browse')).toBeInTheDocument();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('displays label from props', () => {
|
|
22
|
-
render(<AttachmentWidget {...defaultProps} props={{ label: 'Logo' }} />);
|
|
23
|
-
expect(screen.getByText('Logo')).toBeInTheDocument();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('shows file name when value is set', () => {
|
|
27
|
-
render(
|
|
28
|
-
<AttachmentWidget {...defaultProps} bind={{ value: { name: 'report.pdf', size: 2048 } }} />,
|
|
29
|
-
);
|
|
30
|
-
expect(screen.getByText('report.pdf')).toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('shows file size', () => {
|
|
34
|
-
render(
|
|
35
|
-
<AttachmentWidget {...defaultProps} bind={{ value: { name: 'report.pdf', size: 2048 } }} />,
|
|
36
|
-
);
|
|
37
|
-
expect(screen.getByText('2.0 KB')).toBeInTheDocument();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('shows remove button when file exists', () => {
|
|
41
|
-
render(
|
|
42
|
-
<AttachmentWidget {...defaultProps} bind={{ value: { name: 'report.pdf', size: 1024 } }} />,
|
|
43
|
-
);
|
|
44
|
-
expect(screen.getByLabelText('Remove file')).toBeInTheDocument();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('fires on.remove when removing file', () => {
|
|
48
|
-
const onRemove = vi.fn();
|
|
49
|
-
const setValue = vi.fn();
|
|
50
|
-
render(
|
|
51
|
-
<AttachmentWidget
|
|
52
|
-
{...defaultProps}
|
|
53
|
-
bind={{ value: { name: 'x.pdf', size: 100 }, setValue }}
|
|
54
|
-
on={{ remove: onRemove }}
|
|
55
|
-
/>,
|
|
56
|
-
);
|
|
57
|
-
fireEvent.click(screen.getByLabelText('Remove file'));
|
|
58
|
-
expect(onRemove).toHaveBeenCalled();
|
|
59
|
-
expect(setValue).toHaveBeenCalledWith(null);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('handles disabled state - no upload zone click', () => {
|
|
63
|
-
render(<AttachmentWidget {...defaultProps} props={{ disabled: true }} />);
|
|
64
|
-
const zone = screen.getByRole('button', { name: 'Upload file' });
|
|
65
|
-
expect(zone.className).toContain('cursor-not-allowed');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('handles null bind.value gracefully', () => {
|
|
69
|
-
render(<AttachmentWidget {...defaultProps} bind={{ value: null }} />);
|
|
70
|
-
expect(screen.getByText('Drop a file here or click to browse')).toBeInTheDocument();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('falls back to bind.meta.label', () => {
|
|
74
|
-
render(
|
|
75
|
-
<AttachmentWidget
|
|
76
|
-
{...defaultProps}
|
|
77
|
-
bind={{
|
|
78
|
-
value: null,
|
|
79
|
-
meta: { type: 'attachment', label: 'Document', required: false, readOnly: false },
|
|
80
|
-
}}
|
|
81
|
-
/>,
|
|
82
|
-
);
|
|
83
|
-
expect(screen.getByText('Document')).toBeInTheDocument();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
|
|
4
|
-
import { AttachmentsWidget } from '../components/AttachmentsWidget.js';
|
|
5
|
-
|
|
6
|
-
const defaultProps = {
|
|
7
|
-
props: {},
|
|
8
|
-
bind: { value: [] },
|
|
9
|
-
on: {},
|
|
10
|
-
context: { record: {}, model: '', mode: 'view' as const },
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
afterEach(() => cleanup());
|
|
14
|
-
|
|
15
|
-
describe('AttachmentsWidget', () => {
|
|
16
|
-
it('renders upload zone when no files', () => {
|
|
17
|
-
render(<AttachmentsWidget {...defaultProps} />);
|
|
18
|
-
expect(screen.getByText(/Drop files here/)).toBeInTheDocument();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('displays label from props', () => {
|
|
22
|
-
render(<AttachmentsWidget {...defaultProps} props={{ label: 'Documents' }} />);
|
|
23
|
-
expect(screen.getByText('Documents')).toBeInTheDocument();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('shows file list when files exist', () => {
|
|
27
|
-
render(
|
|
28
|
-
<AttachmentsWidget
|
|
29
|
-
{...defaultProps}
|
|
30
|
-
bind={{
|
|
31
|
-
value: [
|
|
32
|
-
{ name: 'a.pdf', size: 1024 },
|
|
33
|
-
{ name: 'b.pdf', size: 2048 },
|
|
34
|
-
],
|
|
35
|
-
}}
|
|
36
|
-
/>,
|
|
37
|
-
);
|
|
38
|
-
expect(screen.getByText('a.pdf')).toBeInTheDocument();
|
|
39
|
-
expect(screen.getByText('b.pdf')).toBeInTheDocument();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('shows file sizes', () => {
|
|
43
|
-
render(
|
|
44
|
-
<AttachmentsWidget {...defaultProps} bind={{ value: [{ name: 'a.pdf', size: 2048 }] }} />,
|
|
45
|
-
);
|
|
46
|
-
expect(screen.getByText('2.0 KB')).toBeInTheDocument();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('shows remove button per file', () => {
|
|
50
|
-
render(
|
|
51
|
-
<AttachmentsWidget {...defaultProps} bind={{ value: [{ name: 'a.pdf', size: 100 }] }} />,
|
|
52
|
-
);
|
|
53
|
-
expect(screen.getByLabelText('Remove a.pdf')).toBeInTheDocument();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('fires on.remove with index when removing', () => {
|
|
57
|
-
const onRemove = vi.fn();
|
|
58
|
-
const setValue = vi.fn();
|
|
59
|
-
render(
|
|
60
|
-
<AttachmentsWidget
|
|
61
|
-
{...defaultProps}
|
|
62
|
-
bind={{
|
|
63
|
-
value: [
|
|
64
|
-
{ name: 'a.pdf', size: 100 },
|
|
65
|
-
{ name: 'b.pdf', size: 200 },
|
|
66
|
-
],
|
|
67
|
-
setValue,
|
|
68
|
-
}}
|
|
69
|
-
on={{ remove: onRemove }}
|
|
70
|
-
/>,
|
|
71
|
-
);
|
|
72
|
-
fireEvent.click(screen.getByLabelText('Remove b.pdf'));
|
|
73
|
-
expect(onRemove).toHaveBeenCalledWith(1);
|
|
74
|
-
expect(setValue).toHaveBeenCalledWith([{ name: 'a.pdf', size: 100 }]);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('shows count in upload zone', () => {
|
|
78
|
-
render(
|
|
79
|
-
<AttachmentsWidget
|
|
80
|
-
{...defaultProps}
|
|
81
|
-
props={{ maxCount: 5 }}
|
|
82
|
-
bind={{ value: [{ name: 'a.pdf', size: 100 }] }}
|
|
83
|
-
/>,
|
|
84
|
-
);
|
|
85
|
-
expect(screen.getByText(/1\/5/)).toBeInTheDocument();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('hides upload zone when max reached', () => {
|
|
89
|
-
render(
|
|
90
|
-
<AttachmentsWidget
|
|
91
|
-
{...defaultProps}
|
|
92
|
-
props={{ maxCount: 1 }}
|
|
93
|
-
bind={{ value: [{ name: 'a.pdf', size: 100 }] }}
|
|
94
|
-
/>,
|
|
95
|
-
);
|
|
96
|
-
expect(screen.queryByRole('button', { name: 'Upload files' })).not.toBeInTheDocument();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('handles disabled state', () => {
|
|
100
|
-
render(<AttachmentsWidget {...defaultProps} props={{ disabled: true }} />);
|
|
101
|
-
const zone = screen.getByRole('button', { name: 'Upload files' });
|
|
102
|
-
expect(zone.className).toContain('cursor-not-allowed');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('handles null bind.value gracefully', () => {
|
|
106
|
-
render(<AttachmentsWidget {...defaultProps} bind={{ value: null }} />);
|
|
107
|
-
expect(screen.getByText(/Drop files here/)).toBeInTheDocument();
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'vitest';
|
|
2
|
-
import { resolveBinding } from '../binding/resolver.js';
|
|
3
|
-
import { createRootContext } from '../context/builder.js';
|
|
4
|
-
import type { FieldMeta } from '../binding/resolver.js';
|
|
5
|
-
|
|
6
|
-
describe('Binding Resolver', () => {
|
|
7
|
-
const ctx = createRootContext(
|
|
8
|
-
{ id: '1', customer_id: 'CUST-001', qty: 5, rate: 100, name: 'Test Order' },
|
|
9
|
-
'sales.order',
|
|
10
|
-
'edit',
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
const fieldMeta: Record<string, FieldMeta> = {
|
|
14
|
-
customer_id: { type: 'link', label: 'Customer', required: true, readOnly: false },
|
|
15
|
-
qty: { type: 'int', label: 'Quantity', required: true, readOnly: false },
|
|
16
|
-
name: { type: 'string', label: 'Order Name', required: false, readOnly: false },
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
test('returns null when no binding', () => {
|
|
20
|
-
expect(resolveBinding(undefined, ctx)).toBeNull();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('field binding returns value from context', () => {
|
|
24
|
-
const result = resolveBinding({ field: 'customer_id' }, ctx, fieldMeta);
|
|
25
|
-
expect(result).not.toBeNull();
|
|
26
|
-
expect(result!.value).toBe('CUST-001');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('field binding returns metadata', () => {
|
|
30
|
-
const result = resolveBinding({ field: 'customer_id' }, ctx, fieldMeta);
|
|
31
|
-
expect(result!.meta).toEqual({
|
|
32
|
-
type: 'link',
|
|
33
|
-
label: 'Customer',
|
|
34
|
-
required: true,
|
|
35
|
-
readOnly: false,
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('field binding provides setValue when handler given', () => {
|
|
40
|
-
const sets: [string, unknown][] = [];
|
|
41
|
-
const setter = (field: string, val: unknown) => sets.push([field, val]);
|
|
42
|
-
const result = resolveBinding({ field: 'qty' }, ctx, fieldMeta, setter);
|
|
43
|
-
expect(result!.setValue).toBeDefined();
|
|
44
|
-
result!.setValue!(10);
|
|
45
|
-
expect(sets).toEqual([['qty', 10]]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('field binding without setter has no setValue', () => {
|
|
49
|
-
const result = resolveBinding({ field: 'qty' }, ctx, fieldMeta);
|
|
50
|
-
expect(result!.setValue).toBeUndefined();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('expression binding evaluates expression', () => {
|
|
54
|
-
const result = resolveBinding({ expression: '{{qty * rate}}' }, ctx);
|
|
55
|
-
expect(result!.value).toBe(500);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('expression binding has no setValue', () => {
|
|
59
|
-
const result = resolveBinding({ expression: '{{qty * rate}}' }, ctx);
|
|
60
|
-
expect(result!.setValue).toBeUndefined();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('model binding returns query config', () => {
|
|
64
|
-
const result = resolveBinding(
|
|
65
|
-
{ model: { name: 'sales.order', filters: { status: 'draft' }, limit: 10 } },
|
|
66
|
-
ctx,
|
|
67
|
-
);
|
|
68
|
-
expect(result!.query).toEqual({ name: 'sales.order', filters: { status: 'draft' }, limit: 10 });
|
|
69
|
-
expect(result!.value).toBeNull();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('field binding returns undefined for missing field', () => {
|
|
73
|
-
const result = resolveBinding({ field: 'missing' }, ctx, fieldMeta);
|
|
74
|
-
expect(result!.value).toBeUndefined();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
|
|
4
|
-
import { ButtonWidget } from '../components/ButtonWidget.js';
|
|
5
|
-
|
|
6
|
-
afterEach(() => {
|
|
7
|
-
cleanup();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
function renderButton(
|
|
11
|
-
overrides: {
|
|
12
|
-
props?: Record<string, unknown>;
|
|
13
|
-
on?: Record<string, (...args: unknown[]) => void>;
|
|
14
|
-
} = {},
|
|
15
|
-
) {
|
|
16
|
-
const defaultProps = {
|
|
17
|
-
props: { label: 'Click me', ...overrides.props },
|
|
18
|
-
bind: { value: undefined },
|
|
19
|
-
on: { click: vi.fn(), ...overrides.on },
|
|
20
|
-
context: { record: {}, model: '', mode: 'view' as const },
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return { ...render(<ButtonWidget {...defaultProps} />), on: defaultProps.on };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('ButtonWidget', () => {
|
|
27
|
-
describe('rendering', () => {
|
|
28
|
-
it('renders with label text', () => {
|
|
29
|
-
renderButton({ props: { label: 'Save' } });
|
|
30
|
-
expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('renders default button without crashing', () => {
|
|
34
|
-
renderButton();
|
|
35
|
-
expect(screen.getByRole('button', { name: 'Click me' })).toBeInTheDocument();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('variants', () => {
|
|
40
|
-
it('renders primary variant (maps to default)', () => {
|
|
41
|
-
renderButton({ props: { variant: 'primary' } });
|
|
42
|
-
const button = screen.getByRole('button');
|
|
43
|
-
expect(button.className).toContain('bg-primary');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('renders secondary variant', () => {
|
|
47
|
-
renderButton({ props: { variant: 'secondary' } });
|
|
48
|
-
const button = screen.getByRole('button');
|
|
49
|
-
expect(button.className).toContain('bg-secondary');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('renders ghost variant', () => {
|
|
53
|
-
renderButton({ props: { variant: 'ghost' } });
|
|
54
|
-
const button = screen.getByRole('button');
|
|
55
|
-
expect(button.className).not.toContain('bg-primary');
|
|
56
|
-
expect(button.className).not.toContain('bg-destructive');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('renders destructive variant', () => {
|
|
60
|
-
renderButton({ props: { variant: 'destructive' } });
|
|
61
|
-
const button = screen.getByRole('button');
|
|
62
|
-
expect(button.className).toContain('destructive');
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('sizes', () => {
|
|
67
|
-
it('renders sm size', () => {
|
|
68
|
-
renderButton({ props: { size: 'sm' } });
|
|
69
|
-
const button = screen.getByRole('button');
|
|
70
|
-
expect(button.className).toContain('h-7');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('renders default size', () => {
|
|
74
|
-
renderButton({ props: { size: 'md' } });
|
|
75
|
-
const button = screen.getByRole('button');
|
|
76
|
-
expect(button.className).toContain('h-8');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('renders lg size', () => {
|
|
80
|
-
renderButton({ props: { size: 'lg' } });
|
|
81
|
-
const button = screen.getByRole('button');
|
|
82
|
-
expect(button.className).toContain('h-9');
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('disabled', () => {
|
|
87
|
-
it('disables the button when disabled prop is true', () => {
|
|
88
|
-
renderButton({ props: { disabled: true } });
|
|
89
|
-
const button = screen.getByRole('button');
|
|
90
|
-
expect(button).toBeDisabled();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('button is not disabled by default', () => {
|
|
94
|
-
renderButton();
|
|
95
|
-
const button = screen.getByRole('button');
|
|
96
|
-
expect(button).not.toBeDisabled();
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('click trigger', () => {
|
|
101
|
-
it('fires on.click handler when clicked', () => {
|
|
102
|
-
const { on } = renderButton();
|
|
103
|
-
const button = screen.getByRole('button');
|
|
104
|
-
|
|
105
|
-
fireEvent.click(button);
|
|
106
|
-
|
|
107
|
-
expect(on.click).toHaveBeenCalledTimes(1);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('does not fire on.click when disabled', () => {
|
|
111
|
-
const { on } = renderButton({ props: { disabled: true } });
|
|
112
|
-
const button = screen.getByRole('button');
|
|
113
|
-
|
|
114
|
-
fireEvent.click(button);
|
|
115
|
-
|
|
116
|
-
expect(on.click).not.toHaveBeenCalled();
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe('widgetMeta', () => {
|
|
121
|
-
it('has correct meta name', () => {
|
|
122
|
-
expect(ButtonWidget.widgetMeta.name).toBe('button');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('has correct category', () => {
|
|
126
|
-
expect(ButtonWidget.widgetMeta.category).toBe('action');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('declares click trigger', () => {
|
|
130
|
-
expect(ButtonWidget.widgetMeta.triggers).toContain('click');
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('is not a container', () => {
|
|
134
|
-
expect(ButtonWidget.widgetMeta.container).toBe(false);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('has binding type none', () => {
|
|
138
|
-
expect(ButtonWidget.widgetMeta.binding).toBe('none');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('requires label in schema', () => {
|
|
142
|
-
expect(ButtonWidget.widgetMeta.schema.label.required).toBe(true);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
});
|