@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,166 @@
1
+ import {describe, expect, it, spyOn} from "bun:test";
2
+ import {act, fireEvent} from "@testing-library/react-native";
3
+ import {Linking} from "react-native";
4
+
5
+ import {LineChart} from "./LineChart";
6
+ import {renderWithTheme} from "./test-utils";
7
+
8
+ const POINTS = [
9
+ {label: "A", value: 0},
10
+ {label: "B", value: 50},
11
+ {label: "C", value: 100},
12
+ ];
13
+
14
+ describe("LineChart", () => {
15
+ it("renders one mark testID per point", () => {
16
+ const {getByTestId, queryByTestId} = renderWithTheme(
17
+ <LineChart data={POINTS} testID="chart" />
18
+ );
19
+
20
+ expect(getByTestId("chart.point.0-clickable")).toBeTruthy();
21
+ expect(getByTestId("chart.point.1-clickable")).toBeTruthy();
22
+ expect(getByTestId("chart.point.2-clickable")).toBeTruthy();
23
+ expect(queryByTestId("chart.point.3-clickable")).toBeNull();
24
+ });
25
+
26
+ it("forwards the chart summary accessibility label to the frame", () => {
27
+ const {getByTestId} = renderWithTheme(
28
+ <LineChart accessibilityLabel="Weekly signups chart" data={POINTS} testID="chart" />
29
+ );
30
+
31
+ expect(getByTestId("chart").props.accessibilityLabel).toBe("Weekly signups chart");
32
+ });
33
+
34
+ it("shows emptyText when data is empty", () => {
35
+ const {getByText, queryByText} = renderWithTheme(
36
+ <LineChart data={[]} emptyText="Nothing yet" />
37
+ );
38
+
39
+ expect(getByText("Nothing yet")).toBeTruthy();
40
+ expect(queryByText("Line chart")).toBeNull();
41
+ });
42
+
43
+ it("shows the default empty copy", () => {
44
+ const {getByText} = renderWithTheme(<LineChart data={[]} />);
45
+
46
+ expect(getByText("No data")).toBeTruthy();
47
+ });
48
+
49
+ it("shows a spinner when loading and hides marks", async () => {
50
+ const {getByTestId, queryByTestId} = renderWithTheme(
51
+ <LineChart data={POINTS} loading testID="chart" />
52
+ );
53
+
54
+ expect(queryByTestId("chart.point.0-clickable")).toBeNull();
55
+
56
+ await act(async () => {
57
+ await new Promise((resolve) => setTimeout(resolve, 350));
58
+ });
59
+
60
+ expect(getByTestId("chart.spinner")).toBeTruthy();
61
+ expect(queryByTestId("chart.point.0-clickable")).toBeNull();
62
+ });
63
+
64
+ it("prefers loading over empty copy", async () => {
65
+ const {queryByText, getByTestId} = renderWithTheme(
66
+ <LineChart data={[]} emptyText="Nothing yet" loading testID="chart" />
67
+ );
68
+
69
+ expect(queryByText("Nothing yet")).toBeNull();
70
+
71
+ await act(async () => {
72
+ await new Promise((resolve) => setTimeout(resolve, 350));
73
+ });
74
+
75
+ expect(getByTestId("chart.spinner")).toBeTruthy();
76
+ expect(queryByText("Nothing yet")).toBeNull();
77
+ });
78
+
79
+ it("shows tooltip copy after pressing a mark", async () => {
80
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
81
+ <LineChart data={POINTS} testID="chart" />
82
+ );
83
+
84
+ expect(queryByTestId("chart.tooltip")).toBeNull();
85
+
86
+ await act(async () => {
87
+ fireEvent.press(getByTestId("chart.point.1-clickable"));
88
+ });
89
+
90
+ expect(getByTestId("chart.tooltip")).toBeTruthy();
91
+ expect(getByText("B: 50")).toBeTruthy();
92
+ });
93
+
94
+ it("updates or clears the active tooltip when data changes", async () => {
95
+ const {getByTestId, getByText, queryByTestId, rerender} = renderWithTheme(
96
+ <LineChart data={POINTS} testID="chart" />
97
+ );
98
+
99
+ await act(async () => {
100
+ fireEvent.press(getByTestId("chart.point.1-clickable"));
101
+ });
102
+ rerender(
103
+ <LineChart
104
+ data={[
105
+ {label: "A", value: 0},
106
+ {label: "B", value: 75},
107
+ ]}
108
+ testID="chart"
109
+ />
110
+ );
111
+ expect(getByText("B: 75")).toBeTruthy();
112
+
113
+ rerender(<LineChart data={[{label: "A", value: 0}]} testID="chart" />);
114
+ expect(queryByTestId("chart.tooltip")).toBeNull();
115
+ });
116
+
117
+ it("renders the legend label", () => {
118
+ const {getByText} = renderWithTheme(<LineChart data={POINTS} legendLabel="Sales" />);
119
+
120
+ expect(getByText("Sales")).toBeTruthy();
121
+ });
122
+
123
+ it("resizes the plot to a measured container narrower than the default width", async () => {
124
+ const {getByTestId} = renderWithTheme(<LineChart data={POINTS} testID="chart" />);
125
+
126
+ await act(async () => {
127
+ fireEvent(getByTestId("chart.plot"), "layout", {
128
+ nativeEvent: {layout: {height: 200, width: 120}},
129
+ });
130
+ });
131
+
132
+ const markStyle = getByTestId("chart.point.2-clickable").props.style;
133
+ const styles = Array.isArray(markStyle) ? markStyle : [markStyle];
134
+ const positioned = styles.find(
135
+ (entry: {left?: number} | undefined) => typeof entry?.left === "number"
136
+ ) as {left: number};
137
+
138
+ expect(positioned.left).toBeLessThan(120);
139
+ });
140
+
141
+ it("keeps x-axis labels absolutely positioned so a long label cannot widen the chart", () => {
142
+ const {getByTestId} = renderWithTheme(
143
+ <LineChart data={[{label: "A very long axis label", value: 10}]} testID="chart" />
144
+ );
145
+ const slotStyle = getByTestId("chart.xtick.0").props.style;
146
+ const styles = Array.isArray(slotStyle) ? slotStyle : [slotStyle];
147
+
148
+ expect(styles).toEqual(
149
+ expect.arrayContaining([expect.objectContaining({position: "absolute"})])
150
+ );
151
+ });
152
+
153
+ it("does not open URLs from x-axis labels", async () => {
154
+ const openURLSpy = spyOn(Linking, "openURL").mockImplementation(() => Promise.resolve(true));
155
+ const {getByText} = renderWithTheme(
156
+ <LineChart data={[{label: "https://evil.example", value: 10}]} />
157
+ );
158
+
159
+ await act(async () => {
160
+ fireEvent.press(getByText("https://evil.example"));
161
+ });
162
+
163
+ expect(openURLSpy).not.toHaveBeenCalled();
164
+ openURLSpy.mockRestore();
165
+ });
166
+ });
@@ -0,0 +1,190 @@
1
+ import type {FC} from "react";
2
+ import {useCallback, useState} from "react";
3
+ import {Circle, Path, Svg, Line as SvgLine} from "react-native-svg";
4
+
5
+ import {Box} from "./Box";
6
+ import type {LayoutChangeEvent, LineChartProps} from "./Common";
7
+ import {ChartFrame} from "./charts/ChartFrame";
8
+ import {
9
+ CHART_X_AXIS_HEIGHT,
10
+ getChartAxisWidth,
11
+ getChartPlot,
12
+ getPlotHeight,
13
+ getXTickStyle,
14
+ getYTickStyle,
15
+ } from "./charts/layout";
16
+ import {getLinePath} from "./charts/paths";
17
+ import {createCartesianScales, getYTickValues} from "./charts/scales";
18
+ import {getChartPaint} from "./charts/theme";
19
+ import type {ChartPoint} from "./charts/types/chartTypes";
20
+ import {Text} from "./Text";
21
+ import {useTheme} from "./Theme";
22
+ import {resolveTestID} from "./testing/resolveTestId";
23
+
24
+ const DEFAULT_HEIGHT = 200;
25
+ const DEFAULT_WIDTH = 300;
26
+ const MARK_HIT_SIZE = 24;
27
+
28
+ const formatChartTooltip = ({
29
+ formatValue,
30
+ point,
31
+ }: {
32
+ formatValue: (value: number) => string;
33
+ point: ChartPoint;
34
+ }): string => {
35
+ return `${point.label}: ${formatValue(point.value)}`;
36
+ };
37
+
38
+ export const LineChart: FC<LineChartProps> = ({
39
+ accessibilityLabel,
40
+ data,
41
+ emptyText = "No data",
42
+ formatValue = String,
43
+ height = DEFAULT_HEIGHT,
44
+ legendLabel,
45
+ loading = false,
46
+ testID,
47
+ }) => {
48
+ const {theme} = useTheme();
49
+ const paint = getChartPaint(theme);
50
+ const [chartWidth, setChartWidth] = useState(DEFAULT_WIDTH);
51
+ const [activePointIndex, setActivePointIndex] = useState<number | undefined>(undefined);
52
+
53
+ const handleLayout = useCallback((event: LayoutChangeEvent): void => {
54
+ const nextWidth = event.nativeEvent.layout.width;
55
+ if (nextWidth > 0) {
56
+ setChartWidth(nextWidth);
57
+ }
58
+ }, []);
59
+
60
+ const handleMarkPress = useCallback((pointIndex: number): void => {
61
+ setActivePointIndex(pointIndex);
62
+ }, []);
63
+
64
+ const axisWidth = getChartAxisWidth(chartWidth);
65
+ const plotHeight = getPlotHeight({hasLegend: Boolean(legendLabel), height});
66
+ const plot = getChartPlot({chartWidth, height: plotHeight});
67
+ const plotWidth = chartWidth - axisWidth;
68
+ const scales = createCartesianScales({plot, points: data});
69
+ const linePath = getLinePath({points: data, scales});
70
+ const yTicks = getYTickValues(data);
71
+ const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
72
+ const tooltipText = activePoint
73
+ ? formatChartTooltip({formatValue, point: activePoint})
74
+ : undefined;
75
+ const summaryLabel =
76
+ accessibilityLabel ?? (legendLabel ? `${legendLabel} line chart` : "Line chart");
77
+
78
+ return (
79
+ <ChartFrame
80
+ accessibilityLabel={summaryLabel}
81
+ emptyText={emptyText}
82
+ isEmpty={data.length === 0}
83
+ legendLabel={legendLabel}
84
+ loading={loading}
85
+ testID={testID}
86
+ tooltipText={tooltipText}
87
+ >
88
+ <Box minWidth={0} onLayout={handleLayout} testID={resolveTestID(testID, "plot")} width="100%">
89
+ <Box direction="row" height={plotHeight}>
90
+ <Box height={plotHeight} position="relative" width={axisWidth}>
91
+ {yTicks.map((tick) => (
92
+ <Box
93
+ dangerouslySetInlineStyle={{__style: getYTickStyle({axisWidth, y: scales.y(tick)})}}
94
+ key={`ytick-${tick}`}
95
+ >
96
+ <Text align="right" color="secondaryDark" size="sm" skipLinking truncate>
97
+ {formatValue(tick)}
98
+ </Text>
99
+ </Box>
100
+ ))}
101
+ </Box>
102
+ <Box flex="grow" height={plotHeight} minWidth={0} overflow="hidden" position="relative">
103
+ <Svg height={plotHeight} width={plotWidth}>
104
+ {yTicks.map((tick) => {
105
+ const y = scales.y(tick);
106
+ return (
107
+ <SvgLine
108
+ key={`grid-${tick}`}
109
+ stroke={paint.grid}
110
+ strokeWidth={1}
111
+ x1={plot.left}
112
+ x2={plot.left + plot.width}
113
+ y1={y}
114
+ y2={y}
115
+ />
116
+ );
117
+ })}
118
+ {linePath ? (
119
+ <Path d={linePath} fill="none" stroke={paint.series} strokeWidth={2} />
120
+ ) : null}
121
+ {data.map((point) => (
122
+ <Circle
123
+ cx={scales.xCenter(point.label)}
124
+ cy={scales.y(point.value)}
125
+ fill={paint.series}
126
+ key={`dot-${point.label}`}
127
+ r={4}
128
+ />
129
+ ))}
130
+ </Svg>
131
+ {data.map((point, index) => {
132
+ const onPress = (): void => {
133
+ handleMarkPress(index);
134
+ };
135
+ return (
136
+ <Box
137
+ accessibilityHint={`Show value for ${point.label}`}
138
+ accessibilityLabel={`${point.label}: ${formatValue(point.value)}`}
139
+ dangerouslySetInlineStyle={{
140
+ __style: {
141
+ height: MARK_HIT_SIZE,
142
+ left: scales.xCenter(point.label) - MARK_HIT_SIZE / 2,
143
+ position: "absolute",
144
+ top: scales.y(point.value) - MARK_HIT_SIZE / 2,
145
+ width: MARK_HIT_SIZE,
146
+ },
147
+ }}
148
+ key={`mark-${point.label}`}
149
+ onClick={onPress}
150
+ onHoverStart={onPress}
151
+ testID={resolveTestID(testID, `point.${index}`)}
152
+ />
153
+ );
154
+ })}
155
+ </Box>
156
+ </Box>
157
+ <Box direction="row">
158
+ <Box width={axisWidth} />
159
+ <Box
160
+ flex="grow"
161
+ height={CHART_X_AXIS_HEIGHT}
162
+ minWidth={0}
163
+ overflow="hidden"
164
+ position="relative"
165
+ >
166
+ {data.map((point, index) => (
167
+ <Box
168
+ dangerouslySetInlineStyle={{
169
+ __style: getXTickStyle({
170
+ bandwidth: scales.bandwidth,
171
+ xCenter: scales.xCenter(point.label),
172
+ }),
173
+ }}
174
+ key={`xtick-${point.label}`}
175
+ testID={resolveTestID(testID, `xtick.${index}`)}
176
+ >
177
+ <Text align="center" color="secondaryDark" size="sm" skipLinking truncate>
178
+ {point.label}
179
+ </Text>
180
+ </Box>
181
+ ))}
182
+ </Box>
183
+ </Box>
184
+ </Box>
185
+ </ChartFrame>
186
+ );
187
+ };
188
+
189
+ export type {LineChartProps} from "./Common";
190
+ export type {ChartPoint} from "./charts/types/chartTypes";
@@ -0,0 +1,134 @@
1
+ import {describe, expect, it} from "bun:test";
2
+ import {fireEvent} from "@testing-library/react-native";
3
+ import type {ScaledSize} from "react-native";
4
+ import {useWindowDimensions} from "react-native";
5
+
6
+ import {MarkdownEditor} from "./MarkdownEditor";
7
+ import {renderWithTheme} from "./test-utils";
8
+
9
+ type WindowDimensionsImpl = () => ScaledSize;
10
+ type MockableUseWindowDimensions = WindowDimensionsImpl & {
11
+ mockImplementation?: (impl: WindowDimensionsImpl) => void;
12
+ };
13
+
14
+ const getScaledSize =
15
+ (width: number): WindowDimensionsImpl =>
16
+ (): ScaledSize => ({fontScale: 1, height: 1000, scale: 2, width});
17
+
18
+ const setWindowWidth = (width: number): (() => void) => {
19
+ const useWindowDimensionsMock = useWindowDimensions as MockableUseWindowDimensions;
20
+ if (typeof useWindowDimensionsMock.mockImplementation !== "function") {
21
+ return (): void => {};
22
+ }
23
+ useWindowDimensionsMock.mockImplementation(getScaledSize(width));
24
+ return (): void => {
25
+ useWindowDimensionsMock.mockImplementation?.(getScaledSize(375));
26
+ };
27
+ };
28
+
29
+ describe("MarkdownEditor", () => {
30
+ it("renders the editor and preview panes", () => {
31
+ const {getByTestId, getByText} = renderWithTheme(
32
+ <MarkdownEditor onChange={(): void => {}} testID="editor" value="# Hello" />
33
+ );
34
+
35
+ expect(getByTestId("editor")).toBeTruthy();
36
+ expect(getByTestId("editor-input")).toBeTruthy();
37
+ expect(getByTestId("editor-preview")).toBeTruthy();
38
+ expect(getByText("Edit")).toBeTruthy();
39
+ expect(getByText("Preview")).toBeTruthy();
40
+ });
41
+
42
+ it("renders the title only when provided", () => {
43
+ const {getByText, queryByText, rerender} = renderWithTheme(
44
+ <MarkdownEditor onChange={(): void => {}} title="Notes" value="" />
45
+ );
46
+ expect(getByText("Notes")).toBeTruthy();
47
+
48
+ rerender(<MarkdownEditor onChange={(): void => {}} value="" />);
49
+ expect(queryByText("Notes")).toBeNull();
50
+ });
51
+
52
+ it("omits the pane test IDs when no testID is given", () => {
53
+ const {queryByTestId} = renderWithTheme(
54
+ <MarkdownEditor onChange={(): void => {}} value="content" />
55
+ );
56
+
57
+ expect(queryByTestId("editor-input")).toBeNull();
58
+ expect(queryByTestId("editor-preview")).toBeNull();
59
+ });
60
+
61
+ it("calls onChange when the editor text changes", () => {
62
+ const changes: string[] = [];
63
+ const {getByTestId} = renderWithTheme(
64
+ <MarkdownEditor
65
+ onChange={(next): void => {
66
+ changes.push(next);
67
+ }}
68
+ placeholder="Write markdown"
69
+ testID="editor"
70
+ value=""
71
+ />
72
+ );
73
+
74
+ fireEvent.changeText(getByTestId("editor-input"), "updated");
75
+ expect(changes).toEqual(["updated"]);
76
+ });
77
+
78
+ it("does not call onChange while disabled", () => {
79
+ const changes: string[] = [];
80
+ const {getByTestId} = renderWithTheme(
81
+ <MarkdownEditor
82
+ disabled
83
+ onChange={(next): void => {
84
+ changes.push(next);
85
+ }}
86
+ testID="editor"
87
+ value="locked"
88
+ />
89
+ );
90
+
91
+ expect(getByTestId("editor-input").props.readOnly).toBe(true);
92
+ expect(changes).toEqual([]);
93
+ });
94
+
95
+ it("stacks the panes on narrow screens and splits them on wide screens", () => {
96
+ const restoreNarrow = setWindowWidth(375);
97
+ const narrow = renderWithTheme(
98
+ <MarkdownEditor onChange={(): void => {}} testID="editor" value="narrow" />
99
+ );
100
+ expect(narrow.getByTestId("editor")).toBeTruthy();
101
+ restoreNarrow();
102
+
103
+ const restoreWide = setWindowWidth(1024);
104
+ const wide = renderWithTheme(
105
+ <MarkdownEditor onChange={(): void => {}} testID="editor" value="wide" />
106
+ );
107
+ expect(wide.getByTestId("editor")).toBeTruthy();
108
+ restoreWide();
109
+ });
110
+
111
+ it("clamps the editor row count for small max heights", () => {
112
+ const {getByTestId} = renderWithTheme(
113
+ <MarkdownEditor maxHeight={60} onChange={(): void => {}} testID="editor" value="short" />
114
+ );
115
+
116
+ expect(getByTestId("editor-input").props.numberOfLines).toBe(3);
117
+ });
118
+
119
+ it("scales the editor row count with the max height", () => {
120
+ const {getByTestId} = renderWithTheme(
121
+ <MarkdownEditor maxHeight={820} onChange={(): void => {}} testID="editor" value="tall" />
122
+ );
123
+
124
+ expect(getByTestId("editor-input").props.numberOfLines).toBe(20);
125
+ });
126
+
127
+ it("renders a blank preview for empty content", () => {
128
+ const {getByTestId} = renderWithTheme(
129
+ <MarkdownEditor onChange={(): void => {}} testID="editor" value="" />
130
+ );
131
+
132
+ expect(getByTestId("editor-preview")).toBeTruthy();
133
+ });
134
+ });
@@ -0,0 +1,124 @@
1
+ import {describe, expect, it, mock} from "bun:test";
2
+ import {fireEvent} from "@testing-library/react-native";
3
+ import {Pressable} from "react-native";
4
+
5
+ import {MarkdownEditorField} from "./MarkdownEditorField";
6
+ import {renderWithTheme} from "./test-utils";
7
+
8
+ // Minimal shape of a test instance returned by UNSAFE_getAllByType that we rely on here.
9
+ interface ToolbarPressableInstance {
10
+ props: {
11
+ style: (state: {pressed: boolean}) => {backgroundColor: string};
12
+ };
13
+ }
14
+
15
+ const TOOLBAR_CASES: {label: string; empty: string; existing: string}[] = [
16
+ {empty: "**text**", existing: "Draft**text**", label: "B"},
17
+ {empty: "_text_", existing: "Draft_text_", label: "I"},
18
+ {empty: "~~text~~", existing: "Draft~~text~~", label: "~"},
19
+ {empty: "`code`", existing: "Draft`code`", label: "<>"},
20
+ {empty: "# text", existing: "Draft\n# text", label: "H1"},
21
+ {empty: "## text", existing: "Draft\n## text", label: "H2"},
22
+ {empty: "- item", existing: "Draft\n- item", label: "•"},
23
+ {empty: "> text", existing: "Draft\n> text", label: ">"},
24
+ {empty: "[text](url)", existing: "Draft[text](url)", label: "🔗"},
25
+ ];
26
+
27
+ describe("MarkdownEditorField", () => {
28
+ it("renders the title, input and preview placeholder", () => {
29
+ const {getByTestId, getByText} = renderWithTheme(
30
+ <MarkdownEditorField onChange={() => {}} testID="editor" title="Consent body" />
31
+ );
32
+
33
+ expect(getByText("Consent body")).toBeTruthy();
34
+ expect(getByTestId("editor-input").props.placeholder).toBe("Enter markdown...");
35
+ expect(getByText("Preview")).toBeTruthy();
36
+ });
37
+
38
+ it("renders the markdown preview instead of the placeholder when a value is set", () => {
39
+ const {queryByText} = renderWithTheme(
40
+ <MarkdownEditorField onChange={() => {}} value="# Heading" />
41
+ );
42
+
43
+ expect(queryByText("Preview")).toBeNull();
44
+ });
45
+
46
+ it("uses a custom placeholder and omits input testID when no testID is given", () => {
47
+ const {getByPlaceholderText} = renderWithTheme(
48
+ <MarkdownEditorField onChange={() => {}} placeholder="Write notes" />
49
+ );
50
+
51
+ expect(getByPlaceholderText("Write notes").props.testID).toBeUndefined();
52
+ });
53
+
54
+ it("reports typed text through onChange", () => {
55
+ const onChange = mock((_text: string) => {});
56
+ const {getByTestId} = renderWithTheme(
57
+ <MarkdownEditorField onChange={onChange} testID="editor" />
58
+ );
59
+
60
+ fireEvent.changeText(getByTestId("editor-input"), "Hello");
61
+
62
+ expect(onChange).toHaveBeenCalledWith("Hello");
63
+ });
64
+
65
+ it("renders error and helper text", () => {
66
+ const {getByText} = renderWithTheme(
67
+ <MarkdownEditorField
68
+ errorText="Body is required"
69
+ helperText="Markdown is supported"
70
+ onChange={() => {}}
71
+ />
72
+ );
73
+
74
+ expect(getByText("Body is required")).toBeTruthy();
75
+ expect(getByText("Markdown is supported")).toBeTruthy();
76
+ });
77
+
78
+ it("disables the input and hides the toolbar when disabled", () => {
79
+ const {getByTestId, queryByText} = renderWithTheme(
80
+ <MarkdownEditorField disabled onChange={() => {}} testID="editor" />
81
+ );
82
+
83
+ expect(getByTestId("editor-input").props.editable).toBe(false);
84
+ expect(queryByText("B")).toBeNull();
85
+ });
86
+
87
+ it("applies a custom max height to the panes", () => {
88
+ const {getByTestId} = renderWithTheme(
89
+ <MarkdownEditorField maxHeight={320} onChange={() => {}} testID="editor" />
90
+ );
91
+
92
+ expect(getByTestId("editor-input").props.style).toMatchObject({minHeight: 166});
93
+ });
94
+
95
+ it("highlights a toolbar button while it is pressed", () => {
96
+ const {UNSAFE_getAllByType} = renderWithTheme(<MarkdownEditorField onChange={() => {}} />);
97
+ const [toolbarButton] = UNSAFE_getAllByType(Pressable) as unknown as ToolbarPressableInstance[];
98
+
99
+ expect(toolbarButton?.props.style({pressed: false}).backgroundColor).toBe("transparent");
100
+ expect(toolbarButton?.props.style({pressed: true}).backgroundColor).not.toBe("transparent");
101
+ });
102
+
103
+ for (const {label, empty, existing} of TOOLBAR_CASES) {
104
+ it(`inserts markdown for the ${label} toolbar button`, () => {
105
+ const onChange = mock((_text: string) => {});
106
+ const {getByText} = renderWithTheme(<MarkdownEditorField onChange={onChange} />);
107
+
108
+ fireEvent.press(getByText(label));
109
+
110
+ expect(onChange).toHaveBeenCalledWith(empty);
111
+ });
112
+
113
+ it(`appends markdown for the ${label} toolbar button when a value exists`, () => {
114
+ const onChange = mock((_text: string) => {});
115
+ const {getByText} = renderWithTheme(
116
+ <MarkdownEditorField onChange={onChange} value="Draft" />
117
+ );
118
+
119
+ fireEvent.press(getByText(label));
120
+
121
+ expect(onChange).toHaveBeenCalledWith(existing);
122
+ });
123
+ }
124
+ });
@@ -0,0 +1,34 @@
1
+ import {describe, expect, it, mock} from "bun:test";
2
+ import {Platform} from "react-native";
3
+
4
+ import {MarkdownEmbed} from "./MarkdownEmbed";
5
+ import {renderWithTheme} from "./test-utils";
6
+
7
+ mock.module("react-native-webview", () => ({
8
+ default: () => null,
9
+ }));
10
+
11
+ describe("MarkdownEmbed", () => {
12
+ const originalOS = Platform.OS;
13
+
14
+ it("returns null for non-embeddable URLs", () => {
15
+ const result = renderWithTheme(<MarkdownEmbed url="https://example.com/docs" />);
16
+ expect(result.toJSON()).toBeNull();
17
+ });
18
+
19
+ it("renders the web iframe on web", () => {
20
+ Platform.OS = "web";
21
+ const result = renderWithTheme(
22
+ <MarkdownEmbed url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" />
23
+ );
24
+ expect(result.getByTestId("markdown-embed-web")).toBeTruthy();
25
+ Platform.OS = originalOS;
26
+ });
27
+
28
+ it("renders the native webview on ios", () => {
29
+ Platform.OS = "ios";
30
+ const result = renderWithTheme(<MarkdownEmbed url="https://www.loom.com/share/abc123def456" />);
31
+ expect(result.getByTestId("markdown-embed-native")).toBeTruthy();
32
+ Platform.OS = originalOS;
33
+ });
34
+ });
@@ -0,0 +1,43 @@
1
+ import React, {useMemo} from "react";
2
+ import {Platform} from "react-native";
3
+ import WebView from "react-native-webview";
4
+
5
+ import {Box} from "./Box";
6
+ import {toMediaEmbedUrl} from "./markdownEmbeds";
7
+
8
+ interface MarkdownEmbedProps {
9
+ url: string;
10
+ }
11
+
12
+ export const MarkdownEmbed: React.FC<MarkdownEmbedProps> = ({url}) => {
13
+ const embedUrl = useMemo(() => toMediaEmbedUrl(url), [url]);
14
+ if (!embedUrl) {
15
+ return null;
16
+ }
17
+
18
+ if (Platform.OS === "web") {
19
+ return (
20
+ <Box margin={3} testID="markdown-embed-web" width="100%">
21
+ <iframe
22
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
23
+ allowFullScreen
24
+ src={embedUrl}
25
+ style={{aspectRatio: "16 / 9", border: 0, borderRadius: 8, width: "100%"}}
26
+ title="Embedded media"
27
+ />
28
+ </Box>
29
+ );
30
+ }
31
+
32
+ return (
33
+ <Box height={220} margin={3} testID="markdown-embed-native" width="100%">
34
+ <WebView
35
+ allowsFullscreenVideo
36
+ javaScriptEnabled
37
+ mediaPlaybackRequiresUserAction={false}
38
+ source={{uri: embedUrl}}
39
+ style={{borderRadius: 8, flex: 1}}
40
+ />
41
+ </Box>
42
+ );
43
+ };