@delacour/react-native-ui 0.6.0-alpha.20261103164139 → 0.6.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 (250) hide show
  1. package/package.json +13 -7
  2. package/src/components/accordion/AGENTS.md +1 -0
  3. package/src/components/accordion/accordion.render.test.tsx +330 -0
  4. package/src/components/alert/AGENTS.md +1 -0
  5. package/src/components/alert/alert.render.test.tsx +162 -0
  6. package/src/components/animated-badge/AGENTS.md +1 -0
  7. package/src/components/animated-badge/animated-badge.render.test.tsx +136 -0
  8. package/src/components/attachment/AGENTS.md +1 -0
  9. package/src/components/attachment/attachment.render.test.tsx +422 -0
  10. package/src/components/avatar/AGENTS.md +1 -0
  11. package/src/components/avatar/avatar.render.test.tsx +353 -0
  12. package/src/components/badge/AGENTS.md +1 -0
  13. package/src/components/badge/badge.render.test.tsx +216 -0
  14. package/src/components/bottom-sheet/AGENTS.md +1 -0
  15. package/src/components/bottom-sheet/bottom-sheet.render.test.tsx +190 -0
  16. package/src/components/breadcrumb/AGENTS.md +1 -0
  17. package/src/components/breadcrumb/breadcrumb.render.test.tsx +324 -0
  18. package/src/components/button/AGENTS.md +1 -0
  19. package/src/components/button/button.render.test.tsx +67 -0
  20. package/src/components/calendar/AGENTS.md +1 -0
  21. package/src/components/calendar/calendar.render.test.tsx +388 -0
  22. package/src/components/card/AGENTS.md +1 -0
  23. package/src/components/card/card.render.test.tsx +287 -0
  24. package/src/components/carousel/AGENTS.md +3 -0
  25. package/src/components/carousel/carousel-content.tsx +3 -1
  26. package/src/components/carousel/carousel.render.test.tsx +356 -0
  27. package/src/components/chart/AGENTS.md +1 -0
  28. package/src/components/chart/chart.render.test.tsx +443 -0
  29. package/src/components/checkbox/AGENTS.md +2 -0
  30. package/src/components/checkbox/checkbox.render.test.tsx +250 -0
  31. package/src/components/checkbox/checkbox.tsx +2 -1
  32. package/src/components/chip/chip.render.test.tsx +277 -0
  33. package/src/components/circular-text/AGENTS.md +1 -0
  34. package/src/components/circular-text/circular-text.render.test.tsx +154 -0
  35. package/src/components/collapsible/AGENTS.md +1 -0
  36. package/src/components/collapsible/collapsible.render.test.tsx +243 -0
  37. package/src/components/color-picker/AGENTS.md +1 -0
  38. package/src/components/color-picker/color-picker.render.test.tsx +347 -0
  39. package/src/components/combobox/AGENTS.md +1 -0
  40. package/src/components/combobox/combobox.render.test.tsx +464 -0
  41. package/src/components/compare/AGENTS.md +1 -0
  42. package/src/components/compare/compare.render.test.tsx +265 -0
  43. package/src/components/context-menu/AGENTS.md +1 -0
  44. package/src/components/context-menu/context-menu.render.test.tsx +183 -0
  45. package/src/components/countdown/AGENTS.md +1 -0
  46. package/src/components/countdown/countdown.render.test.tsx +194 -0
  47. package/src/components/date-picker/AGENTS.md +1 -0
  48. package/src/components/date-picker/date-picker.render.test.tsx +378 -0
  49. package/src/components/date-time-picker/AGENTS.md +1 -0
  50. package/src/components/date-time-picker/date-time-picker.render.test.tsx +356 -0
  51. package/src/components/dialog/AGENTS.md +1 -0
  52. package/src/components/dialog/dialog.render.test.tsx +67 -0
  53. package/src/components/direction/AGENTS.md +1 -0
  54. package/src/components/direction/direction.render.test.tsx +150 -0
  55. package/src/components/drawer/AGENTS.md +1 -0
  56. package/src/components/drawer/drawer.render.test.tsx +340 -0
  57. package/src/components/empty-state/AGENTS.md +1 -0
  58. package/src/components/empty-state/empty-state.render.test.tsx +134 -0
  59. package/src/components/fab/AGENTS.md +1 -0
  60. package/src/components/fab/fab.render.test.tsx +278 -0
  61. package/src/components/feedback/AGENTS.md +1 -0
  62. package/src/components/feedback/feedback.render.test.tsx +257 -0
  63. package/src/components/field/AGENTS.md +1 -0
  64. package/src/components/field/field.render.test.tsx +361 -0
  65. package/src/components/flip-card/AGENTS.md +1 -0
  66. package/src/components/flip-card/flip-card.render.test.tsx +259 -0
  67. package/src/components/flow/AGENTS.md +1 -0
  68. package/src/components/flow/flow.render.test.tsx +354 -0
  69. package/src/components/frame/AGENTS.md +1 -0
  70. package/src/components/frame/frame.render.test.tsx +273 -0
  71. package/src/components/grid-item/AGENTS.md +1 -0
  72. package/src/components/grid-item/grid-item.render.test.tsx +326 -0
  73. package/src/components/icon/AGENTS.md +1 -0
  74. package/src/components/icon/icon.render.test.tsx +110 -0
  75. package/src/components/image-viewer/AGENTS.md +5 -0
  76. package/src/components/image-viewer/image-viewer.render.test.tsx +244 -0
  77. package/src/components/image-viewer/image-viewer.tsx +6 -3
  78. package/src/components/input/AGENTS.md +1 -0
  79. package/src/components/input/input.render.test.tsx +246 -0
  80. package/src/components/item/AGENTS.md +1 -0
  81. package/src/components/item/item.render.test.tsx +276 -0
  82. package/src/components/kpi/AGENTS.md +1 -0
  83. package/src/components/kpi/kpi.render.test.tsx +232 -0
  84. package/src/components/label/AGENTS.md +1 -0
  85. package/src/components/label/label.render.test.tsx +81 -0
  86. package/src/components/leaderboard/AGENTS.md +1 -0
  87. package/src/components/leaderboard/leaderboard.render.test.tsx +198 -0
  88. package/src/components/list-group/AGENTS.md +1 -0
  89. package/src/components/list-group/list-group.render.test.tsx +279 -0
  90. package/src/components/map/AGENTS.md +1 -0
  91. package/src/components/map/map.render.test.tsx +460 -0
  92. package/src/components/markdown-editor/AGENTS.md +1 -0
  93. package/src/components/markdown-editor/markdown-editor.render.test.tsx +461 -0
  94. package/src/components/marker/AGENTS.md +1 -0
  95. package/src/components/marker/marker.render.test.tsx +232 -0
  96. package/src/components/marquee/AGENTS.md +1 -0
  97. package/src/components/marquee/marquee.render.test.tsx +145 -0
  98. package/src/components/menu/AGENTS.md +2 -0
  99. package/src/components/menu/menu-item.tsx +40 -1
  100. package/src/components/menu/menu.render.test.tsx +449 -0
  101. package/src/components/message/AGENTS.md +1 -0
  102. package/src/components/message/message.render.test.tsx +401 -0
  103. package/src/components/message-scroller/AGENTS.md +1 -0
  104. package/src/components/message-scroller/message-scroller.render.test.tsx +295 -0
  105. package/src/components/meter/AGENTS.md +1 -0
  106. package/src/components/meter/meter.render.test.tsx +249 -0
  107. package/src/components/number-input/AGENTS.md +2 -0
  108. package/src/components/number-input/number-input-field.tsx +3 -2
  109. package/src/components/number-input/number-input.render.test.tsx +426 -0
  110. package/src/components/otp-input/AGENTS.md +3 -0
  111. package/src/components/otp-input/otp-input.render.test.tsx +405 -0
  112. package/src/components/otp-input/otp-input.tsx +9 -2
  113. package/src/components/overlay/AGENTS.md +7 -1
  114. package/src/components/overlay/overlay-teleport.ts +21 -0
  115. package/src/components/overlay/overlay.render.test.tsx +367 -0
  116. package/src/components/overlay/overlay.tsx +5 -2
  117. package/src/components/page-header/AGENTS.md +1 -0
  118. package/src/components/page-header/page-header.render.test.tsx +217 -0
  119. package/src/components/pagination/AGENTS.md +1 -0
  120. package/src/components/pagination/pagination.render.test.tsx +293 -0
  121. package/src/components/planner/AGENTS.md +1 -0
  122. package/src/components/planner/planner.render.test.tsx +429 -0
  123. package/src/components/popover/AGENTS.md +1 -0
  124. package/src/components/popover/popover.render.test.tsx +206 -0
  125. package/src/components/post/AGENTS.md +4 -0
  126. package/src/components/post/post-author.tsx +8 -1
  127. package/src/components/post/post-community.tsx +7 -1
  128. package/src/components/post/post.render.test.tsx +456 -0
  129. package/src/components/pressable/AGENTS.md +7 -0
  130. package/src/components/pressable/pressable.render.test.tsx +183 -0
  131. package/src/components/pressable/pressable.tsx +1 -1
  132. package/src/components/progress/AGENTS.md +1 -0
  133. package/src/components/progress/progress.render.test.tsx +192 -0
  134. package/src/components/progress-button/AGENTS.md +1 -0
  135. package/src/components/progress-button/progress-button.render.test.tsx +251 -0
  136. package/src/components/provider/AGENTS.md +1 -0
  137. package/src/components/provider/provider.render.test.tsx +101 -0
  138. package/src/components/qr-code/AGENTS.md +1 -0
  139. package/src/components/qr-code/qr-code.render.test.tsx +117 -0
  140. package/src/components/questionnaire/AGENTS.md +1 -0
  141. package/src/components/questionnaire/questionnaire.render.test.tsx +549 -0
  142. package/src/components/radio/AGENTS.md +1 -0
  143. package/src/components/radio/radio.render.test.tsx +334 -0
  144. package/src/components/rating/AGENTS.md +5 -0
  145. package/src/components/rating/rating-stars.tsx +4 -0
  146. package/src/components/rating/rating.render.test.tsx +402 -0
  147. package/src/components/screen/AGENTS.md +9 -0
  148. package/src/components/screen/screen-error.tsx +3 -1
  149. package/src/components/screen/screen-navbar-title.tsx +6 -1
  150. package/src/components/screen/screen.render.test.tsx +309 -0
  151. package/src/components/scroll-blur/AGENTS.md +1 -0
  152. package/src/components/scroll-blur/scroll-blur.render.test.tsx +197 -0
  153. package/src/components/scroll-canvas/AGENTS.md +1 -0
  154. package/src/components/scroll-canvas/scroll-canvas.render.test.tsx +184 -0
  155. package/src/components/scroll-fade/AGENTS.md +1 -0
  156. package/src/components/scroll-fade/scroll-fade-edge.tsx +1 -0
  157. package/src/components/scroll-fade/scroll-fade.render.test.tsx +122 -0
  158. package/src/components/scroll-header/AGENTS.md +1 -0
  159. package/src/components/scroll-header/scroll-header.render.test.tsx +168 -0
  160. package/src/components/scroll-text/AGENTS.md +1 -0
  161. package/src/components/scroll-text/scroll-text.render.test.tsx +191 -0
  162. package/src/components/search-bar/AGENTS.md +1 -0
  163. package/src/components/search-bar/search-bar.render.test.tsx +377 -0
  164. package/src/components/section-progress/AGENTS.md +1 -0
  165. package/src/components/section-progress/section-progress.render.test.tsx +186 -0
  166. package/src/components/section-rail/AGENTS.md +1 -0
  167. package/src/components/section-rail/section-rail.render.test.tsx +341 -0
  168. package/src/components/select/AGENTS.md +1 -0
  169. package/src/components/select/select.render.test.tsx +466 -0
  170. package/src/components/selection-mode/AGENTS.md +1 -0
  171. package/src/components/selection-mode/selection-mode.render.test.tsx +487 -0
  172. package/src/components/separator/AGENTS.md +1 -0
  173. package/src/components/separator/separator.render.test.tsx +43 -0
  174. package/src/components/signature/AGENTS.md +4 -0
  175. package/src/components/signature/signature-pad.tsx +4 -0
  176. package/src/components/signature/signature.render.test.tsx +257 -0
  177. package/src/components/skeleton/AGENTS.md +2 -1
  178. package/src/components/skeleton/skeleton.render.test.tsx +222 -0
  179. package/src/components/sketch/AGENTS.md +2 -0
  180. package/src/components/sketch/sketch-canvas.tsx +4 -0
  181. package/src/components/sketch/sketch.render.test.tsx +527 -0
  182. package/src/components/slide-button/AGENTS.md +2 -0
  183. package/src/components/slide-button/slide-button.render.test.tsx +354 -0
  184. package/src/components/slide-button/slide-button.tsx +4 -0
  185. package/src/components/slider/AGENTS.md +12 -0
  186. package/src/components/slider/slider-thumb.tsx +2 -1
  187. package/src/components/slider/slider-track.tsx +4 -1
  188. package/src/components/slider/slider.render.test.tsx +254 -0
  189. package/src/components/slider/slider.tsx +11 -0
  190. package/src/components/sortable/AGENTS.md +2 -0
  191. package/src/components/sortable/sortable-item.tsx +2 -1
  192. package/src/components/sortable/sortable.render.test.tsx +204 -0
  193. package/src/components/spinner/AGENTS.md +3 -0
  194. package/src/components/spinner/spinner.render.test.tsx +88 -0
  195. package/src/components/spinner/spinner.tsx +1 -0
  196. package/src/components/split-view/AGENTS.md +1 -0
  197. package/src/components/split-view/split-view-drag-area.tsx +2 -0
  198. package/src/components/split-view/split-view.render.test.tsx +423 -0
  199. package/src/components/splitter/AGENTS.md +7 -0
  200. package/src/components/splitter/splitter-handle.tsx +2 -0
  201. package/src/components/splitter/splitter.render.test.tsx +307 -0
  202. package/src/components/stack-card/AGENTS.md +3 -0
  203. package/src/components/stack-card/stack-card.render.test.tsx +309 -0
  204. package/src/components/stack-card/stack-card.tsx +1 -1
  205. package/src/components/steps/AGENTS.md +1 -0
  206. package/src/components/steps/steps.render.test.tsx +318 -0
  207. package/src/components/support/AGENTS.md +1 -0
  208. package/src/components/support/support.render.test.tsx +331 -0
  209. package/src/components/surface/AGENTS.md +1 -0
  210. package/src/components/surface/surface.render.test.tsx +129 -0
  211. package/src/components/swipe/AGENTS.md +3 -0
  212. package/src/components/swipe/swipe.render.test.tsx +280 -0
  213. package/src/components/swipe/swipe.tsx +7 -4
  214. package/src/components/switch/AGENTS.md +5 -0
  215. package/src/components/switch/switch.render.test.tsx +46 -0
  216. package/src/components/switch/switch.tsx +5 -1
  217. package/src/components/table/AGENTS.md +1 -0
  218. package/src/components/table/table.render.test.tsx +294 -0
  219. package/src/components/tabs/AGENTS.md +6 -0
  220. package/src/components/tabs/tabs.render.test.tsx +325 -0
  221. package/src/components/tabs/tabs.tsx +12 -1
  222. package/src/components/tag-input/AGENTS.md +1 -0
  223. package/src/components/tag-input/tag-input.render.test.tsx +655 -0
  224. package/src/components/text/AGENTS.md +1 -0
  225. package/src/components/text/text.render.test.tsx +197 -0
  226. package/src/components/text-animation/AGENTS.md +1 -0
  227. package/src/components/text-animation/text-animation.render.test.tsx +283 -0
  228. package/src/components/textarea/AGENTS.md +1 -0
  229. package/src/components/textarea/textarea.render.test.tsx +192 -0
  230. package/src/components/theme-selector/AGENTS.md +1 -0
  231. package/src/components/theme-selector/theme-selector.render.test.tsx +196 -0
  232. package/src/components/time-picker/AGENTS.md +1 -0
  233. package/src/components/time-picker/time-picker.render.test.tsx +466 -0
  234. package/src/components/timeline/AGENTS.md +1 -0
  235. package/src/components/timeline/timeline.render.test.tsx +316 -0
  236. package/src/components/toast/AGENTS.md +1 -0
  237. package/src/components/toast/toast.render.test.tsx +245 -0
  238. package/src/components/toggle-button/AGENTS.md +1 -0
  239. package/src/components/toggle-button/toggle-button.render.test.tsx +392 -0
  240. package/src/components/tooltip/AGENTS.md +1 -0
  241. package/src/components/tooltip/tooltip.render.test.tsx +231 -0
  242. package/src/components/tour/AGENTS.md +1 -0
  243. package/src/components/tour/tour.render.test.tsx +217 -0
  244. package/src/components/tree/AGENTS.md +1 -0
  245. package/src/components/tree/tree.render.test.tsx +395 -0
  246. package/src/display-name.test.ts +9 -3
  247. package/src/render-tests.test.ts +27 -0
  248. package/src/test/AGENTS.md +121 -0
  249. package/src/test/render.tsx +22 -0
  250. package/src/test/setup.ts +142 -0
@@ -0,0 +1,136 @@
1
+ import { afterEach, describe, expect, jest, test } from "@jest/globals";
2
+ import { AccessibilityInfo, Platform } from "react-native";
3
+ import { IconSparkle } from "../../icons/central";
4
+ import { renderWithProviders, screen, within } from "../../test/render";
5
+ import { AnimatedBadge } from "./animated-badge";
6
+
7
+ /**
8
+ * The root, by testID: its inner label is also a `text`-role element, so a role query would find two.
9
+ */
10
+ function root() {
11
+ return screen.getByTestId("badge");
12
+ }
13
+
14
+ /*
15
+ * The roll itself (exit, swap, enter) runs on Reanimated timings that Jest does not advance, so
16
+ * what is asserted is what a screen reader sees: the label, the role, busy, the live region and
17
+ * what is hidden. Layout, the width spring and the pulse are verified in the playground.
18
+ */
19
+ describe("AnimatedBadge", () => {
20
+ afterEach(() => {
21
+ jest.restoreAllMocks();
22
+ });
23
+
24
+ test("is a text element named by its label", async () => {
25
+ await renderWithProviders(
26
+ <AnimatedBadge testID="badge" status="success">
27
+ Live
28
+ </AnimatedBadge>
29
+ );
30
+ expect(root()).toBeOnTheScreen();
31
+ expect(root().props.accessibilityRole).toBe("text");
32
+ expect(root()).toHaveAccessibleName("Live");
33
+ expect(screen.getByText("Live")).toBeOnTheScreen();
34
+ });
35
+
36
+ test("defaults to neutral and is not busy", async () => {
37
+ await renderWithProviders(<AnimatedBadge testID="badge">Idle</AnimatedBadge>);
38
+ expect(root()).not.toBeBusy();
39
+ });
40
+
41
+ test("loading is announced as busy", async () => {
42
+ await renderWithProviders(
43
+ <AnimatedBadge testID="badge" status="loading">
44
+ Building
45
+ </AnimatedBadge>
46
+ );
47
+ expect(root()).toBeBusy();
48
+ expect(root()).toHaveAccessibleName("Building");
49
+ });
50
+
51
+ test("joins an array of text children into the label", async () => {
52
+ await renderWithProviders(
53
+ <AnimatedBadge testID="badge" status="info">
54
+ {["3", " reviews"]}
55
+ </AnimatedBadge>
56
+ );
57
+ expect(root()).toHaveAccessibleName("3 reviews");
58
+ });
59
+
60
+ test("a number child is the label", async () => {
61
+ await renderWithProviders(<AnimatedBadge testID="badge">{7}</AnimatedBadge>);
62
+ expect(root()).toHaveAccessibleName("7");
63
+ });
64
+
65
+ test("an accessibilityLabel beats the label text", async () => {
66
+ await renderWithProviders(
67
+ <AnimatedBadge testID="badge" accessibilityLabel="Deploy status: live">
68
+ Live
69
+ </AnimatedBadge>
70
+ );
71
+ expect(root()).toHaveAccessibleName("Deploy status: live");
72
+ });
73
+
74
+ test("announce is a polite live region on the root, announce={false} is not", async () => {
75
+ const view = await renderWithProviders(<AnimatedBadge testID="badge">Live</AnimatedBadge>);
76
+ expect(root().props.accessibilityLiveRegion).toBe("polite");
77
+
78
+ await view.rerender(
79
+ <AnimatedBadge testID="badge" announce={false}>
80
+ Live
81
+ </AnimatedBadge>
82
+ );
83
+ expect(root().props.accessibilityLiveRegion).toBe("none");
84
+ });
85
+
86
+ test("the invisible measurer is hidden from assistive technology", async () => {
87
+ await renderWithProviders(<AnimatedBadge testID="badge">Live</AnimatedBadge>);
88
+ expect(within(root()).getAllByText("Live", { hidden: true })).toHaveLength(2);
89
+ expect(within(root()).getAllByText("Live")).toHaveLength(1);
90
+ });
91
+
92
+ test("accepts a custom icon, and showIcon={false}, without losing the name", async () => {
93
+ const view = await renderWithProviders(
94
+ <AnimatedBadge testID="badge" icon={IconSparkle} status="info">
95
+ Suggested
96
+ </AnimatedBadge>
97
+ );
98
+ expect(root()).toHaveAccessibleName("Suggested");
99
+
100
+ await view.rerender(
101
+ <AnimatedBadge testID="badge" showIcon={false} status="info">
102
+ Suggested
103
+ </AnimatedBadge>
104
+ );
105
+ expect(root()).toHaveAccessibleName("Suggested");
106
+ });
107
+
108
+ test("a status change with the same words updates busy", async () => {
109
+ const view = await renderWithProviders(
110
+ <AnimatedBadge testID="badge" status="loading">
111
+ Build
112
+ </AnimatedBadge>
113
+ );
114
+ expect(root()).toBeBusy();
115
+
116
+ await view.rerender(
117
+ <AnimatedBadge testID="badge" status="success">
118
+ Build
119
+ </AnimatedBadge>
120
+ );
121
+ expect(root()).not.toBeBusy();
122
+ expect(root()).toHaveAccessibleName("Build");
123
+ });
124
+
125
+ test("does not announce on mount, on iOS", async () => {
126
+ const original = Platform.OS;
127
+ Platform.OS = "ios";
128
+ const announce = jest.spyOn(AccessibilityInfo, "announceForAccessibility").mockImplementation(() => undefined);
129
+ try {
130
+ await renderWithProviders(<AnimatedBadge testID="badge">Live</AnimatedBadge>);
131
+ expect(announce).not.toHaveBeenCalled();
132
+ } finally {
133
+ Platform.OS = original;
134
+ }
135
+ });
136
+ });
@@ -27,6 +27,7 @@ Compound root plus `Attachment.Preview`, `.Content`, `.Name`, `.Meta`, `.Progres
27
27
  | `attachment.variants.test.ts` | |
28
28
  | `attachment.utils.ts` | Sizes, durations, kind and extension inference, middle truncation, every accessibility string |
29
29
  | `attachment.utils.test.ts` | |
30
+ | `attachment.render.test.tsx` | Mounted under Jest — name and role, busy and progress value, the root's `activate`/`longpress`/`remove`/`retry` accessibility actions, the error announcement, parts outside a root, and `Attachment.Group` list semantics |
30
31
 
31
32
  ## Design
32
33
 
@@ -0,0 +1,422 @@
1
+ import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
2
+ import { AccessibilityInfo, Platform, Text } from "react-native";
3
+ import { fireEvent, renderWithProviders, screen } from "../../test/render";
4
+ import { Attachment } from "./attachment";
5
+ import { useAttachment } from "./attachment.context";
6
+
7
+ function activate(element: Parameters<typeof fireEvent>[0], actionName: string) {
8
+ return fireEvent(element, "accessibilityAction", { nativeEvent: { actionName } });
9
+ }
10
+
11
+ async function renderWithoutRoot(ui: React.ReactElement) {
12
+ const original = console.error;
13
+ console.error = () => undefined;
14
+ try {
15
+ return await renderWithProviders(ui);
16
+ } finally {
17
+ console.error = original;
18
+ }
19
+ }
20
+
21
+ describe("Attachment", () => {
22
+ describe("accessible name and role", () => {
23
+ test("a file with no handler is text named by kind, name, size and state", async () => {
24
+ await renderWithProviders(<Attachment kind="file" name="report.pdf" sizeBytes={2_516_582} />);
25
+ expect(screen.getByLabelText("File, report.pdf, 2.4 megabytes")).toBeOnTheScreen();
26
+ });
27
+
28
+ test("an image with no handler is an image", async () => {
29
+ await renderWithProviders(
30
+ <Attachment kind="image" name="vacation.jpg" source={{ uri: "https://x.test/a.jpg" }} />
31
+ );
32
+ expect(screen.getByRole("image", { name: "Photo, vacation.jpg" })).toBeOnTheScreen();
33
+ });
34
+
35
+ test("a handler makes it a button, disabled included", async () => {
36
+ await renderWithProviders(<Attachment isDisabled kind="file" name="report.pdf" onPress={jest.fn()} />);
37
+ expect(screen.getByRole("button", { name: "File, report.pdf" })).toBeOnTheScreen();
38
+ });
39
+
40
+ test("an explicit accessibilityLabel wins", async () => {
41
+ await renderWithProviders(<Attachment accessibilityLabel="Contract" kind="file" name="report.pdf" />);
42
+ expect(screen.getByLabelText("Contract")).toBeOnTheScreen();
43
+ });
44
+
45
+ test("the label carries the upload state", async () => {
46
+ const view = await renderWithProviders(<Attachment kind="file" name="a.pdf" status={{ type: "idle" }} />);
47
+ expect(screen.getByLabelText("File, a.pdf, not sent")).toBeOnTheScreen();
48
+
49
+ await view.rerender(<Attachment kind="file" name="a.pdf" status={{ type: "uploading" }} />);
50
+ expect(screen.getByLabelText("File, a.pdf, uploading")).toBeOnTheScreen();
51
+
52
+ await view.rerender(<Attachment kind="file" name="a.pdf" status={{ message: "Too large", type: "error" }} />);
53
+ expect(screen.getByLabelText("File, a.pdf, upload failed, Too large")).toBeOnTheScreen();
54
+ });
55
+
56
+ test("the default parts show the name and the size", async () => {
57
+ await renderWithProviders(<Attachment kind="file" name="report.pdf" sizeBytes={2_516_582} />);
58
+ expect(screen.getByText("report.pdf")).toBeOnTheScreen();
59
+ expect(screen.getByText(/2\.4 MB/)).toBeOnTheScreen();
60
+ });
61
+
62
+ test("an error shows the app's message as the meta line", async () => {
63
+ await renderWithProviders(
64
+ <Attachment kind="file" name="a.pdf" status={{ message: "Too large", type: "error" }} />
65
+ );
66
+ expect(screen.getByText("Too large")).toBeOnTheScreen();
67
+ });
68
+ });
69
+
70
+ describe("accessibility state", () => {
71
+ test("uploading is busy and idle is not", async () => {
72
+ const view = await renderWithProviders(<Attachment kind="file" name="a.pdf" status={{ type: "uploading" }} />);
73
+ expect(screen.getByLabelText(/uploading/)).toBeBusy();
74
+
75
+ await view.rerender(<Attachment kind="file" name="a.pdf" />);
76
+ expect(screen.getByLabelText("File, a.pdf")).not.toBeBusy();
77
+ });
78
+
79
+ test("isDisabled is announced", async () => {
80
+ await renderWithProviders(<Attachment isDisabled kind="file" name="a.pdf" />);
81
+ expect(screen.getByLabelText("File, a.pdf")).toBeDisabled();
82
+ });
83
+
84
+ test("a determinate upload carries its progress in ten-percent steps as the value", async () => {
85
+ const view = await renderWithProviders(
86
+ <Attachment kind="file" name="a.pdf" status={{ progress: 0.42, type: "uploading" }} />
87
+ );
88
+ expect(screen.getByLabelText(/uploading/)).toHaveAccessibilityValue({ max: 100, min: 0, now: 40 });
89
+
90
+ await view.rerender(<Attachment kind="file" name="a.pdf" status={{ progress: 0.58, type: "uploading" }} />);
91
+ expect(screen.getByLabelText(/uploading/)).toHaveAccessibilityValue({ max: 100, min: 0, now: 60 });
92
+ });
93
+
94
+ test("an indeterminate upload has no value", async () => {
95
+ await renderWithProviders(<Attachment kind="file" name="a.pdf" status={{ type: "uploading" }} />);
96
+ expect(screen.getByLabelText(/uploading/)).not.toHaveAccessibilityValue({ now: 0 });
97
+ });
98
+ });
99
+
100
+ describe("callbacks", () => {
101
+ test("the activate action calls onPress", async () => {
102
+ const onPress = jest.fn();
103
+ await renderWithProviders(<Attachment kind="file" name="a.pdf" onPress={onPress} />);
104
+ await activate(screen.getByRole("button"), "activate");
105
+ expect(onPress).toHaveBeenCalledTimes(1);
106
+ });
107
+
108
+ test("the longpress action calls onLongPress", async () => {
109
+ const onLongPress = jest.fn();
110
+ await renderWithProviders(<Attachment kind="file" name="a.pdf" onLongPress={onLongPress} />);
111
+ await activate(screen.getByRole("button"), "longpress");
112
+ expect(onLongPress).toHaveBeenCalledTimes(1);
113
+ });
114
+
115
+ test("a disabled attachment calls neither onPress nor onLongPress", async () => {
116
+ const onPress = jest.fn();
117
+ const onLongPress = jest.fn();
118
+ await renderWithProviders(
119
+ <Attachment isDisabled kind="file" name="a.pdf" onLongPress={onLongPress} onPress={onPress} />
120
+ );
121
+ const root = screen.getByRole("button");
122
+ await activate(root, "activate");
123
+ await activate(root, "longpress");
124
+ expect(onPress).not.toHaveBeenCalled();
125
+ expect(onLongPress).not.toHaveBeenCalled();
126
+ });
127
+
128
+ test("the remove action calls onRemove and is labelled with the name", async () => {
129
+ const onRemove = jest.fn();
130
+ await renderWithProviders(<Attachment kind="file" name="report.pdf" onRemove={onRemove} />);
131
+ const root = screen.getByLabelText("File, report.pdf");
132
+ expect(root.props.accessibilityActions).toEqual([{ label: "Remove report.pdf", name: "remove" }]);
133
+ await activate(root, "remove");
134
+ expect(onRemove).toHaveBeenCalledTimes(1);
135
+ });
136
+
137
+ test("while uploading the remove action reads as cancel", async () => {
138
+ await renderWithProviders(
139
+ <Attachment kind="file" name="report.pdf" onRemove={jest.fn()} status={{ type: "uploading" }} />
140
+ );
141
+ expect(screen.getByLabelText(/uploading/).props.accessibilityActions).toEqual([
142
+ { label: "Cancel upload", name: "remove" },
143
+ ]);
144
+ });
145
+
146
+ test("removeAccessibilityLabel names the remove action", async () => {
147
+ await renderWithProviders(
148
+ <Attachment kind="file" name="a.pdf" onRemove={jest.fn()} removeAccessibilityLabel="Drop it" />
149
+ );
150
+ expect(screen.getByLabelText("File, a.pdf").props.accessibilityActions).toEqual([
151
+ { label: "Drop it", name: "remove" },
152
+ ]);
153
+ });
154
+
155
+ test("the retry action exists only in error and calls onRetry", async () => {
156
+ const onRetry = jest.fn();
157
+ const view = await renderWithProviders(<Attachment kind="file" name="a.pdf" onRetry={onRetry} />);
158
+ expect(screen.getByLabelText("File, a.pdf").props.accessibilityActions).toBeUndefined();
159
+
160
+ await view.rerender(
161
+ <Attachment kind="file" name="a.pdf" onRetry={onRetry} status={{ message: "Offline", type: "error" }} />
162
+ );
163
+ const root = screen.getByLabelText(/upload failed/);
164
+ expect(root.props.accessibilityActions).toEqual([{ label: "Retry upload", name: "retry" }]);
165
+ await activate(root, "retry");
166
+ expect(onRetry).toHaveBeenCalledTimes(1);
167
+ });
168
+
169
+ test("a disabled attachment withdraws remove and retry", async () => {
170
+ const onRemove = jest.fn();
171
+ const onRetry = jest.fn();
172
+ await renderWithProviders(
173
+ <Attachment
174
+ isDisabled
175
+ kind="file"
176
+ name="a.pdf"
177
+ onRemove={onRemove}
178
+ onRetry={onRetry}
179
+ status={{ message: "Offline", type: "error" }}
180
+ />
181
+ );
182
+ const root = screen.getByLabelText(/upload failed/);
183
+ expect(root.props.accessibilityActions).toBeUndefined();
184
+ await activate(root, "remove");
185
+ await activate(root, "retry");
186
+ expect(onRemove).not.toHaveBeenCalled();
187
+ expect(onRetry).not.toHaveBeenCalled();
188
+ });
189
+
190
+ test("a caller's accessibility actions are kept and onAccessibilityAction still hears every action", async () => {
191
+ const onAccessibilityAction = jest.fn();
192
+ const onRemove = jest.fn();
193
+ await renderWithProviders(
194
+ <Attachment
195
+ accessibilityActions={[{ label: "Share", name: "share" }]}
196
+ kind="file"
197
+ name="a.pdf"
198
+ onAccessibilityAction={onAccessibilityAction}
199
+ onRemove={onRemove}
200
+ />
201
+ );
202
+ const root = screen.getByLabelText("File, a.pdf");
203
+ expect(root.props.accessibilityActions).toEqual([
204
+ { label: "Share", name: "share" },
205
+ { label: "Remove a.pdf", name: "remove" },
206
+ ]);
207
+ await activate(root, "share");
208
+ await activate(root, "remove");
209
+ expect(onAccessibilityAction).toHaveBeenCalledTimes(2);
210
+ expect(onRemove).toHaveBeenCalledTimes(1);
211
+ });
212
+ });
213
+
214
+ describe("default parts", () => {
215
+ test("a remove control is composed in only when there is an onRemove", async () => {
216
+ const view = await renderWithProviders(<Attachment kind="file" name="a.pdf" removeTestID="remove" />);
217
+ expect(screen.queryByTestId("remove", { includeHiddenElements: true })).not.toBeOnTheScreen();
218
+
219
+ await view.rerender(<Attachment kind="file" name="a.pdf" onRemove={jest.fn()} removeTestID="remove" />);
220
+ expect(screen.getByTestId("remove", { includeHiddenElements: true })).toBeOnTheScreen();
221
+ });
222
+
223
+ test("a retry control is composed in only in error with an onRetry", async () => {
224
+ const view = await renderWithProviders(
225
+ <Attachment kind="file" name="a.pdf" onRetry={jest.fn()} retryTestID="retry" />
226
+ );
227
+ expect(screen.queryByTestId("retry", { includeHiddenElements: true })).not.toBeOnTheScreen();
228
+
229
+ await view.rerender(
230
+ <Attachment
231
+ kind="file"
232
+ name="a.pdf"
233
+ onRetry={jest.fn()}
234
+ retryTestID="retry"
235
+ status={{ message: "Offline", type: "error" }}
236
+ />
237
+ );
238
+ expect(screen.getByTestId("retry", { includeHiddenElements: true })).toBeOnTheScreen();
239
+ });
240
+
241
+ test("the remove and retry controls are hidden from assistive technology", async () => {
242
+ await renderWithProviders(
243
+ <Attachment
244
+ kind="file"
245
+ name="a.pdf"
246
+ onRemove={jest.fn()}
247
+ onRetry={jest.fn()}
248
+ removeTestID="remove"
249
+ retryTestID="retry"
250
+ status={{ message: "Offline", type: "error" }}
251
+ />
252
+ );
253
+ expect(screen.queryByTestId("remove")).not.toBeOnTheScreen();
254
+ expect(screen.queryByTestId("retry")).not.toBeOnTheScreen();
255
+ });
256
+
257
+ test("the upload bar is drawn only while uploading, and hidden from assistive technology", async () => {
258
+ const view = await renderWithProviders(<Attachment kind="file" name="a.pdf" />);
259
+ expect(screen.queryByRole("progressbar", { includeHiddenElements: true })).not.toBeOnTheScreen();
260
+
261
+ await view.rerender(<Attachment kind="file" name="a.pdf" status={{ progress: 0.4, type: "uploading" }} />);
262
+ expect(screen.queryByRole("progressbar")).not.toBeOnTheScreen();
263
+ });
264
+
265
+ test("children replace the default parts entirely", async () => {
266
+ await renderWithProviders(
267
+ <Attachment kind="file" name="a.pdf" onRemove={jest.fn()} removeTestID="remove">
268
+ <Text>custom</Text>
269
+ </Attachment>
270
+ );
271
+ expect(screen.getByText("custom")).toBeOnTheScreen();
272
+ expect(screen.queryByText("a.pdf")).not.toBeOnTheScreen();
273
+ expect(screen.queryByTestId("remove", { includeHiddenElements: true })).not.toBeOnTheScreen();
274
+ });
275
+
276
+ test("useAttachment reads the enclosing attachment from custom children", async () => {
277
+ function Probe() {
278
+ const { kind, name, status } = useAttachment();
279
+ return <Text>{`${kind}:${name}:${status.type}`}</Text>;
280
+ }
281
+ await renderWithProviders(
282
+ <Attachment kind="audio" name="memo.m4a" status={{ type: "idle" }}>
283
+ <Probe />
284
+ </Attachment>
285
+ );
286
+ expect(screen.getByText("audio:memo.m4a:idle")).toBeOnTheScreen();
287
+ });
288
+ });
289
+
290
+ describe("error announcement", () => {
291
+ const platform = Platform.OS;
292
+ let announce: ReturnType<typeof jest.spyOn>;
293
+
294
+ beforeEach(() => {
295
+ announce = jest.spyOn(AccessibilityInfo, "announceForAccessibility").mockImplementation(() => undefined);
296
+ announce.mockClear();
297
+ Platform.OS = "ios";
298
+ });
299
+
300
+ afterEach(() => {
301
+ Platform.OS = platform;
302
+ announce.mockRestore();
303
+ });
304
+
305
+ test("entering error announces once; mounting in error announces nothing", async () => {
306
+ const mounted = await renderWithProviders(
307
+ <Attachment kind="file" name="a.pdf" status={{ message: "Offline", type: "error" }} />
308
+ );
309
+ expect(announce).not.toHaveBeenCalled();
310
+ await mounted.unmount();
311
+
312
+ const view = await renderWithProviders(<Attachment kind="file" name="a.pdf" status={{ type: "uploading" }} />);
313
+ await view.rerender(<Attachment kind="file" name="a.pdf" status={{ message: "Offline", type: "error" }} />);
314
+ expect(announce).toHaveBeenCalledTimes(1);
315
+ expect(announce).toHaveBeenCalledWith("Upload failed, a.pdf, Offline");
316
+ });
317
+
318
+ test("an error is a polite live region", async () => {
319
+ await renderWithProviders(<Attachment kind="file" name="a.pdf" status={{ message: "Offline", type: "error" }} />);
320
+ expect(screen.getByLabelText(/upload failed/).props.accessibilityLiveRegion).toBe("polite");
321
+ });
322
+ });
323
+
324
+ describe("compound parts", () => {
325
+ test.each([
326
+ ["Preview", () => <Attachment.Preview />],
327
+ ["Content", () => <Attachment.Content />],
328
+ ["Name", () => <Attachment.Name />],
329
+ ["Meta", () => <Attachment.Meta />],
330
+ ["Progress", () => <Attachment.Progress />],
331
+ ["Remove", () => <Attachment.Remove />],
332
+ ["Retry", () => <Attachment.Retry />],
333
+ ])("Attachment.%s outside an Attachment throws", async (part, render) => {
334
+ await expect(renderWithoutRoot(render())).rejects.toThrow(
335
+ `Attachment.${part} must be rendered inside an <Attachment>.`
336
+ );
337
+ });
338
+
339
+ test("useAttachment outside an Attachment throws", async () => {
340
+ function Probe() {
341
+ useAttachment();
342
+ return null;
343
+ }
344
+ await expect(renderWithoutRoot(<Probe />)).rejects.toThrow(
345
+ "useAttachment must be called inside an <Attachment>."
346
+ );
347
+ });
348
+
349
+ test("parts compose inside custom children", async () => {
350
+ await renderWithProviders(
351
+ <Attachment kind="file" name="report.pdf" sizeBytes={1024}>
352
+ <Attachment.Preview />
353
+ <Attachment.Content>
354
+ <Attachment.Name />
355
+ <Attachment.Meta />
356
+ </Attachment.Content>
357
+ </Attachment>
358
+ );
359
+ expect(screen.getByText("report.pdf")).toBeOnTheScreen();
360
+ expect(screen.getByText(/1 KB/)).toBeOnTheScreen();
361
+ });
362
+ });
363
+
364
+ describe("group", () => {
365
+ test("is a labelled list", async () => {
366
+ await renderWithProviders(
367
+ <Attachment.Group>
368
+ <Attachment kind="file" name="a.pdf" />
369
+ </Attachment.Group>
370
+ );
371
+ expect(screen.getByLabelText("Attachments").props.accessibilityRole).toBe("list");
372
+ });
373
+
374
+ test("accessibilityLabel renames the list", async () => {
375
+ await renderWithProviders(
376
+ <Attachment.Group accessibilityLabel="Files to send">
377
+ <Attachment kind="file" name="a.pdf" />
378
+ </Attachment.Group>
379
+ );
380
+ expect(screen.getByLabelText("Files to send").props.accessibilityRole).toBe("list");
381
+ });
382
+
383
+ test("each attachment hints its place, and a caller's own hint wins", async () => {
384
+ await renderWithProviders(
385
+ <Attachment.Group>
386
+ <Attachment key="a" kind="file" name="a.pdf" />
387
+ <Attachment key="b" kind="file" name="b.pdf" />
388
+ <Attachment accessibilityHint="Custom" key="c" kind="file" name="c.pdf" />
389
+ </Attachment.Group>
390
+ );
391
+ expect(screen.getByLabelText("File, a.pdf").props.accessibilityHint).toBe("1 of 3");
392
+ expect(screen.getByLabelText("File, b.pdf").props.accessibilityHint).toBe("2 of 3");
393
+ expect(screen.getByLabelText("File, c.pdf").props.accessibilityHint).toBe("Custom");
394
+ });
395
+
396
+ test("removing one renumbers the rest", async () => {
397
+ const view = await renderWithProviders(
398
+ <Attachment.Group>
399
+ <Attachment key="a" kind="file" name="a.pdf" />
400
+ <Attachment key="b" kind="file" name="b.pdf" />
401
+ </Attachment.Group>
402
+ );
403
+ await view.rerender(
404
+ <Attachment.Group>
405
+ <Attachment key="b" kind="file" name="b.pdf" />
406
+ </Attachment.Group>
407
+ );
408
+ expect(screen.getByLabelText("File, b.pdf").props.accessibilityHint).toBe("1 of 1");
409
+ });
410
+
411
+ test("children keep working inside a group", async () => {
412
+ const onRemove = jest.fn();
413
+ await renderWithProviders(
414
+ <Attachment.Group layout="card" size="lg">
415
+ <Attachment key="a" kind="file" name="a.pdf" onRemove={onRemove} />
416
+ </Attachment.Group>
417
+ );
418
+ await activate(screen.getByLabelText("File, a.pdf"), "remove");
419
+ expect(onRemove).toHaveBeenCalledTimes(1);
420
+ });
421
+ });
422
+ });
@@ -15,6 +15,7 @@ Compound root plus `Avatar.Badge` and `Avatar.Group`.
15
15
  | `avatar-badge.tsx` | `Avatar.Badge` — the corner overlay, a presence dot when empty |
16
16
  | `avatar-group.tsx` | `Avatar.Group`, plus its internal `Item` and `Overflow` leaves |
17
17
  | `avatar.context.tsx` | `AvatarProvider`, `AvatarGroupProvider`, `useAvatar()`, `useAvatarContext()`, `useAvatarGroupContext()`, `useAvatarPart()` |
18
+ | `avatar.render.test.tsx` | Mounted under Jest — accessible name and role, fallback initials, image failure and retry, press and disabled, `Avatar.Badge`, `Avatar.Group` overflow and list semantics, context and out-of-root errors |
18
19
  | `avatar.variants.ts` | Pure `tv()` slots, `AVATAR_SIZE_POINTS`, `resolveAvatarSize`, `resolveAvatarOverlap`, `resolveAvatarInteractive` |
19
20
  | `avatar.variants.test.ts` | |
20
21
  | `avatar.utils.ts` | Pure non-styling logic — initials, the image-retry key, flattening a group's fragments, group overflow maths, the spoken label |