@object-ui/fields 17.2.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 (212) hide show
  1. package/CHANGELOG.md +1533 -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 +5 -5
  7. package/dist/index.css +633 -0
  8. package/dist/index.d.ts +52 -12
  9. package/dist/index.js +5167 -4759
  10. package/dist/widgets/AddressField.d.ts +4 -12
  11. package/dist/widgets/AvatarField.d.ts +1 -1
  12. package/dist/widgets/CharacterCount.d.ts +56 -0
  13. package/dist/widgets/CheckboxesField.d.ts +1 -1
  14. package/dist/widgets/CodeField.d.ts +1 -1
  15. package/dist/widgets/ColorField.d.ts +1 -1
  16. package/dist/widgets/CurrencyField.d.ts +1 -1
  17. package/dist/widgets/EmailField.d.ts +1 -1
  18. package/dist/widgets/FileField.d.ts +1 -1
  19. package/dist/widgets/FilterConditionField.d.ts +1 -1
  20. package/dist/widgets/FullscreenFieldEditor.d.ts +45 -0
  21. package/dist/widgets/GeolocationField.d.ts +1 -1
  22. package/dist/widgets/GridField.d.ts +12 -2
  23. package/dist/widgets/ImageField.d.ts +1 -1
  24. package/dist/widgets/LocationField.d.ts +1 -1
  25. package/dist/widgets/LookupField.d.ts +1 -1
  26. package/dist/widgets/MultiSelectField.d.ts +1 -1
  27. package/dist/widgets/ObjectField.d.ts +1 -1
  28. package/dist/widgets/ObjectRefField.d.ts +1 -1
  29. package/dist/widgets/OptionsEmptyState.d.ts +59 -0
  30. package/dist/widgets/PercentField.d.ts +1 -1
  31. package/dist/widgets/PhoneField.d.ts +1 -1
  32. package/dist/widgets/QRCodeField.d.ts +1 -1
  33. package/dist/widgets/RadioField.d.ts +1 -1
  34. package/dist/widgets/RatingField.d.ts +1 -1
  35. package/dist/widgets/RecipientPickerField.d.ts +1 -1
  36. package/dist/widgets/RecordPickerDialog.d.ts +49 -7
  37. package/dist/widgets/RichTextField.d.ts +19 -1
  38. package/dist/widgets/SelectField.d.ts +25 -5
  39. package/dist/widgets/TagsField.d.ts +1 -1
  40. package/dist/widgets/TextAreaField.d.ts +44 -5
  41. package/dist/widgets/UrlField.d.ts +1 -1
  42. package/dist/widgets/address-format.d.ts +68 -0
  43. package/dist/widgets/file-size-guard.d.ts +41 -0
  44. package/dist/widgets/nativeDateValue.d.ts +37 -0
  45. package/dist/widgets/toDomProps.d.ts +111 -0
  46. package/dist/widgets/toHostGroupProps.d.ts +91 -0
  47. package/dist/widgets/types.d.ts +128 -33
  48. package/dist/widgets/useRecordQuery.d.ts +7 -1
  49. package/dist/withFieldCarrier.d.ts +56 -0
  50. package/package.json +20 -16
  51. package/src/FieldEditWidget.tsx +17 -1
  52. package/src/__tests__/AddressCellRenderer.test.tsx +166 -0
  53. package/src/__tests__/CurrencyField.minorUnits.test.tsx +191 -0
  54. package/src/__tests__/CurrencyField.symbol.test.tsx +198 -0
  55. package/src/__tests__/DateCellRenderer.test.tsx +9 -0
  56. package/src/__tests__/NumberCellRenderer.grouping.test.tsx +146 -0
  57. package/src/__tests__/PercentCellRenderer.locale.test.tsx +152 -0
  58. package/src/__tests__/PercentCellRenderer.test.tsx +115 -0
  59. package/src/__tests__/boolean-label-association-e2e.test.tsx +298 -0
  60. package/src/__tests__/capability-multiselect-retired.test.ts +109 -0
  61. package/src/__tests__/cell-truncation.test.tsx +96 -0
  62. package/src/__tests__/composite-group-label-e2e.test.tsx +436 -0
  63. package/src/__tests__/composite-group-label-readonly-e2e.test.tsx +403 -0
  64. package/src/__tests__/date-formatter-residue-4272.test.ts +120 -0
  65. package/src/__tests__/date-locale-channel.test.tsx +305 -0
  66. package/src/__tests__/field-carrier-sdui.test.tsx +169 -0
  67. package/src/__tests__/formatCurrency.centsDigit.test.tsx +158 -0
  68. package/src/__tests__/formatCurrency.minorUnits.test.tsx +221 -0
  69. package/src/__tests__/group-labelling-declaration.test.ts +148 -0
  70. package/src/__tests__/lookupCellRecordLink.test.tsx +171 -0
  71. package/src/__tests__/percent-cell-vs-measure-4576.test.ts +115 -0
  72. package/src/__tests__/percent-formatter-locale-4553.test.ts +147 -0
  73. package/src/__tests__/percent-tie-halfup-4590.test.ts +224 -0
  74. package/src/__tests__/select-label-association-e2e.test.tsx +199 -0
  75. package/src/__tests__/spec-symbol-batch7.test.ts +29 -15
  76. package/src/__tests__/validation-feedback.test.tsx +22 -13
  77. package/src/__tests__/widget-aria-invalid-e2e.test.tsx +265 -0
  78. package/src/__tests__/widget-aria-invalid-registry-e2e.test.tsx +338 -0
  79. package/src/__tests__/widget-dom-leak-e2e.test.tsx +357 -0
  80. package/src/__tests__/widget-props-contract.test.tsx +22 -9
  81. package/src/complex-widgets.test.tsx +22 -6
  82. package/src/currency.ts +130 -0
  83. package/src/datetime-widgets.test.tsx +94 -2
  84. package/src/field-type-alias.multiple.test.ts +81 -0
  85. package/src/field-type-alias.ts +58 -2
  86. package/src/index.css +44 -0
  87. package/src/index.tsx +558 -268
  88. package/src/standard-widgets.test.tsx +8 -1
  89. package/src/widgets/AddressField.postalCode.test.tsx +257 -0
  90. package/src/widgets/AddressField.tsx +107 -38
  91. package/src/widgets/AddressField.uniqueIds.test.tsx +93 -0
  92. package/src/widgets/AvatarField.tsx +9 -2
  93. package/src/widgets/BooleanField.tsx +44 -10
  94. package/src/widgets/CapabilityMultiSelectField.tsx +17 -5
  95. package/src/widgets/CharacterCount.tsx +263 -0
  96. package/src/widgets/CheckboxesField.tsx +66 -16
  97. package/src/widgets/CodeField.tsx +9 -2
  98. package/src/widgets/ColorField.tsx +11 -2
  99. package/src/widgets/CurrencyField.tsx +60 -19
  100. package/src/widgets/DateField.tsx +13 -4
  101. package/src/widgets/DateTimeField.tsx +14 -5
  102. package/src/widgets/EmailField.tsx +5 -5
  103. package/src/widgets/FileField.tsx +39 -11
  104. package/src/widgets/FilterConditionField.tsx +11 -0
  105. package/src/widgets/FormulaField.tsx +7 -2
  106. package/src/widgets/FullscreenFieldEditor.tsx +60 -0
  107. package/src/widgets/GeolocationField.tsx +49 -8
  108. package/src/widgets/GeolocationField.uniqueIds.test.tsx +88 -0
  109. package/src/widgets/GridField.test.tsx +226 -0
  110. package/src/widgets/GridField.tsx +115 -11
  111. package/src/widgets/ImageField.maxSize.test.tsx +154 -0
  112. package/src/widgets/ImageField.tsx +63 -6
  113. package/src/widgets/LocationField.tsx +9 -2
  114. package/src/widgets/LookupField.gateHintLabel.test.tsx +135 -0
  115. package/src/widgets/LookupField.hydration.test.tsx +1 -1
  116. package/src/widgets/LookupField.tsx +49 -10
  117. package/src/widgets/MasterDetailField.tsx +1 -1
  118. package/src/widgets/MultiSelectField.tsx +86 -16
  119. package/src/widgets/NumberField.tsx +3 -3
  120. package/src/widgets/ObjectField.tsx +17 -8
  121. package/src/widgets/ObjectRefField.tsx +10 -0
  122. package/src/widgets/OptionsEmptyState.no-provider.test.tsx +88 -0
  123. package/src/widgets/OptionsEmptyState.test.tsx +169 -0
  124. package/src/widgets/OptionsEmptyState.tsx +99 -0
  125. package/src/widgets/PasswordField.tsx +3 -3
  126. package/src/widgets/PeoplePicker.tsx +7 -1
  127. package/src/widgets/PercentField.tsx +5 -4
  128. package/src/widgets/PhoneField.tsx +5 -5
  129. package/src/widgets/QRCodeField.tsx +9 -2
  130. package/src/widgets/RadioField.tsx +58 -16
  131. package/src/widgets/RatingField.tsx +32 -4
  132. package/src/widgets/RecipientPickerField.tsx +18 -0
  133. package/src/widgets/RecordPickerDialog.baseFilterShapes.test.tsx +191 -0
  134. package/src/widgets/RecordPickerDialog.dateLocale.test.tsx +124 -0
  135. package/src/widgets/RecordPickerDialog.filterOptions.test.tsx +611 -0
  136. package/src/widgets/RecordPickerDialog.selectLabel.test.tsx +112 -0
  137. package/src/widgets/RecordPickerDialog.tsx +235 -21
  138. package/src/widgets/RichTextField.tsx +151 -24
  139. package/src/widgets/SelectField.tsx +84 -22
  140. package/src/widgets/SliderField.tsx +1 -1
  141. package/src/widgets/SummaryField.tsx +1 -1
  142. package/src/widgets/TagsField.placeholder.no-provider.test.tsx +68 -0
  143. package/src/widgets/TagsField.placeholder.test.tsx +95 -0
  144. package/src/widgets/TagsField.tsx +23 -2
  145. package/src/widgets/TextAreaField.tsx +171 -93
  146. package/src/widgets/TextField.tsx +3 -3
  147. package/src/widgets/TimeField.tsx +2 -2
  148. package/src/widgets/UrlField.tsx +5 -5
  149. package/src/widgets/UserField.tsx +4 -3
  150. package/src/widgets/VectorField.tsx +1 -1
  151. package/src/widgets/__tests__/FilterConditionField.operators.test.ts +25 -1
  152. package/src/widgets/__tests__/FullscreenFieldEditor.i18n.test.tsx +248 -0
  153. package/src/widgets/__tests__/FullscreenFieldEditor.no-provider.test.tsx +116 -0
  154. package/src/widgets/__tests__/RichTextField.fullscreenDisabled.test.tsx +244 -0
  155. package/src/widgets/__tests__/RichTextField.mobileFullscreen.test.tsx +195 -0
  156. package/src/widgets/__tests__/TextAreaField.characterCount.announcements.test.tsx +417 -0
  157. package/src/widgets/__tests__/TextAreaField.characterCount.i18n.test.tsx +287 -0
  158. package/src/widgets/__tests__/TextAreaField.characterCount.no-provider.test.tsx +160 -0
  159. package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.i18n.test.tsx +161 -0
  160. package/src/widgets/__tests__/TextAreaField.fullscreenCharacterCount.test.tsx +346 -0
  161. package/src/widgets/__tests__/TextAreaField.fullscreenDisabled.test.tsx +246 -0
  162. package/src/widgets/__tests__/TextAreaField.mobileFullscreen.test.tsx +175 -0
  163. package/src/widgets/address-format.ts +120 -0
  164. package/src/widgets/file-size-guard.ts +55 -0
  165. package/src/widgets/nativeDateValue.test.ts +115 -0
  166. package/src/widgets/nativeDateValue.ts +112 -0
  167. package/src/widgets/optionWidgets.gatedOptions.test.tsx +267 -0
  168. package/src/widgets/optionWidgets.unconfiguredOptions.test.tsx +150 -0
  169. package/src/widgets/toDomProps.ts +204 -0
  170. package/src/widgets/toHostGroupProps.ts +102 -0
  171. package/src/widgets/types.ts +135 -35
  172. package/src/widgets/useFieldTranslation.ts +46 -4
  173. package/src/widgets/useRecordQuery.ts +30 -3
  174. package/src/withFieldCarrier.tsx +75 -0
  175. package/dist/FieldEditWidget.test.d.ts +0 -8
  176. package/dist/__tests__/DateCellRenderer.test.d.ts +0 -0
  177. package/dist/__tests__/NumberCellRenderer.test.d.ts +0 -0
  178. package/dist/__tests__/lookupCellDisplayField.test.d.ts +0 -0
  179. package/dist/__tests__/lookupCellDisplayName.test.d.ts +0 -0
  180. package/dist/__tests__/lookupCellReferenceKey.test.d.ts +0 -0
  181. package/dist/__tests__/registry-collision.test.d.ts +0 -0
  182. package/dist/__tests__/resolveFieldCurrency.test.d.ts +0 -1
  183. package/dist/__tests__/spec-symbol-batch7.test.d.ts +0 -8
  184. package/dist/__tests__/validation-feedback.test.d.ts +0 -0
  185. package/dist/__tests__/widget-props-contract.test.d.ts +0 -8
  186. package/dist/coerce-safe-value.test.d.ts +0 -1
  187. package/dist/complex-widgets.test.d.ts +0 -1
  188. package/dist/datetime-widgets.test.d.ts +0 -1
  189. package/dist/field-type-coverage.test.d.ts +0 -1
  190. package/dist/standard-widgets.test.d.ts +0 -0
  191. package/dist/widgets/CapabilityMultiSelectField.test.d.ts +0 -0
  192. package/dist/widgets/CheckboxesField.cascade.test.d.ts +0 -0
  193. package/dist/widgets/GridField.test.d.ts +0 -1
  194. package/dist/widgets/ImageLightbox.test.d.ts +0 -1
  195. package/dist/widgets/LookupField.dependsOn.test.d.ts +0 -8
  196. package/dist/widgets/LookupField.hydration.test.d.ts +0 -1
  197. package/dist/widgets/LookupField.idField.test.d.ts +0 -1
  198. package/dist/widgets/MultiSelectField.cascade.test.d.ts +0 -0
  199. package/dist/widgets/PeoplePicker.test.d.ts +0 -8
  200. package/dist/widgets/PeoplePickerComponents.test.d.ts +0 -8
  201. package/dist/widgets/RadioField.cascade.test.d.ts +0 -0
  202. package/dist/widgets/RecipientPickerField.test.d.ts +0 -0
  203. package/dist/widgets/SelectField.cascade.test.d.ts +0 -0
  204. package/dist/widgets/UserFieldPicker.test.d.ts +0 -8
  205. package/dist/widgets/__tests__/FilterConditionField.matchAll.test.d.ts +0 -8
  206. package/dist/widgets/__tests__/FilterConditionField.operators.test.d.ts +0 -8
  207. package/dist/widgets/deriveLookupColumns.test.d.ts +0 -1
  208. package/dist/widgets/file-value.test.d.ts +0 -1
  209. package/dist/widgets/personDisplay.test.d.ts +0 -8
  210. package/dist/widgets/recentLookups.test.d.ts +0 -1
  211. package/dist/widgets/useRecordQuery.test.d.ts +0 -8
  212. package/dist/widgets/useUploadingSignal.test.d.ts +0 -1
@@ -52,6 +52,15 @@ describe('formatRelativeDate', () => {
52
52
  });
53
53
  });
54
54
 
55
+ /**
56
+ * Nothing in this file mounts an `I18nProvider`, and that is load-bearing
57
+ * rather than incidental (objectui#4468): these cases are the pin on
58
+ * `useDisplayLocale()`'s LAST resort — the concrete `'en'` a renderer resolves
59
+ * to when neither a tenant locale nor an active UI language exists. The
60
+ * session-locale cases live in `date-locale-channel.test.tsx`; mounting a
61
+ * provider here would leave react-i18next's global instance on that language
62
+ * and quietly turn these into assertions about test ordering.
63
+ */
55
64
  describe('DateCellRenderer', () => {
56
65
  it('does not label a past start_date as "Overdue" (regression: field-role-agnostic formatter)', () => {
57
66
  render(<DateCellRenderer value={daysAgo(6)} field={{ type: 'date', name: 'start_date' } as any} />);
@@ -0,0 +1,146 @@
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
+ * objectui#4033 (source thread objectstack#5067) — the number cell renderer
11
+ * used to build `new Intl.NumberFormat('en-US', …)` with grouping left at the
12
+ * Intl default, so a four-digit YEAR stored as `Field.number({ scale: 0 })`
13
+ * rendered as `2,026` in every locale and no field property could turn it off.
14
+ *
15
+ * Two independent pins live here:
16
+ *
17
+ * 1. **Ordinal grouping** — a declared `scale: 0` with no currency is an
18
+ * integer/ordinal surface, so grouping is suppressed. Interim default; a
19
+ * future spec-level presentation hint overrides it.
20
+ * 2. **Locale** — grouping and decimal marks follow the ACTIVE display locale,
21
+ * never a hardcoded `en-US`.
22
+ *
23
+ * The controls are as load-bearing as the fixes: currency keeps grouping, a
24
+ * non-zero `scale` keeps grouping, and an UNDECLARED scale keeps grouping
25
+ * (`scale` is optional in the spec and absent means "decimals unknown", not
26
+ * "integer" — see the renderer's own comment).
27
+ */
28
+
29
+ import { describe, it, expect } from 'vitest';
30
+ import React from 'react';
31
+ import { render, screen } from '@testing-library/react';
32
+ import '@testing-library/jest-dom';
33
+ import { LocalizationProvider } from '@object-ui/i18n';
34
+ import { NumberCellRenderer, CurrencyCellRenderer } from '../index';
35
+
36
+ const renderNumber = (
37
+ value: unknown,
38
+ field: Record<string, unknown> = {},
39
+ locale?: string,
40
+ ) =>
41
+ render(
42
+ <LocalizationProvider value={{ locale }}>
43
+ <NumberCellRenderer value={value as any} field={{ type: 'number', ...field } as any} />
44
+ </LocalizationProvider>,
45
+ );
46
+
47
+ const renderCurrency = (
48
+ value: unknown,
49
+ field: Record<string, unknown> = {},
50
+ locale?: string,
51
+ ) =>
52
+ render(
53
+ <LocalizationProvider value={{ locale }}>
54
+ <CurrencyCellRenderer value={value as any} field={{ type: 'currency', ...field } as any} />
55
+ </LocalizationProvider>,
56
+ );
57
+
58
+ describe('NumberCellRenderer — ordinal grouping (objectui#4033)', () => {
59
+ // The card's exact fixture: `year: Field.number({ scale: 0, min: 1900 })`.
60
+ it.each(['en-US', 'de-DE', 'zh-CN', 'fr-FR'])(
61
+ 'renders a scale-0 year ungrouped in %s',
62
+ (locale) => {
63
+ renderNumber(2026, { scale: 0 }, locale);
64
+ expect(screen.getByText('2026')).toBeInTheDocument();
65
+ },
66
+ );
67
+
68
+ it('suppresses grouping for every scale-0 magnitude, not just four digits', () => {
69
+ renderNumber(1234567, { scale: 0 }, 'en-US');
70
+ expect(screen.getByText('1234567')).toBeInTheDocument();
71
+ });
72
+
73
+ it('CONTROL: a non-zero scale keeps grouping', () => {
74
+ renderNumber(1234.5, { scale: 2 }, 'en-US');
75
+ expect(screen.getByText('1,234.50')).toBeInTheDocument();
76
+ });
77
+
78
+ it('CONTROL: an UNDECLARED scale keeps grouping (absent ≠ integer)', () => {
79
+ renderNumber(2026, {}, 'en-US');
80
+ expect(screen.getByText('2,026')).toBeInTheDocument();
81
+ });
82
+ });
83
+
84
+ describe('NumberCellRenderer — active display locale (objectui#4033)', () => {
85
+ it('uses the active locale decimal + grouping marks (de-DE)', () => {
86
+ renderNumber(1234.5, { scale: 1 }, 'de-DE');
87
+ expect(screen.getByText('1.234,5')).toBeInTheDocument();
88
+ });
89
+
90
+ it('uses the active locale decimal + grouping marks (en-US)', () => {
91
+ renderNumber(1234.5, { scale: 1 }, 'en-US');
92
+ expect(screen.getByText('1,234.5')).toBeInTheDocument();
93
+ });
94
+
95
+ it('uses the active locale decimal + grouping marks (fr-FR)', () => {
96
+ // fr-FR groups with U+202F (NARROW NO-BREAK SPACE) and uses "," for the
97
+ // decimal mark — nothing an en-US formatter can produce.
98
+ //
99
+ // Asserted against raw `textContent`, NOT `getByText`: testing-library's
100
+ // default normalizer collapses `\s+` (which includes U+202F) down to an
101
+ // ASCII space, so a `getByText` assertion here can only ever prove "some
102
+ // whitespace" and would pass on the wrong separator. The escape sequence is
103
+ // written out rather than pasted — a raw U+202F in source renders as
104
+ // nothing and is unfindable by grep.
105
+ const { container } = renderNumber(1234.5, { scale: 1 }, 'fr-FR');
106
+ expect(container.textContent).toBe('1 234,5');
107
+ });
108
+
109
+ it('does not take a malformed tenant locale down with it', () => {
110
+ // `locale` arrives from a server response (ADR-0053); a junk tag must
111
+ // degrade to the runtime default, never throw out of a grid cell.
112
+ renderNumber(1234.5, { scale: 1 }, 'not a locale');
113
+ expect(screen.getByText(/1.?234.5/)).toBeInTheDocument();
114
+ });
115
+ });
116
+
117
+ describe('CurrencyCellRenderer — CONTROL, unaffected by the ordinal default', () => {
118
+ it('keeps grouping and the currency symbol for a whole amount', () => {
119
+ renderCurrency(5000000, { currency: 'USD' }, 'en-US');
120
+ expect(screen.getByText('$5,000,000')).toBeInTheDocument();
121
+ });
122
+
123
+ it('keeps grouping and the fractional part when the amount is not whole', () => {
124
+ renderCurrency(1234.5, { currency: 'USD' }, 'en-US');
125
+ // This control pinned the CURRENT behaviour when #4033 landed — `$1,234.5`,
126
+ // NOT the `$1,234.50` that `formatCurrency`'s own doc comment promises
127
+ // ("Salesforce convention: `$1,234.50` keeps cents"). That was a real
128
+ // defect, deliberately filed rather than folded in (objectui#4332) and
129
+ // pinned here so its fix would flip a watched test instead of silently
130
+ // changing an unwatched surface. #4332 is now fixed, so the expectation
131
+ // moves to the promised form; grouping — this control's actual subject —
132
+ // is unchanged, which is still what #4033 needs it to prove.
133
+ expect(screen.getByText('$1,234.50')).toBeInTheDocument();
134
+ });
135
+
136
+ it('follows the active locale for currency too', () => {
137
+ renderCurrency(5000000, { currency: 'EUR' }, 'de-DE');
138
+ // de-DE: grouped with dots and a TRAILING symbol, vs en-US's leading one.
139
+ expect(screen.getByText(/^5\.000\.000\s*€$/)).toBeInTheDocument();
140
+ });
141
+
142
+ it('a currency field with NO resolved currency still groups (money, not an ordinal)', () => {
143
+ renderCurrency(5000000, {}, 'en-US');
144
+ expect(screen.getByText('5,000,000')).toBeInTheDocument();
145
+ });
146
+ });
@@ -0,0 +1,152 @@
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
+ * objectui#4553 phase 2 — the percent CELL, the fields-internal consumer of
11
+ * `formatPercent`.
12
+ *
13
+ * `PercentCellRenderer` had two rendering paths and BOTH were outside the
14
+ * display-locale channel:
15
+ *
16
+ * const formatted = isWholePercentField
17
+ * ? `${numValue.toFixed(precision)}%` // a second bare toFixed path
18
+ * : formatPercent(numValue, precision); // no locale to pass
19
+ *
20
+ * The branch exists for a real reason — a field named `progress` / `completion`
21
+ * stores 0-100, so it must NOT go through `percentDisplayValue`'s fraction
22
+ * scaling — but it had quietly become a second place where a percent was
23
+ * formatted, and it was the more primitive of the two. Threading only the
24
+ * `formatPercent` half would have made ONE grid internally inconsistent: a
25
+ * `progress` column ungrouped and unlocalized beside a `rate` column that was
26
+ * neither. So both branches now render through the same locale-aware body and
27
+ * differ only in the scaling policy, which is all the branch was ever about.
28
+ *
29
+ * ── Directions, predicted in writing BEFORE the run ──────────────────────
30
+ * Runner machine locale en-US.
31
+ *
32
+ * de, ordinary percent 1234.5 `1235%` → `1.235 %` RED
33
+ * de, `progress` 1234.5 `1235%` → `1.235 %` RED (the second path)
34
+ * en, ordinary percent 1234.5 `1235%` → `1,235%` RED (grouping move)
35
+ * en, `progress` 1234.5 `1235%` → `1,235%` RED (grouping move)
36
+ * the fraction/whole SPLIT itself PIN, green both sides
37
+ * small-value en output PIN, green both sides
38
+ *
39
+ * Provider-mounted by construction (objectui#4514) — the pure-function cases
40
+ * live in `percent-formatter-locale-4553.test.ts`.
41
+ */
42
+
43
+ import React from 'react';
44
+ import { describe, it, expect, afterEach } from 'vitest';
45
+ import { render, screen, cleanup } from '@testing-library/react';
46
+ import '@testing-library/jest-dom';
47
+ import { I18nProvider, LocalizationProvider } from '@object-ui/i18n';
48
+ import { PercentCellRenderer } from '../index';
49
+
50
+ /** German writes a NO-BREAK SPACE (U+00A0) before the percent sign. */
51
+ const NBSP = '\u00a0';
52
+
53
+ /**
54
+ * A session: the UI language the user picked plus the tenant's regional
55
+ * default. `useDisplayLocale()` resolves tenant regional default → active UI
56
+ * language → 'en'.
57
+ */
58
+ function renderCell(
59
+ value: unknown,
60
+ field: Record<string, unknown>,
61
+ language: string,
62
+ tenantLocale?: string,
63
+ ) {
64
+ return render(
65
+ <I18nProvider
66
+ config={{ defaultLanguage: language, detectBrowserLanguage: false }}
67
+ persistLanguage={false}
68
+ >
69
+ <LocalizationProvider value={{ locale: tenantLocale }}>
70
+ <PercentCellRenderer
71
+ value={value as any}
72
+ field={{ type: 'percent', ...field } as any}
73
+ />
74
+ </LocalizationProvider>
75
+ </I18nProvider>,
76
+ );
77
+ }
78
+
79
+ /** The cell's text, read off the value span beside the decorative bar. */
80
+ function cellText(): string {
81
+ return document.body.textContent ?? '';
82
+ }
83
+
84
+ afterEach(() => cleanup());
85
+
86
+ describe('PercentCellRenderer follows the display locale (objectui#4553)', () => {
87
+ it('de renders the German percent form', () => {
88
+ renderCell(1234.5, { name: 'win_rate' }, 'de');
89
+ expect(cellText()).toContain(`1.235${NBSP}%`);
90
+ });
91
+
92
+ /**
93
+ * The SECOND path — `progress` matches WHOLE_PERCENT_FIELD_PATTERN, so this
94
+ * value skips fraction scaling and used to skip `formatPercent` entirely.
95
+ */
96
+ it('de renders the German form on the whole-percent path too', () => {
97
+ renderCell(1234.5, { name: 'progress' }, 'de');
98
+ expect(cellText()).toContain(`1.235${NBSP}%`);
99
+ });
100
+
101
+ it('en groups at four digits on both paths — the deliberate output move', () => {
102
+ const { unmount } = renderCell(1234.5, { name: 'win_rate' }, 'en');
103
+ expect(cellText()).toContain('1,235%');
104
+ unmount();
105
+
106
+ renderCell(1234.5, { name: 'progress' }, 'en');
107
+ expect(cellText()).toContain('1,235%');
108
+ });
109
+
110
+ it('an explicit tenant locale outranks the active UI language', () => {
111
+ renderCell(1234.5, { name: 'win_rate' }, 'en', 'de');
112
+ expect(cellText()).toContain(`1.235${NBSP}%`);
113
+ expect(cellText()).not.toContain('1,235%');
114
+ });
115
+ });
116
+
117
+ describe('PercentCellRenderer keeps its scaling contract (objectui#4553 must-not-change)', () => {
118
+ /**
119
+ * PIN, green both sides — and the reason the whole-percent branch was kept
120
+ * rather than collapsed into `formatPercent`. The same stored number means
121
+ * different things in the two columns, and that must not have changed.
122
+ */
123
+ it('an ordinary percent scales a fraction; a progress field does not', () => {
124
+ const { unmount } = renderCell(0.5, { name: 'win_rate' }, 'en');
125
+ // Fraction-stored: 0.5 → 50%.
126
+ expect(cellText()).toContain('50%');
127
+ unmount();
128
+
129
+ renderCell(0.5, { name: 'progress' }, 'en');
130
+ // Whole-percent field: 0.5 really is half a percent, rounded to 1% at
131
+ // precision 0 — NOT 50%.
132
+ expect(cellText()).toContain('1%');
133
+ expect(cellText()).not.toContain('50%');
134
+ });
135
+
136
+ /** PIN: small-value English output is byte-identical across the change. */
137
+ it('en small-value output is unchanged (must-not-change)', () => {
138
+ renderCell(33.33, { name: 'win_rate', precision: 2 }, 'en');
139
+ expect(cellText()).toContain('33.33%');
140
+ });
141
+
142
+ /** PIN: the decorative bar still reports the un-formatted magnitude. */
143
+ it('the progressbar still carries the numeric value', () => {
144
+ renderCell(33.33, { name: 'win_rate' }, 'en');
145
+ expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '33.33');
146
+ });
147
+
148
+ /** PIN: the null path is untouched — and the hook runs before it. */
149
+ it('renders the empty value for null without crashing on the hook', () => {
150
+ expect(() => renderCell(null, { name: 'win_rate' }, 'de')).not.toThrow();
151
+ });
152
+ });
@@ -0,0 +1,115 @@
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
+ * Regression for objectstack-ai/objectstack#5066: the percent / progress cell
11
+ * renderer emitted a FIXED-WIDTH, NON-SHRINKABLE bar (`w-16 shrink-0`) next to a
12
+ * shrinkable value span. Inside a narrow clipping container — a
13
+ * `record:highlights` chip is `basis-[9rem]` / `min-w-[7rem]` and clips with
14
+ * `truncate` — the 64px bar won the space and the VALUE was cut mid-digit: a
15
+ * stored `33.33` carried `33%` in the DOM but read as `3` on screen (measured:
16
+ * 79px clipping box, 32px text node, 25px overflow), with no ellipsis and no
17
+ * signal in the accessible name. A silently wrong number, not a cosmetic glitch.
18
+ *
19
+ * Pin: the number is the CONTENT (`shrink-0`, never sacrificed) and the bar is
20
+ * DECORATION (`w-16` as its preferred width, free to shrink away under
21
+ * pressure — and never `flex-1`, so a wide grid cell keeps today's 64px bar).
22
+ *
23
+ * jsdom has no layout engine, so these are class-semantics assertions (same
24
+ * approach as `cell-truncation.test.tsx` for objectui#3466) plus DOM-text
25
+ * assertions — deliberately not brittle pixel measurements.
26
+ */
27
+ import { describe, it, expect } from 'vitest';
28
+ import { render, screen } from '@testing-library/react';
29
+ import '@testing-library/jest-dom';
30
+ import React from 'react';
31
+
32
+ import { PercentCellRenderer } from '../index';
33
+
34
+ const renderPercent = (value: unknown, field: Record<string, unknown> = {}) =>
35
+ render(
36
+ <PercentCellRenderer value={value as any} field={{ type: 'percent', ...field } as any} />,
37
+ );
38
+
39
+ /** The decorative bar: `role="progressbar"` wrapper the renderer emits. */
40
+ const bar = () => screen.getByRole('progressbar');
41
+ /** The row that holds bar + value. */
42
+ const row = () => bar().parentElement!;
43
+
44
+ describe('PercentCellRenderer — value beats the decorative bar (issue #5066)', () => {
45
+ it('renders BOTH the bar and the value at normal width', () => {
46
+ renderPercent(33.33);
47
+
48
+ expect(bar()).toBeInTheDocument();
49
+ expect(bar()).toHaveAttribute('aria-valuenow', '33.33');
50
+ expect(screen.getByText('33%')).toBeInTheDocument();
51
+ // Bar and value are siblings in one flex row (nothing was dropped).
52
+ expect(row()).toHaveClass('flex');
53
+ expect(row()).toContainElement(screen.getByText('33%'));
54
+ });
55
+
56
+ it('gives the value span shrink priority so a narrow chip cannot clip it', () => {
57
+ renderPercent(33.33);
58
+
59
+ const value = screen.getByText('33%');
60
+ // The number never shrinks — it is the content of the cell.
61
+ expect(value).toHaveClass('shrink-0');
62
+ expect(value).toHaveClass('whitespace-nowrap', 'tabular-nums');
63
+ });
64
+
65
+ it('lets the bar shrink away instead of pushing the value out of the clip box', () => {
66
+ renderPercent(33.33);
67
+
68
+ // The bar keeps `w-16` as its PREFERRED width but is shrinkable, and
69
+ // `min-w-0` stops the automatic minimum size from pinning it at 64px.
70
+ expect(bar()).toHaveClass('w-16', 'min-w-0', 'shrink');
71
+ // The pre-fix spelling: a non-shrinkable bar is exactly the bug.
72
+ expect(bar()).not.toHaveClass('shrink-0');
73
+ // The row itself must be able to shrink below its content width inside the
74
+ // chip's flex column, or the deficit never reaches the bar.
75
+ expect(row()).toHaveClass('min-w-0');
76
+ });
77
+
78
+ it('does not let the bar GROW in a wide cell (no flex-1 / grow)', () => {
79
+ renderPercent(33.33);
80
+
81
+ // `flex-1` would also make the bar stretch to fill every wide grid cell —
82
+ // `w-16` stays the upper bound, only the shrink direction changed.
83
+ expect(bar().className).not.toMatch(/(^|\s)(flex-1|grow|basis-)/);
84
+ });
85
+
86
+ it('keeps the full formatted value in the DOM (fraction, whole, precision)', () => {
87
+ const first = renderPercent(33.33);
88
+ expect(screen.getByText('33%')).toBeInTheDocument();
89
+ first.unmount();
90
+
91
+ // Declared precision keeps the decimals — the widest text, worst overflow.
92
+ renderPercent(33.33, { precision: 2 });
93
+ const wide = screen.getByText('33.33%');
94
+ expect(wide).toBeInTheDocument();
95
+ expect(wide).toHaveClass('shrink-0');
96
+ });
97
+
98
+ it('scales a fraction-stored percent and still renders both parts', () => {
99
+ renderPercent(0.8);
100
+
101
+ expect(screen.getByText('80%')).toBeInTheDocument();
102
+ expect(bar()).toHaveAttribute('aria-valuenow', '80');
103
+ expect(screen.getByText('80%')).toHaveClass('shrink-0');
104
+ });
105
+
106
+ it('applies the same contract to whole-percent `progress` fields', () => {
107
+ renderPercent(33.33, { type: 'progress', name: 'progress' });
108
+
109
+ // 0-100 storage: no fraction scaling, value rendered as-is.
110
+ expect(screen.getByText('33%')).toBeInTheDocument();
111
+ expect(screen.getByText('33%')).toHaveClass('shrink-0');
112
+ expect(bar()).toHaveClass('min-w-0', 'shrink');
113
+ expect(bar()).not.toHaveClass('shrink-0');
114
+ });
115
+ });