@terreno/ui 57.2.0 → 57.4.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 (383) hide show
  1. package/.ai/guidelines/core.md +1 -1
  2. package/README.md +17 -8
  3. package/dist/ActionSheet.d.ts +3 -3
  4. package/dist/ActionSheet.js +2 -2
  5. package/dist/ActionSheet.js.map +1 -1
  6. package/dist/AnnouncementBanner.d.ts +12 -0
  7. package/dist/AnnouncementBanner.js +61 -0
  8. package/dist/AnnouncementBanner.js.map +1 -0
  9. package/dist/AnnouncementNavigator.d.ts +11 -0
  10. package/dist/AnnouncementNavigator.js +189 -0
  11. package/dist/AnnouncementNavigator.js.map +1 -0
  12. package/dist/AnnouncementScreen.d.ts +12 -0
  13. package/dist/AnnouncementScreen.js +28 -0
  14. package/dist/AnnouncementScreen.js.map +1 -0
  15. package/dist/AreaChart.d.ts +5 -0
  16. package/dist/AreaChart.js +69 -0
  17. package/dist/AreaChart.js.map +1 -0
  18. package/dist/BarChart.d.ts +5 -0
  19. package/dist/BarChart.js +89 -0
  20. package/dist/BarChart.js.map +1 -0
  21. package/dist/Box.d.ts +1 -1
  22. package/dist/Box.js +219 -177
  23. package/dist/Box.js.map +1 -1
  24. package/dist/Button.js +116 -35
  25. package/dist/Button.js.map +1 -1
  26. package/dist/Common.d.ts +215 -9
  27. package/dist/Common.js.map +1 -1
  28. package/dist/ConsentFormScreen.js +46 -12
  29. package/dist/ConsentFormScreen.js.map +1 -1
  30. package/dist/ConsentNavigator.d.ts +5 -1
  31. package/dist/ConsentNavigator.js.map +1 -1
  32. package/dist/DashboardGrid.d.ts +4 -0
  33. package/dist/DashboardGrid.js +38 -0
  34. package/dist/DashboardGrid.js.map +1 -0
  35. package/dist/DataTable.d.ts +2 -2
  36. package/dist/DataTable.js +278 -47
  37. package/dist/DataTable.js.map +1 -1
  38. package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
  39. package/dist/DataTableHeaderInfoMarkdown.js +7 -0
  40. package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
  41. package/dist/DonutChart.d.ts +5 -0
  42. package/dist/DonutChart.js +84 -0
  43. package/dist/DonutChart.js.map +1 -0
  44. package/dist/EmojiSelector.d.ts +2 -46
  45. package/dist/EmojiSelector.js +46 -56
  46. package/dist/EmojiSelector.js.map +1 -1
  47. package/dist/Filter.js +12 -2
  48. package/dist/Filter.js.map +1 -1
  49. package/dist/GPTChat.d.ts +7 -1
  50. package/dist/GPTChat.js +28 -15
  51. package/dist/GPTChat.js.map +1 -1
  52. package/dist/Heading.d.ts +5 -2
  53. package/dist/Heading.js +6 -8
  54. package/dist/Heading.js.map +1 -1
  55. package/dist/Hyperlink.js.map +1 -1
  56. package/dist/Icon.d.ts +1 -2
  57. package/dist/Icon.js +4 -1
  58. package/dist/Icon.js.map +1 -1
  59. package/dist/LineChart.d.ts +5 -0
  60. package/dist/LineChart.js +68 -0
  61. package/dist/LineChart.js.map +1 -0
  62. package/dist/MarkdownEmbed.d.ts +6 -0
  63. package/dist/MarkdownEmbed.js +17 -0
  64. package/dist/MarkdownEmbed.js.map +1 -0
  65. package/dist/MarkdownView.d.ts +6 -3
  66. package/dist/MarkdownView.js +81 -44
  67. package/dist/MarkdownView.js.map +1 -1
  68. package/dist/MediaQuery.d.ts +5 -3
  69. package/dist/MediaQuery.js +9 -40
  70. package/dist/MediaQuery.js.map +1 -1
  71. package/dist/Modal.js +12 -10
  72. package/dist/Modal.js.map +1 -1
  73. package/dist/ModalSheet.d.ts +5 -1
  74. package/dist/ModalSheet.js +31 -13
  75. package/dist/ModalSheet.js.map +1 -1
  76. package/dist/MultiselectField.js +4 -9
  77. package/dist/MultiselectField.js.map +1 -1
  78. package/dist/NotificationBell.d.ts +16 -0
  79. package/dist/NotificationBell.js +15 -0
  80. package/dist/NotificationBell.js.map +1 -0
  81. package/dist/NotificationInbox.d.ts +21 -0
  82. package/dist/NotificationInbox.js +41 -0
  83. package/dist/NotificationInbox.js.map +1 -0
  84. package/dist/NotificationPreferences.d.ts +14 -0
  85. package/dist/NotificationPreferences.js +32 -0
  86. package/dist/NotificationPreferences.js.map +1 -0
  87. package/dist/OpenAPIContext.js +7 -6
  88. package/dist/OpenAPIContext.js.map +1 -1
  89. package/dist/Page.js +7 -1
  90. package/dist/Page.js.map +1 -1
  91. package/dist/PickerSelect.js +8 -1
  92. package/dist/PickerSelect.js.map +1 -1
  93. package/dist/Popover.d.ts +12 -0
  94. package/dist/Popover.js +37 -0
  95. package/dist/Popover.js.map +1 -0
  96. package/dist/PortalHost.js +10 -1
  97. package/dist/PortalHost.js.map +1 -1
  98. package/dist/ResponsiveBreakpoint.d.ts +65 -0
  99. package/dist/ResponsiveBreakpoint.js +111 -0
  100. package/dist/ResponsiveBreakpoint.js.map +1 -0
  101. package/dist/SplitPage.d.ts +2 -2
  102. package/dist/SplitPage.js +7 -12
  103. package/dist/SplitPage.js.map +1 -1
  104. package/dist/SplitPage.native.d.ts +2 -2
  105. package/dist/SplitPage.native.js +1 -6
  106. package/dist/SplitPage.native.js.map +1 -1
  107. package/dist/TapToEdit.js +12 -10
  108. package/dist/TapToEdit.js.map +1 -1
  109. package/dist/TerrenoFontProvider.d.ts +7 -0
  110. package/dist/TerrenoFontProvider.js +27 -0
  111. package/dist/TerrenoFontProvider.js.map +1 -0
  112. package/dist/TerrenoProvider.js +4 -2
  113. package/dist/TerrenoProvider.js.map +1 -1
  114. package/dist/Text.d.ts +5 -2
  115. package/dist/Text.js +6 -11
  116. package/dist/Text.js.map +1 -1
  117. package/dist/TextField.js +83 -6
  118. package/dist/TextField.js.map +1 -1
  119. package/dist/TextFieldNumberActionSheet.js +9 -2
  120. package/dist/TextFieldNumberActionSheet.js.map +1 -1
  121. package/dist/Theme.js +10 -8
  122. package/dist/Theme.js.map +1 -1
  123. package/dist/ToastNotifications.d.ts +4 -2
  124. package/dist/ToastNotifications.js.map +1 -1
  125. package/dist/Tooltip.d.ts +4 -3
  126. package/dist/Tooltip.js +14 -3
  127. package/dist/Tooltip.js.map +1 -1
  128. package/dist/Unifier.d.ts +26 -1
  129. package/dist/Unifier.js.map +1 -1
  130. package/dist/WebAddressAutocomplete.js +6 -1
  131. package/dist/WebAddressAutocomplete.js.map +1 -1
  132. package/dist/announcementBuildVersion.d.ts +6 -0
  133. package/dist/announcementBuildVersion.js +21 -0
  134. package/dist/announcementBuildVersion.js.map +1 -0
  135. package/dist/announcementFrequency.d.ts +42 -0
  136. package/dist/announcementFrequency.js +163 -0
  137. package/dist/announcementFrequency.js.map +1 -0
  138. package/dist/announcementPlatform.d.ts +2 -0
  139. package/dist/announcementPlatform.js +11 -0
  140. package/dist/announcementPlatform.js.map +1 -0
  141. package/dist/charts/ChartFrame.d.ts +12 -0
  142. package/dist/charts/ChartFrame.js +13 -0
  143. package/dist/charts/ChartFrame.js.map +1 -0
  144. package/dist/charts/bars.d.ts +18 -0
  145. package/dist/charts/bars.js +29 -0
  146. package/dist/charts/bars.js.map +1 -0
  147. package/dist/charts/layout.d.ts +47 -0
  148. package/dist/charts/layout.js +56 -0
  149. package/dist/charts/layout.js.map +1 -0
  150. package/dist/charts/paths.d.ts +31 -0
  151. package/dist/charts/paths.js +52 -0
  152. package/dist/charts/paths.js.map +1 -0
  153. package/dist/charts/scales.d.ts +6 -0
  154. package/dist/charts/scales.js +43 -0
  155. package/dist/charts/scales.js.map +1 -0
  156. package/dist/charts/theme.d.ts +9 -0
  157. package/dist/charts/theme.js +15 -0
  158. package/dist/charts/theme.js.map +1 -0
  159. package/dist/charts/types/chartTypes.d.ts +17 -0
  160. package/dist/charts/types/chartTypes.js +2 -0
  161. package/dist/charts/types/chartTypes.js.map +1 -0
  162. package/dist/dashboardGridLayout.d.ts +22 -0
  163. package/dist/dashboardGridLayout.js +33 -0
  164. package/dist/dashboardGridLayout.js.map +1 -0
  165. package/dist/dataTableFilters.d.ts +33 -0
  166. package/dist/dataTableFilters.js +221 -0
  167. package/dist/dataTableFilters.js.map +1 -0
  168. package/dist/dataTableListQuery.d.ts +42 -0
  169. package/dist/dataTableListQuery.js +161 -0
  170. package/dist/dataTableListQuery.js.map +1 -0
  171. package/dist/emojiCategories.d.ts +46 -0
  172. package/dist/emojiCategories.js +47 -0
  173. package/dist/emojiCategories.js.map +1 -0
  174. package/dist/index.d.ts +30 -13
  175. package/dist/index.js +12 -13
  176. package/dist/index.js.map +1 -1
  177. package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
  178. package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
  179. package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
  180. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +53 -0
  181. package/dist/lazyBoundaries/heavyOptionalExports.js +51 -0
  182. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
  183. package/dist/login/LoginScreen.d.ts +1 -0
  184. package/dist/login/LoginScreen.js +4 -2
  185. package/dist/login/LoginScreen.js.map +1 -1
  186. package/dist/login/loginTypes.d.ts +2 -0
  187. package/dist/markdownEmbeds.d.ts +6 -0
  188. package/dist/markdownEmbeds.js +59 -0
  189. package/dist/markdownEmbeds.js.map +1 -0
  190. package/dist/testing/resolveTestId.js +2 -1
  191. package/dist/testing/resolveTestId.js.map +1 -1
  192. package/dist/testing/types.d.ts +3 -0
  193. package/dist/textFieldOscillationGuard.d.ts +25 -0
  194. package/dist/textFieldOscillationGuard.js +41 -0
  195. package/dist/textFieldOscillationGuard.js.map +1 -0
  196. package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
  197. package/dist/useAcknowledgeAnnouncement.js +94 -0
  198. package/dist/useAcknowledgeAnnouncement.js.map +1 -0
  199. package/dist/useAnnouncements.d.ts +73 -0
  200. package/dist/useAnnouncements.js +66 -0
  201. package/dist/useAnnouncements.js.map +1 -0
  202. package/package.json +46 -18
  203. package/src/AIRequestExplorer.test.tsx +141 -0
  204. package/src/ActionSheet.tsx +9 -7
  205. package/src/AnnouncementBanner.test.tsx +267 -0
  206. package/src/AnnouncementBanner.tsx +128 -0
  207. package/src/AnnouncementNavigator.test.tsx +759 -0
  208. package/src/AnnouncementNavigator.tsx +287 -0
  209. package/src/AnnouncementScreen.test.tsx +97 -0
  210. package/src/AnnouncementScreen.tsx +70 -0
  211. package/src/AreaChart.test.tsx +68 -0
  212. package/src/AreaChart.tsx +194 -0
  213. package/src/AttachmentPreview.test.tsx +80 -0
  214. package/src/BarChart.test.tsx +96 -0
  215. package/src/BarChart.tsx +208 -0
  216. package/src/Box.test.tsx +97 -10
  217. package/src/Box.tsx +263 -200
  218. package/src/Button.test.tsx +273 -0
  219. package/src/Button.tsx +163 -50
  220. package/src/Common.ts +219 -25
  221. package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
  222. package/src/ConsentFormScreen.test.tsx +145 -8
  223. package/src/ConsentFormScreen.tsx +74 -25
  224. package/src/ConsentNavigator.test.tsx +55 -0
  225. package/src/ConsentNavigator.tsx +13 -5
  226. package/src/DashboardGrid.test.tsx +75 -0
  227. package/src/DashboardGrid.tsx +69 -0
  228. package/src/DataTable.test.tsx +296 -1
  229. package/src/DataTable.tsx +623 -160
  230. package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
  231. package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
  232. package/src/DataTableVirtualizationRegression.test.tsx +266 -0
  233. package/src/DateTimeField.test.tsx +54 -0
  234. package/src/DonutChart.test.tsx +121 -0
  235. package/src/DonutChart.tsx +160 -0
  236. package/src/EmojiSelector.test.tsx +84 -42
  237. package/src/EmojiSelector.tsx +60 -57
  238. package/src/Field.test.tsx +18 -0
  239. package/src/FilePickerButton.test.tsx +167 -0
  240. package/src/Filter.test.tsx +25 -0
  241. package/src/Filter.tsx +38 -7
  242. package/src/FilterAccordion.test.tsx +37 -0
  243. package/src/FilterBoolean.test.tsx +96 -0
  244. package/src/FilterSelectMenu.test.tsx +23 -0
  245. package/src/GPTChat.test.tsx +803 -0
  246. package/src/GPTChat.tsx +177 -87
  247. package/src/GPTMemoryModal.test.tsx +67 -0
  248. package/src/Heading.tsx +8 -14
  249. package/src/HeightActionSheet.test.tsx +6 -9
  250. package/src/Hyperlink.tsx +5 -18
  251. package/src/Icon.tsx +6 -2
  252. package/src/LineChart.test.tsx +166 -0
  253. package/src/LineChart.tsx +190 -0
  254. package/src/MarkdownEditor.test.tsx +134 -0
  255. package/src/MarkdownEditorField.test.tsx +124 -0
  256. package/src/MarkdownEmbed.test.tsx +34 -0
  257. package/src/MarkdownEmbed.tsx +43 -0
  258. package/src/MarkdownView.test.tsx +112 -11
  259. package/src/MarkdownView.tsx +197 -150
  260. package/src/MediaQuery.ts +30 -34
  261. package/src/Modal.test.tsx +107 -14
  262. package/src/Modal.tsx +20 -8
  263. package/src/ModalSheet.test.tsx +121 -9
  264. package/src/ModalSheet.tsx +46 -11
  265. package/src/MultiselectField.test.tsx +21 -0
  266. package/src/MultiselectField.tsx +11 -13
  267. package/src/NotificationBell.test.tsx +91 -0
  268. package/src/NotificationBell.tsx +77 -0
  269. package/src/NotificationInbox.test.tsx +130 -0
  270. package/src/NotificationInbox.tsx +144 -0
  271. package/src/NotificationPreferences.test.tsx +25 -0
  272. package/src/NotificationPreferences.tsx +75 -0
  273. package/src/OpenAPIContext.tsx +36 -29
  274. package/src/OpenAPIRenderRegression.test.tsx +200 -0
  275. package/src/P0RenderRegression.test.tsx +214 -0
  276. package/src/P1RenderRegression.test.tsx +141 -0
  277. package/src/P2ButtonRenderRegression.test.tsx +158 -0
  278. package/src/Page.test.tsx +13 -0
  279. package/src/Page.tsx +25 -5
  280. package/src/PickerSelect.test.tsx +38 -0
  281. package/src/PickerSelect.tsx +7 -0
  282. package/src/Popover.test.tsx +151 -0
  283. package/src/Popover.tsx +211 -0
  284. package/src/PortalHost.tsx +12 -6
  285. package/src/ResponsiveBreakpoint.test.tsx +184 -0
  286. package/src/ResponsiveBreakpoint.tsx +195 -0
  287. package/src/RootImportRegression.test.tsx +82 -0
  288. package/src/SplitPage.native.tsx +5 -9
  289. package/src/SplitPage.tsx +16 -19
  290. package/src/TapToEdit.test.tsx +45 -0
  291. package/src/TapToEdit.tsx +23 -18
  292. package/src/TerrenoFontProvider.test.tsx +38 -0
  293. package/src/TerrenoFontProvider.tsx +50 -0
  294. package/src/TerrenoProvider.tsx +6 -1
  295. package/src/Text.tsx +8 -21
  296. package/src/TextField.test.tsx +421 -0
  297. package/src/TextField.tsx +121 -4
  298. package/src/TextFieldNumberActionSheet.test.tsx +100 -0
  299. package/src/TextFieldNumberActionSheet.tsx +11 -2
  300. package/src/Theme.test.tsx +27 -0
  301. package/src/Theme.tsx +15 -10
  302. package/src/Toast.tsx +1 -1
  303. package/src/ToastNotifications.tsx +4 -4
  304. package/src/Tooltip.test.tsx +64 -0
  305. package/src/Tooltip.tsx +18 -4
  306. package/src/Unifier.ts +26 -3
  307. package/src/WebAddressAutocomplete.tsx +6 -2
  308. package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
  309. package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
  310. package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
  311. package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
  312. package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
  313. package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
  314. package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
  315. package/src/__snapshots__/Field.test.tsx.snap +29 -0
  316. package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
  317. package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
  318. package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
  319. package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
  320. package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
  321. package/src/__snapshots__/Page.test.tsx.snap +13 -1
  322. package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
  323. package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
  324. package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
  325. package/src/__snapshots__/TextField.test.tsx.snap +5 -5
  326. package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
  327. package/src/announcementBuildVersion.test.ts +43 -0
  328. package/src/announcementBuildVersion.ts +21 -0
  329. package/src/announcementFrequency.test.ts +245 -0
  330. package/src/announcementFrequency.ts +246 -0
  331. package/src/announcementPlatform.test.ts +27 -0
  332. package/src/announcementPlatform.ts +13 -0
  333. package/src/benchmarks/importGraph.test.ts +71 -0
  334. package/src/benchmarks/importGraph.ts +136 -0
  335. package/src/benchmarks/importTiming.test.ts +42 -0
  336. package/src/benchmarks/importTiming.ts +86 -0
  337. package/src/bunSetup.ts +174 -32
  338. package/src/charts/ChartFrame.tsx +67 -0
  339. package/src/charts/bars.test.ts +56 -0
  340. package/src/charts/bars.ts +53 -0
  341. package/src/charts/layout.test.ts +80 -0
  342. package/src/charts/layout.ts +99 -0
  343. package/src/charts/paths.test.ts +79 -0
  344. package/src/charts/paths.ts +100 -0
  345. package/src/charts/scales.test.ts +59 -0
  346. package/src/charts/scales.ts +60 -0
  347. package/src/charts/theme.test.ts +22 -0
  348. package/src/charts/theme.ts +24 -0
  349. package/src/charts/types/chartTypes.ts +19 -0
  350. package/src/dashboardGridLayout.test.ts +90 -0
  351. package/src/dashboardGridLayout.ts +60 -0
  352. package/src/dataTableFilters.test.tsx +552 -0
  353. package/src/dataTableFilters.tsx +441 -0
  354. package/src/dataTableListQuery.test.ts +220 -0
  355. package/src/dataTableListQuery.ts +201 -0
  356. package/src/emojiCategories.test.ts +23 -0
  357. package/src/emojiCategories.ts +46 -0
  358. package/src/index.tsx +48 -14
  359. package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
  360. package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
  361. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
  362. package/src/lazyBoundaries/heavyOptionalExports.tsx +134 -0
  363. package/src/login/LoginScreen.test.tsx +9 -2
  364. package/src/login/LoginScreen.tsx +6 -2
  365. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
  366. package/src/login/loginTypes.ts +2 -0
  367. package/src/markdownEmbeds.test.ts +53 -0
  368. package/src/markdownEmbeds.ts +62 -0
  369. package/src/pdfHtmlTemplate.test.ts +119 -0
  370. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
  371. package/src/table/TableDate.test.tsx +35 -1
  372. package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
  373. package/src/testing/resolveTestId.test.ts +3 -0
  374. package/src/testing/resolveTestId.ts +1 -0
  375. package/src/testing/types.ts +3 -0
  376. package/src/textFieldOscillationGuard.test.ts +63 -0
  377. package/src/textFieldOscillationGuard.ts +89 -0
  378. package/src/types/react-native-markdown-display.d.ts +6 -0
  379. package/src/types/react-native-swiper-flatlist.d.ts +5 -5
  380. package/src/useAcknowledgeAnnouncement.test.ts +223 -0
  381. package/src/useAcknowledgeAnnouncement.ts +166 -0
  382. package/src/useAnnouncements.test.ts +226 -0
  383. package/src/useAnnouncements.ts +150 -0
@@ -0,0 +1,803 @@
1
+ import {afterAll, afterEach, describe, it, mock} from "bun:test";
2
+ import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
+ import {assert} from "chai";
4
+ import React from "react";
5
+ import {Platform, Pressable, ScrollView} from "react-native";
6
+
7
+ import type {SelectedFile} from "./FilePickerButton";
8
+ import type {GPTChatHistory, GPTChatMessage, GPTChatProps, MessageContentPart} from "./GPTChat";
9
+ import {GPTChat} from "./GPTChat";
10
+ import {Text} from "./Text";
11
+ import {ThemeProvider} from "./Theme";
12
+ import {renderWithTheme} from "./test-utils";
13
+
14
+ const setStringAsync = mock(async (_text: string) => {});
15
+ mock.module("expo-clipboard", () => ({setStringAsync}));
16
+
17
+ const pickedDocument = {mimeType: "text/plain", name: "notes.txt", uri: "file:///notes.txt"};
18
+ mock.module("expo-document-picker", () => ({
19
+ getDocumentAsync: mock(async () => ({assets: [pickedDocument], canceled: false})),
20
+ }));
21
+
22
+ // bunSetup.ts mocks IconButton to render null; GPTChat's controls are icon buttons, so replace it
23
+ // with a pressable stub that keeps the accessibility label and testID.
24
+ mock.module("./IconButton", () => ({
25
+ IconButton: ({
26
+ accessibilityLabel,
27
+ disabled,
28
+ onClick,
29
+ testID,
30
+ }: {
31
+ accessibilityLabel?: string;
32
+ disabled?: boolean;
33
+ onClick?: () => void;
34
+ testID?: string;
35
+ }) => React.createElement(Pressable, {accessibilityLabel, disabled, onPress: onClick, testID}),
36
+ }));
37
+
38
+ // Module mocks are global, so restore the bunSetup stub for test files that run after this one.
39
+ afterAll(() => {
40
+ mock.module("./IconButton", () => ({IconButton: mock(() => null)}));
41
+ });
42
+
43
+ // Box and IconButton presses run through an async haptic call, so state updates land in a
44
+ // microtask after the event.
45
+ const press = async (element: Parameters<typeof fireEvent.press>[0]): Promise<void> => {
46
+ await act(async () => {
47
+ fireEvent.press(element);
48
+ });
49
+ };
50
+
51
+ const histories: GPTChatHistory[] = [
52
+ {id: "h1", prompts: [], title: "First chat"},
53
+ {id: "h2", prompts: []},
54
+ ];
55
+
56
+ const renderChat = (overrides: Partial<GPTChatProps> = {}): ReturnType<typeof renderWithTheme> => {
57
+ return renderWithTheme(
58
+ <GPTChat
59
+ currentMessages={[]}
60
+ histories={histories}
61
+ onCreateHistory={() => {}}
62
+ onDeleteHistory={() => {}}
63
+ onSelectHistory={() => {}}
64
+ onSubmit={() => {}}
65
+ testID="gpt-chat"
66
+ {...overrides}
67
+ />
68
+ );
69
+ };
70
+
71
+ describe("GPTChat", () => {
72
+ it("renders the sidebar with chat histories", () => {
73
+ const {getByTestId, getByText} = renderChat();
74
+
75
+ assert.isOk(getByTestId("gpt-chat"));
76
+ assert.isOk(getByText("Chats"));
77
+ assert.isOk(getByText("First chat"));
78
+ assert.isOk(getByText("New Chat"));
79
+ });
80
+
81
+ it("selects, creates, and deletes histories", async () => {
82
+ const onSelectHistory = mock((_id: string) => {});
83
+ const onCreateHistory = mock(() => {});
84
+ const onDeleteHistory = mock((_id: string) => {});
85
+ const {getByLabelText, getByTestId} = renderChat({
86
+ currentHistoryId: "h1",
87
+ onCreateHistory,
88
+ onDeleteHistory,
89
+ onSelectHistory,
90
+ });
91
+
92
+ await press(getByLabelText("Select chat: First chat"));
93
+ await press(getByTestId("gpt-new-chat-button"));
94
+ await press(getByTestId("gpt-delete-history-h2"));
95
+
96
+ assert.deepEqual(onSelectHistory.mock.calls, [["h1"]]);
97
+ assert.equal(onCreateHistory.mock.calls.length, 1);
98
+ assert.deepEqual(onDeleteHistory.mock.calls, [["h2"]]);
99
+ });
100
+
101
+ it("renames a history and saves the new title once", async () => {
102
+ const onUpdateTitle = mock((_id: string, _title: string) => {});
103
+ const {getByTestId} = renderChat({onUpdateTitle});
104
+
105
+ await press(getByTestId("gpt-rename-history-h1"));
106
+ fireEvent.changeText(getByTestId("gpt-rename-input-h1"), "Renamed");
107
+ await press(getByTestId("gpt-rename-save-h1"));
108
+
109
+ assert.deepEqual(onUpdateTitle.mock.calls, [["h1", "Renamed"]]);
110
+ });
111
+
112
+ it("ignores a rename with a blank title and skips duplicate saves", async () => {
113
+ const onUpdateTitle = mock((_id: string, _title: string) => {});
114
+ const {getByTestId} = renderChat({onUpdateTitle});
115
+
116
+ await press(getByTestId("gpt-rename-history-h2"));
117
+ fireEvent.changeText(getByTestId("gpt-rename-input-h2"), " ");
118
+ fireEvent(getByTestId("gpt-rename-input-h2"), "blur");
119
+
120
+ assert.equal(onUpdateTitle.mock.calls.length, 0);
121
+ });
122
+
123
+ it("hides the rename button when renaming is not supported", () => {
124
+ const {queryByTestId} = renderChat();
125
+
126
+ assert.isNull(queryByTestId("gpt-rename-history-h1"));
127
+ });
128
+
129
+ it("renders a model selector only when models and a change handler are given", () => {
130
+ const onModelChange = mock((_id: string) => {});
131
+ const {getAllByText} = renderChat({
132
+ availableModels: [
133
+ {label: "Flash", value: "flash"},
134
+ {label: "Pro", value: "pro"},
135
+ ],
136
+ onModelChange,
137
+ selectedModel: "pro",
138
+ });
139
+
140
+ assert.isNotEmpty(getAllByText("Pro"));
141
+ });
142
+
143
+ it("omits the model selector when there is no change handler", () => {
144
+ const {queryByText} = renderChat({
145
+ availableModels: [{label: "Flash", value: "flash"}],
146
+ });
147
+
148
+ assert.isNull(queryByText("Flash"));
149
+ });
150
+
151
+ it("hides the optional sidebar buttons when their handlers are missing", () => {
152
+ const {queryByTestId} = renderChat({mcpServers: []});
153
+
154
+ assert.isNull(queryByTestId("gpt-api-key-button"));
155
+ assert.isNull(queryByTestId("gpt-memory-button"));
156
+ });
157
+
158
+ it("edits the Gemini API key through the modal", async () => {
159
+ const onGeminiApiKeyChange = mock((_key: string) => {});
160
+ const {getByTestId, getByText} = renderChat({geminiApiKey: "old-key", onGeminiApiKeyChange});
161
+
162
+ await press(getByTestId("gpt-api-key-button"));
163
+ fireEvent.changeText(getByTestId("gpt-api-key-input"), "new-key");
164
+ await press(getByText("Save"));
165
+
166
+ assert.deepEqual(onGeminiApiKeyChange.mock.calls, [["new-key"]]);
167
+ });
168
+
169
+ it("dismisses the API key modal without saving", async () => {
170
+ const onGeminiApiKeyChange = mock((_key: string) => {});
171
+ const {getByTestId, getByText} = renderChat({onGeminiApiKeyChange});
172
+
173
+ await press(getByTestId("gpt-api-key-button"));
174
+ await press(getByText("Cancel"));
175
+
176
+ assert.equal(onGeminiApiKeyChange.mock.calls.length, 0);
177
+ });
178
+
179
+ it("opens the system memory editor with the current memory", async () => {
180
+ const onMemoryEdit = mock((_memory: string) => {});
181
+ const {getByTestId} = renderChat({onMemoryEdit, systemMemory: "remember this"});
182
+
183
+ await press(getByTestId("gpt-memory-button"));
184
+
185
+ assert.deepEqual(onMemoryEdit.mock.calls, [["remember this"]]);
186
+ });
187
+
188
+ it("opens the system memory editor with an empty memory by default", async () => {
189
+ const onMemoryEdit = mock((_memory: string) => {});
190
+ const {getByTestId} = renderChat({onMemoryEdit});
191
+
192
+ await press(getByTestId("gpt-memory-button"));
193
+
194
+ assert.deepEqual(onMemoryEdit.mock.calls, [[""]]);
195
+ });
196
+
197
+ it("toggles the MCP server list", async () => {
198
+ const {getByLabelText, getByText, queryByText} = renderChat({
199
+ mcpServers: [
200
+ {connected: true, name: "files"},
201
+ {connected: false, name: "search"},
202
+ ],
203
+ });
204
+
205
+ assert.isOk(getByText("1/2 MCP"));
206
+ assert.isNull(queryByText("files"));
207
+
208
+ await press(getByLabelText("MCP server status"));
209
+ assert.isOk(getByText("files"));
210
+ assert.isOk(getByText("search"));
211
+
212
+ await press(getByLabelText("MCP server status"));
213
+ assert.isNull(queryByText("files"));
214
+ });
215
+
216
+ it("renders a disconnected MCP indicator when no server is connected", () => {
217
+ const {getByText} = renderChat({mcpServers: [{connected: false, name: "files"}]});
218
+
219
+ assert.isOk(getByText("0/1 MCP"));
220
+ });
221
+
222
+ it("lists the available MCP tools in a modal", async () => {
223
+ const {getByTestId, getByText} = renderChat({
224
+ mcpTools: [{description: "Reads files", name: "readFile"}, {name: "writeFile"}],
225
+ });
226
+
227
+ await press(getByTestId("gpt-tools-button"));
228
+
229
+ assert.isOk(getByText("readFile"));
230
+ assert.isOk(getByText("Reads files"));
231
+ assert.isOk(getByText("writeFile"));
232
+ });
233
+
234
+ it("hides the tools button when there are no tools", () => {
235
+ const {queryByTestId} = renderChat({mcpTools: []});
236
+
237
+ assert.isNull(queryByTestId("gpt-tools-button"));
238
+ });
239
+
240
+ it("omits the mascot when the consumer does not pass one", () => {
241
+ const {queryByTestId} = renderChat({suggestedPrompts: ["Summarize this"]});
242
+
243
+ assert.isNull(queryByTestId("gpt-mascot"));
244
+ });
245
+
246
+ it("renders the consumer mascot on an empty chat", () => {
247
+ const {getByTestId, getByText} = renderChat({
248
+ mascot: <Text testID="consumer-mascot">App fox</Text>,
249
+ });
250
+
251
+ assert.isOk(getByTestId("gpt-mascot"));
252
+ assert.isOk(getByText("App fox"));
253
+ });
254
+
255
+ it("keeps the mascot above suggested prompts on an empty chat", () => {
256
+ const {getByTestId, getByText} = renderChat({
257
+ mascot: <Text>App fox</Text>,
258
+ suggestedPrompts: ["Summarize this"],
259
+ });
260
+
261
+ assert.isOk(getByTestId("gpt-mascot"));
262
+ assert.isOk(getByText("Try asking..."));
263
+ });
264
+
265
+ it("centers the empty state in the chat panel", () => {
266
+ const {getByTestId} = renderChat({
267
+ mascot: <Text>App fox</Text>,
268
+ suggestedPrompts: ["Summarize this"],
269
+ });
270
+
271
+ const emptyState = getByTestId("gpt-empty-state");
272
+
273
+ assert.equal(emptyState.props.style.flexGrow, 1);
274
+ assert.equal(emptyState.props.style.justifyContent, "center");
275
+ assert.equal(emptyState.props.style.alignItems, "center");
276
+ });
277
+
278
+ it("sizes the empty hero to the viewport so short content can center", () => {
279
+ const {getByTestId} = renderChat({
280
+ mascot: <Text>App fox</Text>,
281
+ suggestedPrompts: ["Summarize this"],
282
+ });
283
+
284
+ fireEvent(getByTestId("gpt-viewport"), "layout", {
285
+ nativeEvent: {layout: {height: 480, width: 100, x: 0, y: 0}},
286
+ });
287
+
288
+ assert.equal(getByTestId("gpt-empty-state").props.style.minHeight, 480);
289
+ });
290
+
291
+ it("keeps the empty state inside the scrollable message content", () => {
292
+ const {getByTestId} = renderChat({
293
+ mascot: <Text>App fox</Text>,
294
+ suggestedPrompts: ["Summarize this"],
295
+ });
296
+
297
+ assert.isOk(getByTestId("gpt-messages").findByProps({testID: "gpt-empty-state"}));
298
+ });
299
+
300
+ it("keeps empty-chat streaming feedback in the centered hero", () => {
301
+ const {getByTestId} = renderChat({
302
+ isStreaming: true,
303
+ mascot: <Text>App fox</Text>,
304
+ });
305
+
306
+ assert.isOk(getByTestId("gpt-empty-state").findByProps({testID: "gpt-streaming-indicator"}));
307
+ });
308
+
309
+ it("drops the centered empty state once messages exist", () => {
310
+ const {queryByTestId} = renderChat({
311
+ currentMessages: [{content: "Hi there", role: "user"}],
312
+ mascot: <Text>App fox</Text>,
313
+ suggestedPrompts: ["Summarize this"],
314
+ });
315
+
316
+ assert.isNull(queryByTestId("gpt-empty-state"));
317
+ });
318
+
319
+ it("vertically centers each composer control beside the input", () => {
320
+ const {getByTestId} = renderChat({
321
+ mcpTools: [{name: "readFile"}],
322
+ onAttachFiles: () => {},
323
+ });
324
+
325
+ // Button hard-codes alignSelf, so each control sits in a full-height cell that centers it.
326
+ for (const cell of ["gpt-composer-attach", "gpt-composer-tools", "gpt-composer-send"]) {
327
+ assert.equal(getByTestId(cell).props.style.justifyContent, "center");
328
+ }
329
+ });
330
+
331
+ it("omits the attachment composer cell when attachments are unavailable", () => {
332
+ const {queryByTestId} = renderChat();
333
+
334
+ assert.isNull(queryByTestId("gpt-composer-attach"));
335
+ });
336
+
337
+ it("hides the mascot after messages exist", () => {
338
+ const {queryByTestId} = renderChat({
339
+ currentMessages: [{content: "Hi there", role: "user"}],
340
+ mascot: <Text>App fox</Text>,
341
+ });
342
+
343
+ assert.isNull(queryByTestId("gpt-mascot"));
344
+ });
345
+
346
+ it("renders suggested prompts and submits the tapped prompt", async () => {
347
+ const onSubmit = mock((_prompt: string) => {});
348
+ const {getByLabelText, getByText} = renderChat({
349
+ onSubmit,
350
+ suggestedPrompts: ["Summarize this"],
351
+ });
352
+
353
+ assert.isOk(getByText("Try asking..."));
354
+ await press(getByLabelText("Summarize this"));
355
+
356
+ assert.deepEqual(onSubmit.mock.calls, [["Summarize this"]]);
357
+ });
358
+
359
+ it("ignores suggested prompts while streaming", async () => {
360
+ const onSubmit = mock((_prompt: string) => {});
361
+ const {getByLabelText} = renderChat({
362
+ isStreaming: true,
363
+ onSubmit,
364
+ suggestedPrompts: ["Summarize this"],
365
+ });
366
+
367
+ await press(getByLabelText("Summarize this"));
368
+
369
+ assert.equal(onSubmit.mock.calls.length, 0);
370
+ });
371
+
372
+ it("submits typed input and clears the field", async () => {
373
+ const onSubmit = mock((_prompt: string) => {});
374
+ const {getByTestId} = renderChat({onSubmit});
375
+
376
+ fireEvent.changeText(getByTestId("gpt-input"), " Hello ");
377
+ await press(getByTestId("gpt-submit"));
378
+
379
+ assert.deepEqual(onSubmit.mock.calls, [["Hello"]]);
380
+ assert.equal(getByTestId("gpt-input").props.value, "");
381
+ });
382
+
383
+ it("does not submit blank input", async () => {
384
+ const onSubmit = mock((_prompt: string) => {});
385
+ const {getByTestId} = renderChat({onSubmit});
386
+
387
+ fireEvent.changeText(getByTestId("gpt-input"), " ");
388
+ await press(getByTestId("gpt-submit"));
389
+
390
+ assert.equal(onSubmit.mock.calls.length, 0);
391
+ });
392
+
393
+ it("does not submit while streaming", async () => {
394
+ const onSubmit = mock((_prompt: string) => {});
395
+ const {getByTestId} = renderChat({isStreaming: true, onSubmit});
396
+
397
+ fireEvent.changeText(getByTestId("gpt-input"), "Hello");
398
+ await press(getByTestId("gpt-submit"));
399
+
400
+ assert.equal(onSubmit.mock.calls.length, 0);
401
+ });
402
+
403
+ it("renders user and assistant messages", async () => {
404
+ const messages: GPTChatMessage[] = [
405
+ {content: "Hi there", role: "user"},
406
+ {content: "Hello!", role: "assistant"},
407
+ ];
408
+ const {getByText, toJSON} = renderChat({currentMessages: messages});
409
+
410
+ assert.isOk(getByText("Hi there"));
411
+ // The assistant message renders through the lazily loaded markdown view.
412
+ await waitFor(() => {
413
+ assert.include(JSON.stringify(toJSON()), "Hello!");
414
+ });
415
+ });
416
+
417
+ it("expands tool call details", async () => {
418
+ const messages: GPTChatMessage[] = [
419
+ {
420
+ content: "",
421
+ role: "tool-call",
422
+ toolCall: {args: {path: "README.md"}, toolCallId: "1", toolName: "readFile"},
423
+ },
424
+ ];
425
+ const {getByLabelText, getByText, queryByText} = renderChat({currentMessages: messages});
426
+
427
+ assert.isNull(queryByText(/README.md/));
428
+ await press(getByLabelText("Tool: readFile"));
429
+ assert.isOk(getByText(/README.md/));
430
+ });
431
+
432
+ it("expands string and object tool results", async () => {
433
+ const messages: GPTChatMessage[] = [
434
+ {
435
+ content: "",
436
+ role: "tool-result",
437
+ toolResult: {result: "done", toolCallId: "1", toolName: "readFile"},
438
+ },
439
+ {
440
+ content: "",
441
+ role: "tool-result",
442
+ toolResult: {result: {ok: true}, toolCallId: "2", toolName: "writeFile"},
443
+ },
444
+ ];
445
+ const {getByLabelText, getByText} = renderChat({currentMessages: messages});
446
+
447
+ await press(getByLabelText("Result: readFile"));
448
+ await press(getByLabelText("Result: writeFile"));
449
+
450
+ assert.isOk(getByText("done"));
451
+ assert.isOk(getByText(/"ok": true/));
452
+ });
453
+
454
+ it("renders image and file content parts", () => {
455
+ const messages: GPTChatMessage[] = [
456
+ {
457
+ content: "See attached",
458
+ contentParts: [
459
+ {text: "See attached", type: "text"},
460
+ {type: "image", url: "https://example.com/pic.png"},
461
+ {mimeType: "application/pdf", type: "file", url: "https://example.com/doc.pdf"},
462
+ {filename: "notes.txt", mimeType: "text/plain", type: "file", url: "file:///notes.txt"},
463
+ ],
464
+ role: "user",
465
+ },
466
+ ];
467
+ const {getByText} = renderChat({currentMessages: messages});
468
+
469
+ assert.isOk(getByText("File"));
470
+ assert.isOk(getByText("notes.txt"));
471
+ });
472
+
473
+ it("downloads a file content part on press", async () => {
474
+ const messages: GPTChatMessage[] = [
475
+ {
476
+ content: "",
477
+ contentParts: [
478
+ {filename: "doc.pdf", mimeType: "application/pdf", type: "file", url: "data:abc"},
479
+ ],
480
+ role: "assistant",
481
+ },
482
+ ];
483
+ const clicked: string[] = [];
484
+ const link = {click: () => clicked.push("click"), download: "", href: ""};
485
+ const appended: unknown[] = [];
486
+ const removed: unknown[] = [];
487
+ const domGlobals = globalThis as typeof globalThis & {
488
+ document?: unknown;
489
+ window?: unknown;
490
+ };
491
+ const originalDocument = domGlobals.document;
492
+ const originalWindow = domGlobals.window;
493
+ domGlobals.window = {};
494
+ domGlobals.document = {
495
+ body: {
496
+ appendChild: (node: unknown) => appended.push(node),
497
+ removeChild: (node: unknown) => removed.push(node),
498
+ },
499
+ createElement: () => link,
500
+ };
501
+
502
+ try {
503
+ const {getByLabelText} = renderChat({currentMessages: messages});
504
+ await press(getByLabelText("File: doc.pdf"));
505
+ } finally {
506
+ domGlobals.document = originalDocument;
507
+ domGlobals.window = originalWindow;
508
+ }
509
+
510
+ assert.equal(link.href, "data:abc");
511
+ assert.equal(link.download, "doc.pdf");
512
+ assert.deepEqual(clicked, ["click"]);
513
+ assert.deepEqual(appended, [link]);
514
+ assert.deepEqual(removed, [link]);
515
+ });
516
+
517
+ it("skips the download outside a browser environment", async () => {
518
+ const messages: GPTChatMessage[] = [
519
+ {
520
+ content: "",
521
+ contentParts: [{mimeType: "text/plain", type: "file", url: "https://example.com/a.txt"}],
522
+ role: "assistant",
523
+ },
524
+ ];
525
+ const domGlobals = globalThis as typeof globalThis & {window?: unknown};
526
+ const originalWindow = domGlobals.window;
527
+ domGlobals.window = undefined;
528
+
529
+ try {
530
+ const {getByLabelText} = renderChat({currentMessages: messages});
531
+ await press(getByLabelText("File: File"));
532
+ } finally {
533
+ domGlobals.window = originalWindow;
534
+ }
535
+ });
536
+
537
+ it("rates assistant messages and toggles the rating off", () => {
538
+ const onRateFeedback = mock((_index: number, _rating: "up" | "down" | null) => {});
539
+ const messages: GPTChatMessage[] = [
540
+ {content: "Hello!", rating: "up", role: "assistant"},
541
+ {content: "More", role: "assistant"},
542
+ ];
543
+ const {getByTestId} = renderChat({currentMessages: messages, onRateFeedback});
544
+
545
+ fireEvent.press(getByTestId("gpt-rate-up-0"));
546
+ fireEvent.press(getByTestId("gpt-rate-down-0"));
547
+ fireEvent.press(getByTestId("gpt-rate-down-1"));
548
+
549
+ assert.deepEqual(onRateFeedback.mock.calls, [
550
+ [0, null],
551
+ [0, "down"],
552
+ [1, "down"],
553
+ ]);
554
+ });
555
+
556
+ it("hides rating buttons without a feedback handler", () => {
557
+ const {queryByTestId} = renderChat({
558
+ currentMessages: [{content: "Hello!", role: "assistant"}],
559
+ });
560
+
561
+ assert.isNull(queryByTestId("gpt-rate-up-0"));
562
+ });
563
+
564
+ it("copies an assistant message to the clipboard", async () => {
565
+ setStringAsync.mockClear();
566
+ const {getByTestId} = renderChat({
567
+ currentMessages: [{content: "Copy me", role: "assistant"}],
568
+ });
569
+
570
+ await act(async () => {
571
+ fireEvent.press(getByTestId("gpt-copy-msg-0"));
572
+ });
573
+
574
+ assert.deepEqual(setStringAsync.mock.calls, [["Copy me"]]);
575
+ });
576
+
577
+ it("disables input and the attachment picker while streaming", () => {
578
+ const {getByTestId} = renderChat({isStreaming: true, onAttachFiles: () => {}});
579
+
580
+ assert.isTrue(getByTestId("gpt-input").props.readOnly);
581
+ assert.isTrue(getByTestId("gpt-attach-button").props.disabled);
582
+ });
583
+
584
+ it("keeps the attachment picker enabled when not streaming", () => {
585
+ const {getByTestId} = renderChat({onAttachFiles: () => {}});
586
+
587
+ assert.isNotTrue(getByTestId("gpt-attach-button").props.disabled);
588
+ });
589
+
590
+ it("hides the attachment picker without an attach handler", () => {
591
+ const {queryByTestId} = renderChat();
592
+
593
+ assert.isNull(queryByTestId("gpt-attach-button"));
594
+ });
595
+
596
+ it("shows the scroll to bottom button once scrolled away from the end", async () => {
597
+ const {getByTestId, getByText, queryByText, UNSAFE_getByType} = renderChat({
598
+ currentMessages: [{content: "Hello!", role: "assistant"}],
599
+ });
600
+
601
+ assert.isNull(queryByText("Scroll to bottom"));
602
+
603
+ fireEvent(getByTestId("gpt-viewport"), "layout", {
604
+ nativeEvent: {layout: {height: 200, width: 100, x: 0, y: 0}},
605
+ });
606
+ fireEvent(getByTestId("gpt-messages"), "layout", {
607
+ nativeEvent: {layout: {height: 600, width: 100, x: 0, y: 0}},
608
+ });
609
+ await act(async () => {
610
+ fireEvent.scroll(UNSAFE_getByType(ScrollView), {
611
+ nativeEvent: {contentOffset: {x: 0, y: 100}},
612
+ });
613
+ });
614
+
615
+ assert.isOk(getByText("Scroll to bottom"));
616
+
617
+ await press(getByText("Scroll to bottom"));
618
+
619
+ assert.isNull(queryByText("Scroll to bottom"));
620
+ });
621
+
622
+ it("renders attachments and the attach button", () => {
623
+ const onAttachFiles = mock(() => {});
624
+ const onRemoveAttachment = mock((_index: number) => {});
625
+ const {getByTestId} = renderChat({
626
+ attachments: [{mimeType: "image/png", name: "photo.png", uri: "file:///photo.png"}],
627
+ onAttachFiles,
628
+ onRemoveAttachment,
629
+ });
630
+
631
+ assert.isOk(getByTestId("gpt-attach-button"));
632
+ assert.isOk(getByTestId("attachment-preview"));
633
+ });
634
+
635
+ it("hides the attachment preview without a remove handler", () => {
636
+ const {queryByTestId} = renderChat({
637
+ attachments: [{mimeType: "image/png", name: "photo.png", uri: "file:///photo.png"}],
638
+ });
639
+
640
+ assert.isNull(queryByTestId("attachment-preview"));
641
+ });
642
+
643
+ it("renders nothing for unknown content part types", () => {
644
+ const parts = [
645
+ {type: "audio", url: "https://example.com/a.mp3"},
646
+ ] as unknown as MessageContentPart[];
647
+ const {getByText, queryByText} = renderChat({
648
+ currentMessages: [{content: "Listen", contentParts: parts, role: "user"}],
649
+ });
650
+
651
+ assert.isOk(getByText("Listen"));
652
+ assert.isNull(queryByText("File"));
653
+ });
654
+
655
+ it("forwards picked files to onAttachFiles", async () => {
656
+ const onAttachFiles = mock((_files: SelectedFile[]) => {});
657
+ const {getByTestId, getByText} = renderChat({onAttachFiles});
658
+
659
+ await press(getByTestId("gpt-attach-button"));
660
+ await press(getByText("Document"));
661
+
662
+ await waitFor(() => {
663
+ assert.deepEqual(onAttachFiles.mock.calls, [[[pickedDocument]]]);
664
+ });
665
+ });
666
+
667
+ it("saves a rename only once when blur and enter both fire", async () => {
668
+ const onUpdateTitle = mock((_id: string, _title: string) => {});
669
+ const {getByTestId} = renderChat({onUpdateTitle});
670
+
671
+ await press(getByTestId("gpt-rename-history-h1"));
672
+ fireEvent.changeText(getByTestId("gpt-rename-input-h1"), "Renamed");
673
+ const input = getByTestId("gpt-rename-input-h1");
674
+ await act(async () => {
675
+ input.props.onSubmitEditing();
676
+ input.props.onBlur();
677
+ });
678
+
679
+ assert.deepEqual(onUpdateTitle.mock.calls, [["h1", "Renamed"]]);
680
+ });
681
+
682
+ it("scrolls to the bottom when new messages arrive", () => {
683
+ const {getByText, rerender} = renderChat({
684
+ currentMessages: [{content: "First", role: "assistant"}],
685
+ });
686
+
687
+ rerender(
688
+ <GPTChat
689
+ currentMessages={[
690
+ {content: "First", role: "assistant"},
691
+ {content: "Second", role: "assistant"},
692
+ ]}
693
+ histories={histories}
694
+ onCreateHistory={() => {}}
695
+ onDeleteHistory={() => {}}
696
+ onSelectHistory={() => {}}
697
+ onSubmit={() => {}}
698
+ testID="gpt-chat"
699
+ />
700
+ );
701
+
702
+ assert.isOk(getByText("Second"));
703
+ });
704
+ });
705
+
706
+ describe("GPTChat web keyboard submit", () => {
707
+ const originalOS = Platform.OS;
708
+
709
+ afterEach(() => {
710
+ Platform.OS = originalOS;
711
+ });
712
+
713
+ const renderOnWeb = (): {
714
+ handlers: Map<string, (event: Event) => void>;
715
+ onSubmit: ReturnType<typeof mock<(prompt: string) => void>>;
716
+ result: ReturnType<typeof render>;
717
+ removed: string[];
718
+ } => {
719
+ Platform.OS = "web";
720
+ const handlers = new Map<string, (event: Event) => void>();
721
+ const removed: string[] = [];
722
+ const onSubmit = mock((_prompt: string) => {});
723
+ const node = {
724
+ addEventListener: (type: string, handler: (event: Event) => void): void => {
725
+ handlers.set(type, handler);
726
+ },
727
+ removeEventListener: (type: string): void => {
728
+ removed.push(type);
729
+ },
730
+ scrollToEnd: () => {},
731
+ };
732
+ const result = render(
733
+ <GPTChat
734
+ currentMessages={[]}
735
+ histories={histories}
736
+ onCreateHistory={() => {}}
737
+ onDeleteHistory={() => {}}
738
+ onSelectHistory={() => {}}
739
+ onSubmit={onSubmit}
740
+ testID="gpt-chat"
741
+ />,
742
+ {
743
+ createNodeMock: () => node,
744
+ wrapper: ThemeProvider,
745
+ }
746
+ );
747
+ return {handlers, onSubmit, removed, result};
748
+ };
749
+
750
+ const keyEvent = (init: {
751
+ key: string;
752
+ metaKey?: boolean;
753
+ shiftKey?: boolean;
754
+ }): {
755
+ event: Event;
756
+ prevented: () => boolean;
757
+ } => {
758
+ let prevented = false;
759
+ const event = {
760
+ key: init.key,
761
+ metaKey: init.metaKey ?? false,
762
+ preventDefault: (): void => {
763
+ prevented = true;
764
+ },
765
+ shiftKey: init.shiftKey ?? false,
766
+ } as unknown as Event;
767
+ return {event, prevented: (): boolean => prevented};
768
+ };
769
+
770
+ it("submits on Enter but not on other keys or modified Enter", async () => {
771
+ const {handlers, onSubmit, result} = renderOnWeb();
772
+ const keydown = handlers.get("keydown");
773
+ assert.isFunction(keydown);
774
+
775
+ fireEvent.changeText(result.getByTestId("gpt-input"), "Hello there");
776
+
777
+ const other = keyEvent({key: "a"});
778
+ const shifted = keyEvent({key: "Enter", shiftKey: true});
779
+ const meta = keyEvent({key: "Enter", metaKey: true});
780
+ await act(async () => {
781
+ keydown?.(other.event);
782
+ keydown?.(shifted.event);
783
+ keydown?.(meta.event);
784
+ });
785
+ assert.isFalse(other.prevented());
786
+ assert.isFalse(shifted.prevented());
787
+ assert.isFalse(meta.prevented());
788
+ assert.equal(onSubmit.mock.calls.length, 0);
789
+
790
+ const enter = keyEvent({key: "Enter"});
791
+ await act(async () => {
792
+ keydown?.(enter.event);
793
+ });
794
+ assert.isTrue(enter.prevented());
795
+ assert.deepEqual(onSubmit.mock.calls, [["Hello there"]]);
796
+ });
797
+
798
+ it("removes the keydown listener on unmount", () => {
799
+ const {removed, result} = renderOnWeb();
800
+ result.unmount();
801
+ assert.include(removed, "keydown");
802
+ });
803
+ });