@object-ui/fields 17.3.0 → 17.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +941 -0
  2. package/README.md +1 -12
  3. package/dist/FieldEditWidget.d.ts +7 -1
  4. package/dist/currency.d.ts +46 -0
  5. package/dist/field-type-alias.d.ts +19 -1
  6. package/dist/index.cjs +4 -4
  7. package/dist/index.css +633 -0
  8. package/dist/index.d.ts +48 -12
  9. package/dist/index.js +5026 -4933
  10. package/dist/widgets/AddressField.d.ts +3 -11
  11. package/dist/widgets/FullscreenFieldEditor.d.ts +42 -152
  12. package/dist/widgets/GridField.d.ts +12 -2
  13. package/dist/widgets/OptionsEmptyState.d.ts +15 -1
  14. package/dist/widgets/RecordPickerDialog.d.ts +32 -6
  15. package/dist/widgets/SelectField.d.ts +25 -5
  16. package/dist/widgets/address-format.d.ts +68 -0
  17. package/dist/widgets/file-size-guard.d.ts +41 -0
  18. package/dist/widgets/nativeDateValue.d.ts +37 -0
  19. package/dist/widgets/toDomProps.d.ts +30 -10
  20. package/dist/widgets/toHostGroupProps.d.ts +91 -0
  21. package/dist/widgets/useRecordQuery.d.ts +7 -1
  22. package/package.json +17 -13
  23. package/src/FieldEditWidget.tsx +17 -1
  24. package/src/__tests__/AddressCellRenderer.test.tsx +166 -0
  25. package/src/__tests__/CurrencyField.minorUnits.test.tsx +191 -0
  26. package/src/__tests__/CurrencyField.symbol.test.tsx +198 -0
  27. package/src/__tests__/DateCellRenderer.test.tsx +9 -0
  28. package/src/__tests__/NumberCellRenderer.grouping.test.tsx +146 -0
  29. package/src/__tests__/PercentCellRenderer.locale.test.tsx +152 -0
  30. package/src/__tests__/PercentCellRenderer.test.tsx +115 -0
  31. package/src/__tests__/boolean-label-association-e2e.test.tsx +298 -0
  32. package/src/__tests__/capability-multiselect-retired.test.ts +109 -0
  33. package/src/__tests__/composite-group-label-e2e.test.tsx +436 -0
  34. package/src/__tests__/composite-group-label-readonly-e2e.test.tsx +403 -0
  35. package/src/__tests__/date-formatter-residue-4272.test.ts +120 -0
  36. package/src/__tests__/date-locale-channel.test.tsx +305 -0
  37. package/src/__tests__/formatCurrency.centsDigit.test.tsx +158 -0
  38. package/src/__tests__/formatCurrency.minorUnits.test.tsx +221 -0
  39. package/src/__tests__/group-labelling-declaration.test.ts +148 -0
  40. package/src/__tests__/lookupCellRecordLink.test.tsx +171 -0
  41. package/src/__tests__/percent-cell-vs-measure-4576.test.ts +115 -0
  42. package/src/__tests__/percent-formatter-locale-4553.test.ts +147 -0
  43. package/src/__tests__/percent-tie-halfup-4590.test.ts +224 -0
  44. package/src/__tests__/select-label-association-e2e.test.tsx +199 -0
  45. package/src/__tests__/widget-dom-leak-e2e.test.tsx +29 -270
  46. package/src/complex-widgets.test.tsx +22 -6
  47. package/src/currency.ts +130 -0
  48. package/src/datetime-widgets.test.tsx +94 -2
  49. package/src/field-type-alias.multiple.test.ts +81 -0
  50. package/src/field-type-alias.ts +58 -2
  51. package/src/index.css +44 -0
  52. package/src/index.tsx +489 -247
  53. package/src/standard-widgets.test.tsx +8 -1
  54. package/src/widgets/AddressField.postalCode.test.tsx +257 -0
  55. package/src/widgets/AddressField.tsx +79 -29
  56. package/src/widgets/AddressField.uniqueIds.test.tsx +2 -1
  57. package/src/widgets/BooleanField.tsx +41 -7
  58. package/src/widgets/CapabilityMultiSelectField.tsx +17 -5
  59. package/src/widgets/CheckboxesField.tsx +35 -2
  60. package/src/widgets/CurrencyField.tsx +55 -15
  61. package/src/widgets/DateField.tsx +11 -2
  62. package/src/widgets/DateTimeField.tsx +12 -3
  63. package/src/widgets/FileField.tsx +27 -9
  64. package/src/widgets/FormulaField.tsx +6 -1
  65. package/src/widgets/FullscreenFieldEditor.tsx +47 -258
  66. package/src/widgets/GeolocationField.tsx +29 -3
  67. package/src/widgets/GridField.test.tsx +226 -0
  68. package/src/widgets/GridField.tsx +114 -10
  69. package/src/widgets/ImageField.maxSize.test.tsx +154 -0
  70. package/src/widgets/ImageField.tsx +54 -4
  71. package/src/widgets/LookupField.hydration.test.tsx +1 -1
  72. package/src/widgets/LookupField.tsx +8 -4
  73. package/src/widgets/MultiSelectField.tsx +56 -2
  74. package/src/widgets/OptionsEmptyState.tsx +16 -0
  75. package/src/widgets/RadioField.tsx +35 -3
  76. package/src/widgets/RatingField.tsx +15 -2
  77. package/src/widgets/RecordPickerDialog.baseFilterShapes.test.tsx +191 -0
  78. package/src/widgets/RecordPickerDialog.dateLocale.test.tsx +124 -0
  79. package/src/widgets/RecordPickerDialog.tsx +64 -15
  80. package/src/widgets/RichTextField.tsx +1 -1
  81. package/src/widgets/SelectField.tsx +36 -5
  82. package/src/widgets/UserField.tsx +3 -2
  83. package/src/widgets/__tests__/FilterConditionField.operators.test.ts +25 -1
  84. package/src/widgets/address-format.ts +120 -0
  85. package/src/widgets/file-size-guard.ts +55 -0
  86. package/src/widgets/nativeDateValue.test.ts +115 -0
  87. package/src/widgets/nativeDateValue.ts +112 -0
  88. package/src/widgets/optionWidgets.gatedOptions.test.tsx +267 -0
  89. package/src/widgets/optionWidgets.unconfiguredOptions.test.tsx +150 -0
  90. package/src/widgets/toDomProps.ts +48 -19
  91. package/src/widgets/toHostGroupProps.ts +102 -0
  92. package/src/widgets/useFieldTranslation.ts +15 -33
  93. package/src/widgets/useRecordQuery.ts +30 -3
  94. package/dist/FieldEditWidget.test.d.ts +0 -8
  95. package/dist/__tests__/DateCellRenderer.test.d.ts +0 -0
  96. package/dist/__tests__/NumberCellRenderer.test.d.ts +0 -0
  97. package/dist/__tests__/cell-truncation.test.d.ts +0 -0
  98. package/dist/__tests__/field-carrier-sdui.test.d.ts +0 -0
  99. package/dist/__tests__/lookupCellDisplayField.test.d.ts +0 -0
  100. package/dist/__tests__/lookupCellDisplayName.test.d.ts +0 -0
  101. package/dist/__tests__/lookupCellReferenceKey.test.d.ts +0 -0
  102. package/dist/__tests__/registry-collision.test.d.ts +0 -0
  103. package/dist/__tests__/resolveFieldCurrency.test.d.ts +0 -1
  104. package/dist/__tests__/spec-symbol-batch7.test.d.ts +0 -8
  105. package/dist/__tests__/validation-feedback.test.d.ts +0 -0
  106. package/dist/__tests__/widget-aria-invalid-e2e.test.d.ts +0 -0
  107. package/dist/__tests__/widget-aria-invalid-registry-e2e.test.d.ts +0 -0
  108. package/dist/__tests__/widget-dom-leak-e2e.test.d.ts +0 -0
  109. package/dist/__tests__/widget-props-contract.test.d.ts +0 -8
  110. package/dist/coerce-safe-value.test.d.ts +0 -1
  111. package/dist/complex-widgets.test.d.ts +0 -1
  112. package/dist/datetime-widgets.test.d.ts +0 -1
  113. package/dist/field-type-coverage.test.d.ts +0 -1
  114. package/dist/standard-widgets.test.d.ts +0 -0
  115. package/dist/widgets/AddressField.uniqueIds.test.d.ts +0 -0
  116. package/dist/widgets/CapabilityMultiSelectField.test.d.ts +0 -0
  117. package/dist/widgets/CheckboxesField.cascade.test.d.ts +0 -0
  118. package/dist/widgets/GeolocationField.uniqueIds.test.d.ts +0 -0
  119. package/dist/widgets/GridField.test.d.ts +0 -1
  120. package/dist/widgets/ImageLightbox.test.d.ts +0 -1
  121. package/dist/widgets/LookupField.dependsOn.test.d.ts +0 -8
  122. package/dist/widgets/LookupField.gateHintLabel.test.d.ts +0 -8
  123. package/dist/widgets/LookupField.hydration.test.d.ts +0 -1
  124. package/dist/widgets/LookupField.idField.test.d.ts +0 -1
  125. package/dist/widgets/MultiSelectField.cascade.test.d.ts +0 -0
  126. package/dist/widgets/OptionsEmptyState.no-provider.test.d.ts +0 -0
  127. package/dist/widgets/OptionsEmptyState.test.d.ts +0 -0
  128. package/dist/widgets/PeoplePicker.test.d.ts +0 -8
  129. package/dist/widgets/PeoplePickerComponents.test.d.ts +0 -8
  130. package/dist/widgets/RadioField.cascade.test.d.ts +0 -0
  131. package/dist/widgets/RecipientPickerField.test.d.ts +0 -0
  132. package/dist/widgets/RecordPickerDialog.filterOptions.test.d.ts +0 -8
  133. package/dist/widgets/RecordPickerDialog.selectLabel.test.d.ts +0 -8
  134. package/dist/widgets/SelectField.cascade.test.d.ts +0 -0
  135. package/dist/widgets/TagsField.placeholder.no-provider.test.d.ts +0 -0
  136. package/dist/widgets/TagsField.placeholder.test.d.ts +0 -0
  137. package/dist/widgets/UserFieldPicker.test.d.ts +0 -8
  138. package/dist/widgets/__tests__/FilterConditionField.matchAll.test.d.ts +0 -8
  139. package/dist/widgets/__tests__/FilterConditionField.operators.test.d.ts +0 -8
  140. package/dist/widgets/__tests__/FullscreenFieldEditor.i18n.test.d.ts +0 -0
  141. package/dist/widgets/__tests__/FullscreenFieldEditor.no-provider.test.d.ts +0 -0
  142. package/dist/widgets/__tests__/RichTextField.fullscreenDisabled.test.d.ts +0 -0
  143. package/dist/widgets/__tests__/RichTextField.mobileFullscreen.test.d.ts +0 -0
  144. package/dist/widgets/__tests__/TextAreaField.characterCount.announcements.test.d.ts +0 -0
  145. package/dist/widgets/__tests__/TextAreaField.characterCount.i18n.test.d.ts +0 -0
  146. package/dist/widgets/__tests__/TextAreaField.characterCount.no-provider.test.d.ts +0 -0
  147. package/dist/widgets/__tests__/TextAreaField.fullscreenCharacterCount.i18n.test.d.ts +0 -0
  148. package/dist/widgets/__tests__/TextAreaField.fullscreenCharacterCount.test.d.ts +0 -0
  149. package/dist/widgets/__tests__/TextAreaField.fullscreenDisabled.test.d.ts +0 -0
  150. package/dist/widgets/__tests__/TextAreaField.mobileFullscreen.test.d.ts +0 -0
  151. package/dist/widgets/deriveLookupColumns.test.d.ts +0 -1
  152. package/dist/widgets/file-value.test.d.ts +0 -1
  153. package/dist/widgets/personDisplay.test.d.ts +0 -8
  154. package/dist/widgets/recentLookups.test.d.ts +0 -1
  155. package/dist/widgets/useRecordQuery.test.d.ts +0 -8
  156. package/dist/widgets/useUploadingSignal.test.d.ts +0 -1
@@ -0,0 +1,298 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ /**
10
+ * End-to-end: a boolean field's VISIBLE label is associated with the control
11
+ * the widget renders (objectui#3952).
12
+ *
13
+ * The defect: `<FormControl>` is a Radix `Slot` that hands its child the id
14
+ * `<FormLabel htmlFor>` already points at (`_r_N_-form-item`), and
15
+ * `BooleanField` REPLACED it with the field name. So the form's visible label
16
+ * referenced an id no element carried — clicking it toggled nothing — while the
17
+ * widget emitted a SECOND, `sr-only` label of its own carrying the same text.
18
+ * The accessible name survived only by that accident.
19
+ *
20
+ * Two scenarios, pinned separately, because the widget has two hosts with
21
+ * opposite needs:
22
+ *
23
+ * - **hosted** (the form renderer, `ObjectForm`, any `<FormControl>`): the host
24
+ * owns the id AND the label. The widget must use the id it was handed and
25
+ * must NOT emit a label of its own — that is the duplicate half of the bug.
26
+ * - **standalone** (`FieldEditWidget`'s inline grid editor, a bare SDUI node):
27
+ * nobody hands an id and nobody renders a label, so the widget's own
28
+ * `sr-only` label is the control's ONLY accessible name and must stay.
29
+ *
30
+ * The widgets are registered raw rather than through `registerAllFields()`,
31
+ * which wraps every loader in `React.lazy`: an unbounded module load inside a
32
+ * bounded `findBy`/`waitFor` window is the repo's known flake generator
33
+ * (AGENTS.md 测试纪律, objectui#3010). Same component, no Suspense boundary.
34
+ */
35
+
36
+ import { describe, it, expect, beforeAll, beforeEach, afterEach, vi } from 'vitest';
37
+ import { render, screen, fireEvent, cleanup } from '@testing-library/react';
38
+ import '@testing-library/jest-dom';
39
+ import { ComponentRegistry } from '@object-ui/core';
40
+ // Module scope: pulls in the form renderer's registration side effect.
41
+ import '@object-ui/components';
42
+
43
+ import { BooleanField } from '../widgets/BooleanField';
44
+
45
+ beforeAll(() => {
46
+ ComponentRegistry.register('boolean', BooleanField as any, {
47
+ namespace: 'field',
48
+ skipFallback: true,
49
+ });
50
+ }, 30000);
51
+
52
+ beforeEach(() => {
53
+ if (!(Element.prototype as any).scrollIntoView) {
54
+ (Element.prototype as any).scrollIntoView = () => {};
55
+ }
56
+ });
57
+
58
+ afterEach(() => {
59
+ cleanup();
60
+ vi.restoreAllMocks();
61
+ });
62
+
63
+ /** The real form renderer hosting one field — the #3952 reproduction. */
64
+ function renderForm(field: any, defaultValue: unknown) {
65
+ const Form = ComponentRegistry.get('form')!;
66
+ return render(
67
+ <Form
68
+ schema={{
69
+ type: 'form',
70
+ mode: 'create',
71
+ showSubmit: true,
72
+ showCancel: false,
73
+ submitLabel: 'Create',
74
+ defaultValues: { [field.name]: defaultValue },
75
+ fields: [field],
76
+ onSubmit: () => {},
77
+ }}
78
+ />,
79
+ );
80
+ }
81
+
82
+ /** Every `<label for=…>` in the document, paired with its resolved target. */
83
+ function labelTargets(): Array<{ text: string; forId: string; resolves: boolean }> {
84
+ return Array.from(document.querySelectorAll('label'))
85
+ .map((el) => ({
86
+ text: (el.textContent ?? '').trim(),
87
+ forId: el.getAttribute('for') ?? '',
88
+ resolves: !!el.getAttribute('for') && !!document.getElementById(el.getAttribute('for')!),
89
+ }))
90
+ .filter((l) => l.forId !== '');
91
+ }
92
+
93
+ const switchOf = (name: string): Element => {
94
+ const el = document.querySelector(`[data-field="${name}"] [role="switch"]`);
95
+ if (!el) throw new Error(`no switch rendered for field "${name}"`);
96
+ return el;
97
+ };
98
+
99
+ const BOOLEAN_FIELD = {
100
+ name: 'notifications',
101
+ label: 'Email Notifications',
102
+ type: 'boolean',
103
+ };
104
+
105
+ describe('a form-hosted boolean field is labelled by its HOST (objectui#3952)', () => {
106
+ it('every label the form emits points at an element that exists', () => {
107
+ renderForm(BOOLEAN_FIELD, false);
108
+
109
+ const labels = labelTargets();
110
+ expect(labels.length).toBeGreaterThan(0);
111
+ // A `for` naming an id nothing carries is the defect verbatim: the form's
112
+ // visible label used to reference `_r_N_-form-item` while the switch
113
+ // carried `notifications`.
114
+ expect(labels.filter((l) => !l.resolves)).toEqual([]);
115
+ });
116
+
117
+ it('the visible label names the switch — one label, associated with the control', () => {
118
+ renderForm(BOOLEAN_FIELD, false);
119
+
120
+ // `getAllByLabelText` resolves label→control through `for`/id, so it guards
121
+ // the ID half: restore the override and it does not merely return the wrong
122
+ // node, it throws "found a label … however no form control was found
123
+ // associated to that label" — the switch left with NO accessible name,
124
+ // which is exactly what #3952 warned would happen the day the widget's own
125
+ // label went away. It does NOT guard the duplicate half: two labels
126
+ // pointing at ONE control still resolve to one element (measured), so the
127
+ // duplicate is pinned by the label-text count below.
128
+ const labelled = screen.getAllByLabelText('Email Notifications');
129
+ expect(labelled).toHaveLength(1);
130
+ expect(labelled[0]).toBe(switchOf('notifications'));
131
+ expect(labelled[0]).toHaveAttribute('role', 'switch');
132
+ });
133
+
134
+ it('the label text appears exactly once in the DOM', () => {
135
+ renderForm(BOOLEAN_FIELD, false);
136
+
137
+ // The duplicate half of the defect (and why a naive `getByText` on a
138
+ // boolean field returned two nodes).
139
+ expect(screen.getAllByText('Email Notifications')).toHaveLength(1);
140
+ });
141
+
142
+ it('activating the visible label toggles the switch', () => {
143
+ renderForm(BOOLEAN_FIELD, false);
144
+
145
+ const control = switchOf('notifications');
146
+ expect(control).toHaveAttribute('aria-checked', 'false');
147
+
148
+ // The user-facing symptom of #3952: the normal affordance for a switch row
149
+ // is clicking its label. It reaches the control only through the `for`/id
150
+ // association the form set up.
151
+ fireEvent.click(screen.getByText('Email Notifications'));
152
+
153
+ expect(switchOf('notifications')).toHaveAttribute('aria-checked', 'true');
154
+ });
155
+
156
+ it('the control keeps the HOST id verbatim — the widget does not rename it', () => {
157
+ renderForm(BOOLEAN_FIELD, false);
158
+
159
+ const control = switchOf('notifications');
160
+ const id = control.getAttribute('id') ?? '';
161
+ // The host's id is a `useId()`-derived form-item id; the field name is what
162
+ // the widget used to substitute for it.
163
+ expect(id).not.toBe('');
164
+ expect(id).not.toBe('notifications');
165
+ expect(id).toMatch(/-form-item$/);
166
+ // …and it is the id the visible label points at.
167
+ const visible = screen.getByText('Email Notifications');
168
+ expect(visible.getAttribute('for')).toBe(id);
169
+ });
170
+
171
+ it('two boolean fields in one form each get their own label', () => {
172
+ const Form = ComponentRegistry.get('form')!;
173
+ render(
174
+ <Form
175
+ schema={{
176
+ type: 'form',
177
+ mode: 'create',
178
+ showSubmit: false,
179
+ showCancel: false,
180
+ defaultValues: { notifications: false, digest: false },
181
+ fields: [BOOLEAN_FIELD, { name: 'digest', label: 'Weekly Digest', type: 'boolean' }],
182
+ onSubmit: () => {},
183
+ }}
184
+ />,
185
+ );
186
+
187
+ expect(labelTargets().filter((l) => !l.resolves)).toEqual([]);
188
+ // Each label reaches its OWN switch (a shared/colliding id would make both
189
+ // resolve to the first one).
190
+ fireEvent.click(screen.getByText('Weekly Digest'));
191
+ expect(switchOf('digest')).toHaveAttribute('aria-checked', 'true');
192
+ expect(switchOf('notifications')).toHaveAttribute('aria-checked', 'false');
193
+ });
194
+ });
195
+
196
+ describe('a STANDALONE boolean widget keeps its own accessible name (objectui#3952)', () => {
197
+ // `FieldEditWidget` (the grid's inline cell editor) renders these widgets with
198
+ // no `id` and no label of its own, so removing the widget's `sr-only` label
199
+ // unconditionally would leave the control unnamed. These pin the fallback.
200
+
201
+ it('switch variant: the sr-only label names the control', () => {
202
+ render(
203
+ <BooleanField
204
+ value={false}
205
+ onChange={() => {}}
206
+ field={{ name: 'notifications', label: 'Email Notifications', type: 'boolean' } as any}
207
+ />,
208
+ );
209
+
210
+ expect(labelTargets().filter((l) => !l.resolves)).toEqual([]);
211
+ const labelled = screen.getAllByLabelText('Email Notifications');
212
+ expect(labelled).toHaveLength(1);
213
+ expect(labelled[0]).toHaveAttribute('role', 'switch');
214
+ });
215
+
216
+ it('checkbox variant: the sr-only label names the control', () => {
217
+ render(
218
+ <BooleanField
219
+ value={false}
220
+ onChange={() => {}}
221
+ field={
222
+ {
223
+ name: 'agreed',
224
+ label: 'I agree',
225
+ type: 'boolean',
226
+ widget: 'checkbox',
227
+ } as any
228
+ }
229
+ />,
230
+ );
231
+
232
+ expect(labelTargets().filter((l) => !l.resolves)).toEqual([]);
233
+ const labelled = screen.getAllByLabelText('I agree');
234
+ expect(labelled).toHaveLength(1);
235
+ expect(labelled[0]).toHaveAttribute('role', 'checkbox');
236
+ });
237
+ });
238
+
239
+ describe('a host that labels by field NAME keeps its association (objectui#3952)', () => {
240
+ // `@object-ui/app-shell`'s `ActionParamDialog` boolean branch renders
241
+ // `<Label htmlFor={param.name}>` and — unlike its own generic branch, which
242
+ // passes `id={param.name}` — hands the widget NO id. It works only because
243
+ // the fallback chain's second term derives the id from the field name
244
+ // (`paramToField` sets `name: param.name`).
245
+ //
246
+ // So the chain is `hostId || config.name || useId()`, in that order, and the
247
+ // middle term is NOT dead weight to be "cleaned up" into a bare `useId()`:
248
+ // that would silently unlink every boolean action param in the console. This
249
+ // pin is what makes that attempt fail loudly instead.
250
+ it('falls back to the field name when no id was handed down', () => {
251
+ render(
252
+ <div>
253
+ <BooleanField
254
+ value={false}
255
+ onChange={() => {}}
256
+ field={{ name: 'confirmed', label: 'Confirmed', type: 'boolean' } as any}
257
+ />
258
+ <label htmlFor="confirmed">Send anyway</label>
259
+ </div>,
260
+ );
261
+
262
+ const control = document.querySelector('[role="switch"]')!;
263
+ expect(control).toHaveAttribute('id', 'confirmed');
264
+ expect(labelTargets().filter((l) => !l.resolves)).toEqual([]);
265
+ // The host's OWN label reaches the control through that id.
266
+ expect(screen.getAllByLabelText(/Send anyway/)).toHaveLength(1);
267
+ });
268
+ });
269
+
270
+ describe('a host-supplied id wins for BOTH variants (objectui#3952)', () => {
271
+ // The checkbox variant is unreachable through the standalone form renderer —
272
+ // `resolvedType = widget || field.widget || type` turns `widget: 'checkbox'`
273
+ // into the renderer's own BUILTIN `checkbox` branch before the registry is
274
+ // consulted — so its host contract is pinned at the prop boundary, exactly
275
+ // as `<FormControl>`'s Slot delivers it.
276
+ it.each([
277
+ ['switch', undefined, 'switch'],
278
+ ['checkbox', 'checkbox', 'checkbox'],
279
+ ] as const)('%s variant uses the id the host handed it', (_name, widget, role) => {
280
+ render(
281
+ <label htmlFor="host-item">
282
+ Host Label
283
+ <BooleanField
284
+ value={false}
285
+ onChange={() => {}}
286
+ id="host-item"
287
+ field={{ name: 'agreed', label: 'I agree', type: 'boolean', widget } as any}
288
+ />
289
+ </label>,
290
+ );
291
+
292
+ const control = document.querySelector(`[role="${role}"]`)!;
293
+ expect(control).toHaveAttribute('id', 'host-item');
294
+ // And the widget adds no second label of its own.
295
+ expect(screen.queryByText('I agree')).toBeNull();
296
+ expect(document.querySelectorAll('label')).toHaveLength(1);
297
+ });
298
+ });
@@ -0,0 +1,109 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ /**
10
+ * Retirement pin — `field:capability-multiselect` (objectui#3308, ADR-0049
11
+ * enforce-or-remove).
12
+ *
13
+ * The key was registered on ONE path only: `registerFields()`, whose sole caller
14
+ * was the docs site. The live path (`registerAllFields()`, run at module import)
15
+ * never had it, because `fieldWidgetMap` never listed it — so a field authored
16
+ * with `widget: 'capability-multiselect'` resolved to nothing in every real app
17
+ * while a code comment advertised it as usable from a record form. Nothing
18
+ * stamped the hint either: ADR-0056 P1 stamps `permission-facet-link` on all six
19
+ * `sys_permission_set` facets (including `system_permissions`), and P2 put the
20
+ * capability editor in Studio.
21
+ *
22
+ * `registerFields()` itself is gone as of objectui#3910 (ruling B of
23
+ * objectui#3798): the docs catalog's field examples are form-hosted now, so the
24
+ * demo adapter that path existed for has no reason to exist. That REMOVES this
25
+ * file's second and third assertions rather than re-spelling them — a test may
26
+ * not call a function that no longer exists, and asserting over a deleted path
27
+ * would pass for the empty reason (nothing is registered because nothing runs).
28
+ * What each one becomes:
29
+ *
30
+ * 1. absent on the live path — UNCHANGED, and it is now the whole fact. While
31
+ * a second path existed this assertion pinned nothing (it passed on
32
+ * `origin/main` too, as PR #3793 recorded); with that path deleted, the
33
+ * live registry is the only registry, so re-adding the name to
34
+ * `fieldWidgetMap` is exactly what turns this red.
35
+ * 2. "absent after `registerFields()` too" — DELETED with the path.
36
+ * 3. "registers every other docs-path key" — RE-POINTED at the live path,
37
+ * which is a superset of the 38 keys the docs path used to register. It
38
+ * still pins "the retirement subtracts exactly one name", now against the
39
+ * surviving seam instead of a deleted one.
40
+ *
41
+ * `CapabilityMultiSelectField` the component is deliberately NOT asserted gone:
42
+ * Studio's `PermissionMatrixEditor` imports and renders it directly, which is
43
+ * ADR-0056 P2's design. Only the widget NAME is retired.
44
+ */
45
+
46
+ import { describe, it, expect } from 'vitest';
47
+ import { ComponentRegistry } from '@object-ui/core';
48
+
49
+ // Importing the entry runs `registerAllFields()` at module load — the live path.
50
+ import { registerAllFields, FORM_FIELD_TYPES } from '../index';
51
+
52
+ const RETIRED = 'capability-multiselect';
53
+
54
+ /**
55
+ * Every key the retired docs-demo path (`registerFields()`) registered, minus the
56
+ * retired one. Spelled out rather than derived so a future edit that silently
57
+ * drops one of these registrations fails here instead of passing vacuously.
58
+ * The live path registers these AND more (`multiselect`, `radio`, `checkboxes`,
59
+ * `tags`, `richtext`, and the widget-hint-only pickers) — this list is the floor
60
+ * the retirement promised to leave intact, not the full live surface.
61
+ */
62
+ const RETAINED_FIELD_KEYS = [
63
+ 'text', 'textarea', 'number', 'boolean', 'select', 'date', 'datetime', 'time',
64
+ 'email', 'phone', 'url',
65
+ 'currency', 'percent', 'password', 'markdown', 'html', 'lookup', 'master_detail',
66
+ 'file', 'image', 'location',
67
+ 'formula', 'summary', 'auto_number',
68
+ 'user', 'owner',
69
+ 'object', 'vector', 'grid',
70
+ 'color', 'slider', 'rating', 'code', 'avatar', 'address', 'geolocation',
71
+ 'signature', 'qrcode',
72
+ ] as const;
73
+
74
+ describe('capability-multiselect widget retirement (objectui#3308)', () => {
75
+ it('is absent on the live registerAllFields() path', () => {
76
+ registerAllFields();
77
+ expect(ComponentRegistry.get(`field:${RETIRED}`)).toBeUndefined();
78
+ expect(ComponentRegistry.get(RETIRED)).toBeUndefined();
79
+ });
80
+
81
+ it('is not in fieldWidgetMap, so no bare field type can reach it either', () => {
82
+ expect(FORM_FIELD_TYPES).not.toContain(RETIRED);
83
+ });
84
+
85
+ it('registers every retained field key (retirement subtracts exactly one)', () => {
86
+ registerAllFields();
87
+ for (const key of RETAINED_FIELD_KEYS) {
88
+ expect(
89
+ ComponentRegistry.get(`field:${key}`),
90
+ `field:${key} must survive the retirement`,
91
+ ).toBeTruthy();
92
+ }
93
+ expect(RETAINED_FIELD_KEYS).toHaveLength(38);
94
+ });
95
+
96
+ it('has no second registration path left to shadow the live one (objectui#3910)', async () => {
97
+ // The defect ruling B closed was structural, not cosmetic: `registerFields()`
98
+ // re-registered the SAME `field:<type>` keys with demo-only wrappers, so
99
+ // whichever ran last won the registry for every consumer sharing it. Pinning
100
+ // the export gone is what stops it growing back under a new name.
101
+ const entry = (await import('../index')) as Record<string, unknown>;
102
+ expect(entry.registerFields).toBeUndefined();
103
+ expect(entry.createFieldRenderer).toBeUndefined();
104
+ // The surviving seam is still exported — this test must fail loudly if the
105
+ // removal ever takes the live path with it.
106
+ expect(typeof entry.registerAllFields).toBe('function');
107
+ expect(typeof entry.registerField).toBe('function');
108
+ });
109
+ });