@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.
Files changed (317) hide show
  1. package/dist/App.d.ts.map +1 -1
  2. package/dist/App.js +7 -1
  3. package/dist/App.js.map +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/main.d.ts.map +1 -1
  9. package/dist/main.js +20 -0
  10. package/dist/main.js.map +1 -1
  11. package/dist/shell/assets/index-63v1sBS3.css +1 -0
  12. package/dist/shell/assets/index-Dh7K40cQ.js +8634 -0
  13. package/dist/shell/assets/vendor-query-B2cydN5j.js +1 -0
  14. package/dist/shell/assets/vendor-radix-BJxYPxPb.js +69 -0
  15. package/dist/shell/assets/vendor-router-ET_myMt5.js +17 -0
  16. package/dist/shell/index.html +5 -2
  17. package/dist/theme.css +82 -0
  18. package/dist/widgets/components/lazy-manifest.d.ts +11 -0
  19. package/dist/widgets/components/lazy-manifest.d.ts.map +1 -0
  20. package/dist/widgets/components/lazy-manifest.js +32 -0
  21. package/dist/widgets/components/lazy-manifest.js.map +1 -0
  22. package/dist/widgets/components/register.js +12 -12
  23. package/dist/widgets/components/register.js.map +1 -1
  24. package/dist/widgets/loader.d.ts +3 -0
  25. package/dist/widgets/loader.d.ts.map +1 -0
  26. package/dist/widgets/loader.js +73 -0
  27. package/dist/widgets/loader.js.map +1 -0
  28. package/dist/widgets/renderer/LazyWidget.d.ts +8 -0
  29. package/dist/widgets/renderer/LazyWidget.d.ts.map +1 -0
  30. package/dist/widgets/renderer/LazyWidget.js +31 -0
  31. package/dist/widgets/renderer/LazyWidget.js.map +1 -0
  32. package/dist/widgets/renderer/WidgetErrorBoundary.d.ts +17 -0
  33. package/dist/widgets/renderer/WidgetErrorBoundary.d.ts.map +1 -0
  34. package/dist/widgets/renderer/WidgetErrorBoundary.js +18 -0
  35. package/dist/widgets/renderer/WidgetErrorBoundary.js.map +1 -0
  36. package/dist/widgets/renderer/WidgetRenderer.d.ts.map +1 -1
  37. package/dist/widgets/renderer/WidgetRenderer.js +8 -6
  38. package/dist/widgets/renderer/WidgetRenderer.js.map +1 -1
  39. package/package.json +7 -4
  40. package/.claude/skills/add-widget/SKILL.md +0 -101
  41. package/.turbo/turbo-build.log +0 -29
  42. package/CHANGELOG.md +0 -25
  43. package/CLAUDE.md +0 -236
  44. package/components.json +0 -25
  45. package/dist/components/ui/chart.d.ts +0 -45
  46. package/dist/components/ui/chart.d.ts.map +0 -1
  47. package/dist/components/ui/chart.js +0 -119
  48. package/dist/components/ui/chart.js.map +0 -1
  49. package/dist/shell/assets/index--35CAvcP.js +0 -8715
  50. package/dist/shell/assets/index-COLmoPYo.css +0 -1
  51. package/index.html +0 -12
  52. package/src/App.tsx +0 -44
  53. package/src/__tests__/setup.ts +0 -1
  54. package/src/api/auth.ts +0 -41
  55. package/src/api/boot.ts +0 -10
  56. package/src/api/client.ts +0 -26
  57. package/src/api/paths.ts +0 -3
  58. package/src/api/token.ts +0 -13
  59. package/src/auth/LoginForm.tsx +0 -67
  60. package/src/auth/SessionExpired.tsx +0 -24
  61. package/src/auth/SetupForm.tsx +0 -76
  62. package/src/boot/BootGate.tsx +0 -35
  63. package/src/boot/BootProvider.tsx +0 -28
  64. package/src/boot/types.ts +0 -9
  65. package/src/boot/useBoot.ts +0 -111
  66. package/src/components/Icon.tsx +0 -17
  67. package/src/components/ui/accordion.tsx +0 -82
  68. package/src/components/ui/alert-dialog.tsx +0 -180
  69. package/src/components/ui/alert.tsx +0 -76
  70. package/src/components/ui/aspect-ratio.tsx +0 -9
  71. package/src/components/ui/avatar.tsx +0 -94
  72. package/src/components/ui/badge.tsx +0 -45
  73. package/src/components/ui/breadcrumb.tsx +0 -104
  74. package/src/components/ui/button-group.tsx +0 -78
  75. package/src/components/ui/button.tsx +0 -65
  76. package/src/components/ui/calendar.tsx +0 -187
  77. package/src/components/ui/card.tsx +0 -85
  78. package/src/components/ui/carousel.tsx +0 -229
  79. package/src/components/ui/chart.tsx +0 -339
  80. package/src/components/ui/checkbox.tsx +0 -27
  81. package/src/components/ui/collapsible.tsx +0 -21
  82. package/src/components/ui/combobox.tsx +0 -275
  83. package/src/components/ui/command.tsx +0 -178
  84. package/src/components/ui/context-menu.tsx +0 -242
  85. package/src/components/ui/dialog.tsx +0 -146
  86. package/src/components/ui/direction.tsx +0 -20
  87. package/src/components/ui/drawer.tsx +0 -118
  88. package/src/components/ui/dropdown-menu.tsx +0 -247
  89. package/src/components/ui/empty.tsx +0 -94
  90. package/src/components/ui/field.tsx +0 -224
  91. package/src/components/ui/hover-card.tsx +0 -36
  92. package/src/components/ui/input-group.tsx +0 -142
  93. package/src/components/ui/input-otp.tsx +0 -86
  94. package/src/components/ui/input.tsx +0 -19
  95. package/src/components/ui/item.tsx +0 -182
  96. package/src/components/ui/kbd.tsx +0 -26
  97. package/src/components/ui/label.tsx +0 -19
  98. package/src/components/ui/menubar.tsx +0 -260
  99. package/src/components/ui/native-select.tsx +0 -55
  100. package/src/components/ui/navigation-menu.tsx +0 -160
  101. package/src/components/ui/pagination.tsx +0 -112
  102. package/src/components/ui/popover.tsx +0 -74
  103. package/src/components/ui/progress.tsx +0 -31
  104. package/src/components/ui/radio-group.tsx +0 -42
  105. package/src/components/ui/resizable.tsx +0 -42
  106. package/src/components/ui/scroll-area.tsx +0 -53
  107. package/src/components/ui/select.tsx +0 -185
  108. package/src/components/ui/separator.tsx +0 -26
  109. package/src/components/ui/sheet.tsx +0 -128
  110. package/src/components/ui/sidebar.tsx +0 -669
  111. package/src/components/ui/skeleton.tsx +0 -13
  112. package/src/components/ui/slider.tsx +0 -54
  113. package/src/components/ui/sonner.tsx +0 -43
  114. package/src/components/ui/spinner.tsx +0 -16
  115. package/src/components/ui/switch.tsx +0 -33
  116. package/src/components/ui/table.tsx +0 -87
  117. package/src/components/ui/tabs.tsx +0 -80
  118. package/src/components/ui/textarea.tsx +0 -18
  119. package/src/components/ui/toggle-group.tsx +0 -86
  120. package/src/components/ui/toggle.tsx +0 -44
  121. package/src/components/ui/tooltip.tsx +0 -53
  122. package/src/context/MetaContext.tsx +0 -22
  123. package/src/context/ModuleContext.tsx +0 -62
  124. package/src/context/PermissionsContext.tsx +0 -39
  125. package/src/context/ShellProviders.tsx +0 -33
  126. package/src/context/UserContext.tsx +0 -16
  127. package/src/data/QueryProvider.tsx +0 -7
  128. package/src/data/queryClient.ts +0 -18
  129. package/src/data/useModelMeta.ts +0 -17
  130. package/src/data/useMutation.ts +0 -60
  131. package/src/data/useRecord.ts +0 -29
  132. package/src/data/useSource.ts +0 -112
  133. package/src/hooks/use-mobile.ts +0 -19
  134. package/src/index.css +0 -260
  135. package/src/index.ts +0 -16
  136. package/src/lib/utils.ts +0 -6
  137. package/src/main.tsx +0 -17
  138. package/src/router/NotFound.tsx +0 -8
  139. package/src/router/RouterProvider.tsx +0 -7
  140. package/src/router/buildRouteTree.tsx +0 -63
  141. package/src/router/createShellRouter.ts +0 -9
  142. package/src/router/hooks.ts +0 -43
  143. package/src/shell/CommandPalette.tsx +0 -76
  144. package/src/shell/ConfirmDialog.tsx +0 -34
  145. package/src/shell/ConfirmProvider.tsx +0 -56
  146. package/src/shell/DrawerContext.tsx +0 -44
  147. package/src/shell/HeaderActions.tsx +0 -31
  148. package/src/shell/ModuleSelectorPage.tsx +0 -149
  149. package/src/shell/PageOutlet.tsx +0 -21
  150. package/src/shell/ShellContext.tsx +0 -45
  151. package/src/shell/ShellDevTools.tsx +0 -153
  152. package/src/shell/ShellLayout.tsx +0 -231
  153. package/src/shell/Toast.tsx +0 -58
  154. package/src/shell/ToastProvider.tsx +0 -60
  155. package/src/shell/app-sidebar/AppSidebar.tsx +0 -44
  156. package/src/shell/app-sidebar/ModuleSwitcher.tsx +0 -87
  157. package/src/shell/app-sidebar/NavMain.tsx +0 -64
  158. package/src/shell/app-sidebar/NavUser.tsx +0 -97
  159. package/src/shell/app-sidebar/SearchMenu.tsx +0 -22
  160. package/src/shell/app-sidebar/index.ts +0 -8
  161. package/src/shell/app-sidebar/types.ts +0 -38
  162. package/src/shell/types.ts +0 -6
  163. package/src/shell/useBreadcrumbs.ts +0 -42
  164. package/src/studio/bridge.ts +0 -125
  165. package/src/studio/index.ts +0 -3
  166. package/src/studio/overlay.ts +0 -47
  167. package/src/studio/types.ts +0 -32
  168. package/src/studio/walker.ts +0 -48
  169. package/src/vite-env.d.ts +0 -1
  170. package/src/widgets/__tests__/action-edge-cases.test.ts +0 -281
  171. package/src/widgets/__tests__/action.test.ts +0 -236
  172. package/src/widgets/__tests__/attachment-widget.test.tsx +0 -85
  173. package/src/widgets/__tests__/attachments-widget.test.tsx +0 -109
  174. package/src/widgets/__tests__/binding.test.ts +0 -76
  175. package/src/widgets/__tests__/button-widget.test.tsx +0 -145
  176. package/src/widgets/__tests__/checkbox-widget.test.tsx +0 -158
  177. package/src/widgets/__tests__/code-widget.test.tsx +0 -64
  178. package/src/widgets/__tests__/computed-widget.test.tsx +0 -62
  179. package/src/widgets/__tests__/condition-edge-cases.test.ts +0 -120
  180. package/src/widgets/__tests__/condition.test.ts +0 -221
  181. package/src/widgets/__tests__/context.test.ts +0 -99
  182. package/src/widgets/__tests__/data-widget.test.tsx +0 -204
  183. package/src/widgets/__tests__/datepicker-widget.test.tsx +0 -66
  184. package/src/widgets/__tests__/datetime-widget.test.tsx +0 -67
  185. package/src/widgets/__tests__/drawer-widget.test.tsx +0 -149
  186. package/src/widgets/__tests__/dynamic-link-widget.test.tsx +0 -52
  187. package/src/widgets/__tests__/edge-cases.test.ts +0 -232
  188. package/src/widgets/__tests__/evaluator.test.ts +0 -107
  189. package/src/widgets/__tests__/functions.test.ts +0 -147
  190. package/src/widgets/__tests__/grid-widget.test.tsx +0 -137
  191. package/src/widgets/__tests__/hooks.test.tsx +0 -249
  192. package/src/widgets/__tests__/icon-widget.test.tsx +0 -129
  193. package/src/widgets/__tests__/input-widget.test.tsx +0 -264
  194. package/src/widgets/__tests__/integration.test.ts +0 -116
  195. package/src/widgets/__tests__/json-widget.test.tsx +0 -70
  196. package/src/widgets/__tests__/link-widget.test.tsx +0 -92
  197. package/src/widgets/__tests__/many-to-many-widget.test.tsx +0 -93
  198. package/src/widgets/__tests__/modal-widget.test.tsx +0 -148
  199. package/src/widgets/__tests__/money-widget.test.tsx +0 -97
  200. package/src/widgets/__tests__/parser.test.ts +0 -171
  201. package/src/widgets/__tests__/reactive-variables.test.ts +0 -383
  202. package/src/widgets/__tests__/renderer.test.tsx +0 -300
  203. package/src/widgets/__tests__/repeat-widget.test.tsx +0 -229
  204. package/src/widgets/__tests__/select-widget.test.tsx +0 -231
  205. package/src/widgets/__tests__/sequence-widget.test.tsx +0 -58
  206. package/src/widgets/__tests__/shell-integration.test.tsx +0 -1343
  207. package/src/widgets/__tests__/split-widget.test.tsx +0 -133
  208. package/src/widgets/__tests__/state-edge-cases.test.ts +0 -118
  209. package/src/widgets/__tests__/state.test.ts +0 -106
  210. package/src/widgets/__tests__/table-data-binding.test.tsx +0 -482
  211. package/src/widgets/__tests__/table-filter-popover.test.tsx +0 -486
  212. package/src/widgets/__tests__/table-search.test.tsx +0 -305
  213. package/src/widgets/__tests__/table-widget.test.tsx +0 -509
  214. package/src/widgets/__tests__/textarea-widget.test.tsx +0 -105
  215. package/src/widgets/__tests__/tracker-validator-edge-cases.test.ts +0 -242
  216. package/src/widgets/__tests__/tracker.test.ts +0 -133
  217. package/src/widgets/__tests__/tree-widget.test.tsx +0 -97
  218. package/src/widgets/__tests__/use-model-source.test.ts +0 -67
  219. package/src/widgets/__tests__/validator.test.ts +0 -208
  220. package/src/widgets/action/dispatcher.ts +0 -334
  221. package/src/widgets/action/index.ts +0 -2
  222. package/src/widgets/binding/index.ts +0 -2
  223. package/src/widgets/binding/resolver.ts +0 -61
  224. package/src/widgets/components/AttachmentWidget.tsx +0 -111
  225. package/src/widgets/components/AttachmentsWidget.tsx +0 -121
  226. package/src/widgets/components/BadgeWidget.tsx +0 -35
  227. package/src/widgets/components/ButtonWidget.tsx +0 -43
  228. package/src/widgets/components/CardWidget.tsx +0 -68
  229. package/src/widgets/components/CheckboxWidget.tsx +0 -39
  230. package/src/widgets/components/CodeWidget.tsx +0 -44
  231. package/src/widgets/components/ColumnWidget.tsx +0 -22
  232. package/src/widgets/components/ComputedWidget.tsx +0 -49
  233. package/src/widgets/components/DataWidget.tsx +0 -189
  234. package/src/widgets/components/DatePickerWidget.tsx +0 -73
  235. package/src/widgets/components/DatetimeWidget.tsx +0 -160
  236. package/src/widgets/components/DividerWidget.tsx +0 -37
  237. package/src/widgets/components/DrawerWidget.tsx +0 -52
  238. package/src/widgets/components/DynamicLinkWidget.tsx +0 -130
  239. package/src/widgets/components/GridWidget.tsx +0 -134
  240. package/src/widgets/components/GroupWidget.tsx +0 -111
  241. package/src/widgets/components/IconWidget.tsx +0 -29
  242. package/src/widgets/components/ImageWidget.tsx +0 -28
  243. package/src/widgets/components/InputWidget.tsx +0 -70
  244. package/src/widgets/components/JsonWidget.tsx +0 -78
  245. package/src/widgets/components/LinkWidget.tsx +0 -99
  246. package/src/widgets/components/ManyToManyWidget.tsx +0 -125
  247. package/src/widgets/components/ModalWidget.tsx +0 -52
  248. package/src/widgets/components/MoneyWidget.tsx +0 -80
  249. package/src/widgets/components/RepeatWidget.tsx +0 -66
  250. package/src/widgets/components/ScrollAreaWidget.tsx +0 -40
  251. package/src/widgets/components/SectionWidget.tsx +0 -78
  252. package/src/widgets/components/SelectWidget.tsx +0 -63
  253. package/src/widgets/components/SequenceWidget.tsx +0 -32
  254. package/src/widgets/components/SpacerWidget.tsx +0 -29
  255. package/src/widgets/components/SplitWidget.tsx +0 -60
  256. package/src/widgets/components/StackWidget.tsx +0 -44
  257. package/src/widgets/components/TableWidget.tsx +0 -366
  258. package/src/widgets/components/TextWidget.tsx +0 -44
  259. package/src/widgets/components/TextareaWidget.tsx +0 -49
  260. package/src/widgets/components/TreeWidget.tsx +0 -109
  261. package/src/widgets/components/index.ts +0 -30
  262. package/src/widgets/components/register.ts +0 -93
  263. package/src/widgets/components/table/CellRenderers.tsx +0 -83
  264. package/src/widgets/components/table/TablePagination.tsx +0 -45
  265. package/src/widgets/components/table/TableToolbar.tsx +0 -285
  266. package/src/widgets/components/table/filter-operators.ts +0 -134
  267. package/src/widgets/components/table/index.ts +0 -11
  268. package/src/widgets/condition/evaluator.ts +0 -57
  269. package/src/widgets/condition/index.ts +0 -1
  270. package/src/widgets/context/builder.ts +0 -99
  271. package/src/widgets/context/index.ts +0 -8
  272. package/src/widgets/context/types.ts +0 -37
  273. package/src/widgets/data/index.ts +0 -5
  274. package/src/widgets/data/useModelQuery.ts +0 -116
  275. package/src/widgets/data/useModelRecord.ts +0 -37
  276. package/src/widgets/expression/evaluator.ts +0 -100
  277. package/src/widgets/expression/functions.ts +0 -131
  278. package/src/widgets/expression/index.ts +0 -13
  279. package/src/widgets/expression/parser.ts +0 -229
  280. package/src/widgets/expression/types.ts +0 -45
  281. package/src/widgets/form/FormContext.ts +0 -29
  282. package/src/widgets/form/FormProvider.tsx +0 -84
  283. package/src/widgets/form/FormWidget.tsx +0 -42
  284. package/src/widgets/form/index.ts +0 -4
  285. package/src/widgets/form/useFormState.ts +0 -127
  286. package/src/widgets/form/useFormSubmit.ts +0 -90
  287. package/src/widgets/form/useFormValidation.ts +0 -62
  288. package/src/widgets/hooks/index.ts +0 -8
  289. package/src/widgets/hooks/useAction.ts +0 -83
  290. package/src/widgets/hooks/useBind.ts +0 -34
  291. package/src/widgets/hooks/useCondition.ts +0 -21
  292. package/src/widgets/hooks/useDataQuery.ts +0 -48
  293. package/src/widgets/hooks/useExpression.ts +0 -14
  294. package/src/widgets/hooks/usePageState.ts +0 -21
  295. package/src/widgets/hooks/useSurfaceContext.ts +0 -11
  296. package/src/widgets/hooks/useWidgetContext.ts +0 -14
  297. package/src/widgets/index.ts +0 -80
  298. package/src/widgets/lib/layout-props.ts +0 -135
  299. package/src/widgets/reactivity/index.ts +0 -11
  300. package/src/widgets/reactivity/tracker.ts +0 -139
  301. package/src/widgets/reactivity/variables.ts +0 -213
  302. package/src/widgets/registry.ts +0 -41
  303. package/src/widgets/renderer/SlotRenderer.tsx +0 -47
  304. package/src/widgets/renderer/WidgetRenderer.tsx +0 -191
  305. package/src/widgets/renderer/index.ts +0 -4
  306. package/src/widgets/shell/WidgetSlotRenderer.tsx +0 -73
  307. package/src/widgets/shell/index.ts +0 -4
  308. package/src/widgets/shell/useActionHandlers.ts +0 -170
  309. package/src/widgets/state/index.ts +0 -2
  310. package/src/widgets/state/store.ts +0 -96
  311. package/src/widgets/types.ts +0 -28
  312. package/src/widgets/validation/index.ts +0 -2
  313. package/src/widgets/validation/validator.ts +0 -140
  314. package/tsconfig.json +0 -27
  315. package/tsconfig.tsbuildinfo +0 -1
  316. package/vite.config.ts +0 -21
  317. package/vitest.config.ts +0 -16
@@ -1,482 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2
- import React from 'react';
3
- import { render, screen, fireEvent, cleanup, waitFor } from '@testing-library/react';
4
- import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5
- import type { WidgetNode } from '@rangka/shared';
6
- import { registerWidget, clearWidgetRegistry } from '../registry.js';
7
- import { SlotRenderer } from '../renderer/SlotRenderer.js';
8
- import { StateStore } from '../state/store.js';
9
- import { TableWidget } from '../components/TableWidget.js';
10
- import { ColumnWidget } from '../components/ColumnWidget.js';
11
- import { MetaProvider } from '../../context/MetaContext.js';
12
- import type { WidgetProps } from '../types.js';
13
- import type { WidgetContext } from '../context/types.js';
14
- import type { ComponentType } from 'react';
15
-
16
- vi.mock('../../api/client.js', () => ({
17
- apiClient: vi.fn(),
18
- }));
19
-
20
- import { apiClient } from '../../api/client.js';
21
- const mockApiClient = vi.mocked(apiClient);
22
-
23
- function TestText({ bind }: WidgetProps) {
24
- return <span data-testid="cell-text">{String(bind?.value ?? '')}</span>;
25
- }
26
-
27
- function TestBadge({ bind }: WidgetProps) {
28
- return <span data-testid="cell-badge">{String(bind?.value ?? '')}</span>;
29
- }
30
-
31
- function createQueryClient() {
32
- return new QueryClient({
33
- defaultOptions: {
34
- queries: { retry: false, gcTime: 0 },
35
- },
36
- });
37
- }
38
-
39
- function mockApiResponse(data: Record<string, unknown>[], total?: number) {
40
- const body = total != null ? { data, total } : data;
41
- mockApiClient.mockResolvedValueOnce({
42
- ok: true,
43
- json: () => Promise.resolve(body),
44
- } as unknown as Response);
45
- }
46
-
47
- function renderTable(
48
- nodes: WidgetNode[],
49
- options: {
50
- records?: Record<string, unknown>[];
51
- model?: string;
52
- state?: StateStore;
53
- } = {},
54
- ) {
55
- const { records, model = 'sales.order', state = new StateStore() } = options;
56
- const ctx: WidgetContext = {
57
- record: {},
58
- records,
59
- model,
60
- mode: 'view',
61
- };
62
- const queryClient = createQueryClient();
63
- const meta = {
64
- navigation: [],
65
- pages: [],
66
- models: {
67
- [model]: {
68
- qualifiedName: model,
69
- fields: [
70
- { name: 'customer', type: 'string', label: 'Customer' },
71
- { name: 'date', type: 'date', label: 'Date' },
72
- {
73
- name: 'status',
74
- type: 'enum',
75
- label: 'Status',
76
- options: ['Draft', 'Confirmed', 'Shipped'],
77
- },
78
- { name: 'total', type: 'money', label: 'Total' },
79
- ],
80
- },
81
- },
82
- };
83
- const result = render(
84
- <MetaProvider meta={meta}>
85
- <QueryClientProvider client={queryClient}>
86
- <SlotRenderer nodes={nodes} context={ctx} state={state} />
87
- </QueryClientProvider>
88
- </MetaProvider>,
89
- );
90
- return { ...result, state, queryClient };
91
- }
92
-
93
- beforeEach(() => {
94
- clearWidgetRegistry();
95
- registerWidget(
96
- {
97
- name: 'table',
98
- label: 'Table',
99
- category: 'data',
100
- schema: {},
101
- binding: 'model',
102
- triggers: ['rowClick', 'select', 'pageChange'],
103
- container: true,
104
- accepts: ['column'],
105
- },
106
- TableWidget as unknown as ComponentType<WidgetProps>,
107
- );
108
- registerWidget(
109
- {
110
- name: 'column',
111
- label: 'Column',
112
- category: 'layout',
113
- schema: {},
114
- binding: 'none',
115
- triggers: [],
116
- container: true,
117
- },
118
- ColumnWidget as unknown as ComponentType<WidgetProps>,
119
- );
120
- registerWidget(
121
- {
122
- name: 'text',
123
- label: 'Text',
124
- category: 'display',
125
- schema: {},
126
- binding: 'expression',
127
- triggers: [],
128
- container: false,
129
- },
130
- TestText,
131
- );
132
- registerWidget(
133
- {
134
- name: 'badge',
135
- label: 'Badge',
136
- category: 'display',
137
- schema: {},
138
- binding: 'field',
139
- triggers: [],
140
- container: false,
141
- },
142
- TestBadge,
143
- );
144
- mockApiClient.mockReset();
145
- });
146
-
147
- afterEach(() => {
148
- cleanup();
149
- clearWidgetRegistry();
150
- });
151
-
152
- const sampleData = [
153
- { id: '1', customer: 'Acme Corp', total: 1500, status: 'paid' },
154
- { id: '2', customer: 'Beta Inc', total: 2300, status: 'draft' },
155
- { id: '3', customer: 'Gamma Ltd', total: 800, status: 'paid' },
156
- ];
157
-
158
- function tableWithColumns(props: Record<string, unknown> = {}): WidgetNode[] {
159
- return [
160
- {
161
- type: 'table',
162
- bind: { model: { name: 'sales.order' } },
163
- props: { pageSize: 20, ...props },
164
- children: [
165
- {
166
- type: 'column',
167
- props: { label: 'Customer', sortable: true, filterable: true },
168
- bind: { field: 'customer' },
169
- },
170
- {
171
- type: 'column',
172
- props: { label: 'Total', align: 'right', sortable: true },
173
- bind: { field: 'total' },
174
- },
175
- { type: 'column', props: { label: 'Status', filterable: true }, bind: { field: 'status' } },
176
- ],
177
- },
178
- ];
179
- }
180
-
181
- describe('Table data binding (smart mode)', () => {
182
- describe('data fetching', () => {
183
- it('fetches data on mount when bind.model and pageSize are set', async () => {
184
- mockApiResponse(sampleData, 3);
185
- renderTable(tableWithColumns());
186
-
187
- await waitFor(() => {
188
- expect(mockApiClient).toHaveBeenCalledTimes(1);
189
- });
190
-
191
- const callUrl = mockApiClient.mock.calls[0][0] as string;
192
- expect(callUrl).toContain('/api/sales/order');
193
- expect(callUrl).toContain('page=1');
194
- expect(callUrl).toContain('limit=20');
195
- });
196
-
197
- it('renders fetched data as rows', async () => {
198
- mockApiResponse(sampleData, 3);
199
- renderTable(tableWithColumns());
200
-
201
- await waitFor(() => {
202
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
203
- });
204
- expect(screen.getByText('Beta Inc')).toBeInTheDocument();
205
- expect(screen.getByText('Gamma Ltd')).toBeInTheDocument();
206
- });
207
-
208
- it('shows loading state', () => {
209
- mockApiClient.mockReturnValue(new Promise(() => {}));
210
- renderTable(tableWithColumns());
211
- expect(screen.getAllByRole('row').length).toBeGreaterThan(1);
212
- expect(document.querySelectorAll('[data-slot="skeleton"]').length).toBeGreaterThan(0);
213
- });
214
- });
215
-
216
- describe('sorting', () => {
217
- it('clicking sortable header updates $sort in store', async () => {
218
- mockApiResponse(sampleData, 3);
219
- const state = new StateStore();
220
- renderTable(tableWithColumns(), { state });
221
-
222
- await waitFor(() => {
223
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
224
- });
225
-
226
- fireEvent.click(screen.getByText('Customer'));
227
- expect(state.get('$sort.sales.order')).toBe('customer');
228
- });
229
-
230
- it('sort cycles asc → desc → clear', async () => {
231
- mockApiResponse(sampleData, 3);
232
- const state = new StateStore();
233
- renderTable(tableWithColumns(), { state });
234
-
235
- await waitFor(() => {
236
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
237
- });
238
-
239
- const header = screen.getByText('Customer');
240
-
241
- fireEvent.click(header);
242
- expect(state.get('$sort.sales.order')).toBe('customer');
243
-
244
- mockApiResponse(sampleData, 3);
245
- fireEvent.click(header);
246
- expect(state.get('$sort.sales.order')).toBe('-customer');
247
-
248
- mockApiResponse(sampleData, 3);
249
- fireEvent.click(header);
250
- expect(state.get('$sort.sales.order')).toBeNull();
251
- });
252
-
253
- it('clicking sort resets page to 1', async () => {
254
- mockApiResponse(sampleData, 3);
255
- const state = new StateStore();
256
- state.set('$page.sales.order', 3);
257
- renderTable(tableWithColumns(), { state });
258
-
259
- await waitFor(() => {
260
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
261
- });
262
-
263
- fireEvent.click(screen.getByText('Customer'));
264
- expect(state.get('$page.sales.order')).toBe(1);
265
- });
266
-
267
- it('non-sortable column header is not clickable', async () => {
268
- mockApiResponse(sampleData, 3);
269
- const state = new StateStore();
270
- renderTable(tableWithColumns(), { state });
271
-
272
- await waitFor(() => {
273
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
274
- });
275
-
276
- fireEvent.click(screen.getByText('Status'));
277
- expect(state.get('$sort.sales.order')).toBeUndefined();
278
- });
279
- });
280
-
281
- describe('pagination', () => {
282
- it('renders pagination info with total', async () => {
283
- mockApiResponse(sampleData, 42);
284
- renderTable(tableWithColumns());
285
-
286
- await waitFor(() => {
287
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
288
- });
289
-
290
- expect(screen.getByText(/Showing 1–20 of 42/)).toBeInTheDocument();
291
- });
292
-
293
- it('next button increments page', async () => {
294
- mockApiResponse(sampleData, 42);
295
- const state = new StateStore();
296
- renderTable(tableWithColumns(), { state });
297
-
298
- await waitFor(() => {
299
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
300
- });
301
-
302
- const nextBtn = screen.getByLabelText('Next page');
303
- fireEvent.click(nextBtn);
304
- expect(state.get('$page.sales.order')).toBe(2);
305
- });
306
-
307
- it('prev button is disabled on page 1', async () => {
308
- mockApiResponse(sampleData, 42);
309
- renderTable(tableWithColumns());
310
-
311
- await waitFor(() => {
312
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
313
- });
314
-
315
- const prevBtn = screen.getByLabelText('Previous page');
316
- expect(prevBtn).toBeDisabled();
317
- });
318
-
319
- it('next button is disabled on last page', async () => {
320
- mockApiResponse(sampleData, 3);
321
- const state = new StateStore();
322
- renderTable(tableWithColumns(), { state });
323
-
324
- await waitFor(() => {
325
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
326
- });
327
-
328
- const nextBtn = screen.getByLabelText('Next page');
329
- expect(nextBtn).toBeDisabled();
330
- });
331
- });
332
-
333
- describe('filter bar', () => {
334
- it('renders filter button when filterable columns exist', async () => {
335
- mockApiResponse(sampleData, 3);
336
- renderTable(tableWithColumns());
337
-
338
- await waitFor(() => {
339
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
340
- });
341
-
342
- expect(screen.getByText('Filter')).toBeInTheDocument();
343
- });
344
-
345
- it('clicking filter shows searchable field list', async () => {
346
- mockApiResponse(sampleData, 3);
347
- renderTable(tableWithColumns());
348
-
349
- await waitFor(() => {
350
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
351
- });
352
-
353
- fireEvent.click(screen.getByText('Filter'));
354
-
355
- await waitFor(() => {
356
- expect(screen.getByPlaceholderText('Search fields...')).toBeInTheDocument();
357
- });
358
- });
359
-
360
- it('applying a filter updates store with operator', async () => {
361
- mockApiResponse(sampleData, 3);
362
- const state = new StateStore();
363
- renderTable(tableWithColumns(), { state });
364
-
365
- await waitFor(() => {
366
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
367
- });
368
-
369
- fireEvent.click(screen.getByText('Filter'));
370
-
371
- await waitFor(() => {
372
- expect(screen.getByPlaceholderText('Search fields...')).toBeInTheDocument();
373
- });
374
-
375
- // Click the Status field in the popover field list
376
- const statusBtn = screen.getAllByRole('button').find((btn) => btn.textContent === 'Status')!;
377
- fireEvent.click(statusBtn);
378
-
379
- // Should show operator select and value input
380
- const input = screen.getByPlaceholderText('Value...');
381
- fireEvent.change(input, { target: { value: 'paid' } });
382
- fireEvent.click(screen.getByText('Apply'));
383
-
384
- // enum defaults to 'eq' operator, stored without suffix
385
- expect(state.get('$filter.sales.order.status')).toBe('paid');
386
- expect(state.get('$page.sales.order')).toBe(1);
387
- });
388
-
389
- it('removing a filter chip clears it from store', async () => {
390
- const state = new StateStore();
391
- state.set('$filter.sales.order.status', 'paid');
392
- mockApiResponse(sampleData, 3);
393
- renderTable(tableWithColumns(), { state });
394
-
395
- await waitFor(() => {
396
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
397
- });
398
-
399
- const removeBtn = screen.getByLabelText('Remove Status filter');
400
- fireEvent.click(removeBtn);
401
-
402
- expect(state.get('$filter.sales.order.status')).toBeNull();
403
- });
404
- });
405
-
406
- describe('external reactivity', () => {
407
- it('refetches when $filter changes externally', async () => {
408
- mockApiResponse(sampleData, 3);
409
- const state = new StateStore();
410
- renderTable(tableWithColumns(), { state });
411
-
412
- await waitFor(() => {
413
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
414
- });
415
-
416
- const filteredData = [{ id: '1', customer: 'Acme Corp', total: 1500, status: 'paid' }];
417
- mockApiResponse(filteredData, 1);
418
-
419
- state.set('$filter.sales.order.status', 'paid');
420
-
421
- await waitFor(() => {
422
- expect(mockApiClient).toHaveBeenCalledTimes(2);
423
- });
424
-
425
- const secondCall = mockApiClient.mock.calls[1][0] as string;
426
- expect(secondCall).toContain('filter%5Bstatus%5D=paid');
427
- });
428
- });
429
-
430
- describe('dumb mode (no pageSize)', () => {
431
- it('renders records from context without fetching', () => {
432
- const nodes: WidgetNode[] = [
433
- {
434
- type: 'table',
435
- bind: { model: { name: 'sales.order' } },
436
- children: [{ type: 'column', props: { label: 'Customer' }, bind: { field: 'customer' } }],
437
- },
438
- ];
439
-
440
- renderTable(nodes, { records: sampleData });
441
-
442
- expect(screen.getByText('Acme Corp')).toBeInTheDocument();
443
- expect(screen.getByText('Beta Inc')).toBeInTheDocument();
444
- expect(mockApiClient).not.toHaveBeenCalled();
445
- });
446
-
447
- it('does not render pagination in dumb mode', () => {
448
- const nodes: WidgetNode[] = [
449
- {
450
- type: 'table',
451
- bind: { model: { name: 'sales.order' } },
452
- children: [{ type: 'column', props: { label: 'Customer' }, bind: { field: 'customer' } }],
453
- },
454
- ];
455
-
456
- renderTable(nodes, { records: sampleData });
457
-
458
- expect(screen.queryByLabelText('Next page')).not.toBeInTheDocument();
459
- expect(screen.queryByLabelText('Previous page')).not.toBeInTheDocument();
460
- });
461
-
462
- it('does not render filter bar in dumb mode', () => {
463
- const nodes: WidgetNode[] = [
464
- {
465
- type: 'table',
466
- bind: { model: { name: 'sales.order' } },
467
- children: [
468
- {
469
- type: 'column',
470
- props: { label: 'Customer', filterable: true },
471
- bind: { field: 'customer' },
472
- },
473
- ],
474
- },
475
- ];
476
-
477
- renderTable(nodes, { records: sampleData });
478
-
479
- expect(screen.queryByText('Filter')).not.toBeInTheDocument();
480
- });
481
- });
482
- });