@terreno/ui 57.2.0 → 57.3.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 (201) 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/Box.d.ts +1 -1
  7. package/dist/Box.js +219 -177
  8. package/dist/Box.js.map +1 -1
  9. package/dist/Button.js +101 -34
  10. package/dist/Button.js.map +1 -1
  11. package/dist/Common.d.ts +119 -9
  12. package/dist/Common.js.map +1 -1
  13. package/dist/ConsentFormScreen.js +46 -12
  14. package/dist/ConsentFormScreen.js.map +1 -1
  15. package/dist/ConsentNavigator.d.ts +5 -1
  16. package/dist/ConsentNavigator.js.map +1 -1
  17. package/dist/DataTable.d.ts +2 -2
  18. package/dist/DataTable.js +203 -44
  19. package/dist/DataTable.js.map +1 -1
  20. package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
  21. package/dist/DataTableHeaderInfoMarkdown.js +7 -0
  22. package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
  23. package/dist/EmojiSelector.d.ts +2 -46
  24. package/dist/EmojiSelector.js +46 -56
  25. package/dist/EmojiSelector.js.map +1 -1
  26. package/dist/GPTChat.js +1 -1
  27. package/dist/GPTChat.js.map +1 -1
  28. package/dist/Heading.d.ts +5 -2
  29. package/dist/Heading.js +6 -8
  30. package/dist/Heading.js.map +1 -1
  31. package/dist/Hyperlink.js.map +1 -1
  32. package/dist/Icon.d.ts +1 -2
  33. package/dist/Icon.js +4 -1
  34. package/dist/Icon.js.map +1 -1
  35. package/dist/MarkdownView.d.ts +6 -3
  36. package/dist/MarkdownView.js +45 -43
  37. package/dist/MarkdownView.js.map +1 -1
  38. package/dist/MediaQuery.d.ts +5 -3
  39. package/dist/MediaQuery.js +9 -40
  40. package/dist/MediaQuery.js.map +1 -1
  41. package/dist/OpenAPIContext.js +7 -6
  42. package/dist/OpenAPIContext.js.map +1 -1
  43. package/dist/Page.js +7 -1
  44. package/dist/Page.js.map +1 -1
  45. package/dist/PickerSelect.js +8 -1
  46. package/dist/PickerSelect.js.map +1 -1
  47. package/dist/Popover.d.ts +12 -0
  48. package/dist/Popover.js +37 -0
  49. package/dist/Popover.js.map +1 -0
  50. package/dist/PortalHost.js +10 -1
  51. package/dist/PortalHost.js.map +1 -1
  52. package/dist/ResponsiveBreakpoint.d.ts +65 -0
  53. package/dist/ResponsiveBreakpoint.js +111 -0
  54. package/dist/ResponsiveBreakpoint.js.map +1 -0
  55. package/dist/SplitPage.d.ts +2 -2
  56. package/dist/SplitPage.js +7 -12
  57. package/dist/SplitPage.js.map +1 -1
  58. package/dist/SplitPage.native.d.ts +2 -2
  59. package/dist/SplitPage.native.js +1 -6
  60. package/dist/SplitPage.native.js.map +1 -1
  61. package/dist/TapToEdit.js +12 -10
  62. package/dist/TapToEdit.js.map +1 -1
  63. package/dist/TerrenoFontProvider.d.ts +7 -0
  64. package/dist/TerrenoFontProvider.js +27 -0
  65. package/dist/TerrenoFontProvider.js.map +1 -0
  66. package/dist/TerrenoProvider.js +4 -2
  67. package/dist/TerrenoProvider.js.map +1 -1
  68. package/dist/Text.d.ts +5 -2
  69. package/dist/Text.js +6 -11
  70. package/dist/Text.js.map +1 -1
  71. package/dist/TextFieldNumberActionSheet.js +9 -2
  72. package/dist/TextFieldNumberActionSheet.js.map +1 -1
  73. package/dist/Theme.js +10 -8
  74. package/dist/Theme.js.map +1 -1
  75. package/dist/ToastNotifications.d.ts +4 -2
  76. package/dist/ToastNotifications.js.map +1 -1
  77. package/dist/Tooltip.d.ts +4 -3
  78. package/dist/Tooltip.js +14 -3
  79. package/dist/Tooltip.js.map +1 -1
  80. package/dist/Unifier.d.ts +26 -1
  81. package/dist/Unifier.js.map +1 -1
  82. package/dist/WebAddressAutocomplete.js +6 -1
  83. package/dist/WebAddressAutocomplete.js.map +1 -1
  84. package/dist/emojiCategories.d.ts +46 -0
  85. package/dist/emojiCategories.js +47 -0
  86. package/dist/emojiCategories.js.map +1 -0
  87. package/dist/index.d.ts +13 -13
  88. package/dist/index.js +2 -13
  89. package/dist/index.js.map +1 -1
  90. package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
  91. package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
  92. package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
  93. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +41 -0
  94. package/dist/lazyBoundaries/heavyOptionalExports.js +43 -0
  95. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
  96. package/dist/login/LoginScreen.d.ts +1 -0
  97. package/dist/login/LoginScreen.js +4 -2
  98. package/dist/login/LoginScreen.js.map +1 -1
  99. package/dist/login/loginTypes.d.ts +2 -0
  100. package/package.json +40 -1
  101. package/src/AIRequestExplorer.test.tsx +141 -0
  102. package/src/ActionSheet.tsx +9 -7
  103. package/src/AttachmentPreview.test.tsx +80 -0
  104. package/src/Box.test.tsx +97 -10
  105. package/src/Box.tsx +263 -200
  106. package/src/Button.test.tsx +207 -0
  107. package/src/Button.tsx +146 -48
  108. package/src/Common.ts +124 -25
  109. package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
  110. package/src/ConsentFormScreen.test.tsx +145 -8
  111. package/src/ConsentFormScreen.tsx +74 -25
  112. package/src/ConsentNavigator.tsx +13 -5
  113. package/src/DataTable.tsx +418 -147
  114. package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
  115. package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
  116. package/src/DataTableVirtualizationRegression.test.tsx +266 -0
  117. package/src/DateTimeField.test.tsx +54 -0
  118. package/src/EmojiSelector.test.tsx +33 -42
  119. package/src/EmojiSelector.tsx +60 -57
  120. package/src/FilePickerButton.test.tsx +167 -0
  121. package/src/FilterAccordion.test.tsx +37 -0
  122. package/src/FilterBoolean.test.tsx +96 -0
  123. package/src/FilterSelectMenu.test.tsx +23 -0
  124. package/src/GPTChat.test.tsx +696 -0
  125. package/src/GPTChat.tsx +2 -2
  126. package/src/GPTMemoryModal.test.tsx +67 -0
  127. package/src/Heading.tsx +8 -14
  128. package/src/HeightActionSheet.test.tsx +6 -9
  129. package/src/Hyperlink.tsx +5 -18
  130. package/src/Icon.tsx +6 -2
  131. package/src/MarkdownEditor.test.tsx +134 -0
  132. package/src/MarkdownEditorField.test.tsx +124 -0
  133. package/src/MarkdownView.test.tsx +55 -11
  134. package/src/MarkdownView.tsx +149 -150
  135. package/src/MediaQuery.ts +30 -34
  136. package/src/OpenAPIContext.tsx +36 -29
  137. package/src/OpenAPIRenderRegression.test.tsx +200 -0
  138. package/src/P0RenderRegression.test.tsx +214 -0
  139. package/src/P1RenderRegression.test.tsx +141 -0
  140. package/src/P2ButtonRenderRegression.test.tsx +158 -0
  141. package/src/Page.test.tsx +13 -0
  142. package/src/Page.tsx +25 -5
  143. package/src/PickerSelect.test.tsx +38 -0
  144. package/src/PickerSelect.tsx +7 -0
  145. package/src/Popover.test.tsx +151 -0
  146. package/src/Popover.tsx +211 -0
  147. package/src/PortalHost.tsx +12 -6
  148. package/src/ResponsiveBreakpoint.test.tsx +184 -0
  149. package/src/ResponsiveBreakpoint.tsx +195 -0
  150. package/src/RootImportRegression.test.tsx +62 -0
  151. package/src/SplitPage.native.tsx +5 -9
  152. package/src/SplitPage.tsx +16 -19
  153. package/src/TapToEdit.test.tsx +45 -0
  154. package/src/TapToEdit.tsx +23 -18
  155. package/src/TerrenoFontProvider.test.tsx +38 -0
  156. package/src/TerrenoFontProvider.tsx +50 -0
  157. package/src/TerrenoProvider.tsx +6 -1
  158. package/src/Text.tsx +8 -21
  159. package/src/TextFieldNumberActionSheet.test.tsx +100 -0
  160. package/src/TextFieldNumberActionSheet.tsx +11 -2
  161. package/src/Theme.test.tsx +27 -0
  162. package/src/Theme.tsx +15 -10
  163. package/src/Toast.tsx +1 -1
  164. package/src/ToastNotifications.tsx +4 -4
  165. package/src/Tooltip.test.tsx +64 -0
  166. package/src/Tooltip.tsx +18 -4
  167. package/src/Unifier.ts +26 -3
  168. package/src/WebAddressAutocomplete.tsx +6 -2
  169. package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
  170. package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
  171. package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
  172. package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
  173. package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
  174. package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
  175. package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
  176. package/src/__snapshots__/Field.test.tsx.snap +7 -0
  177. package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
  178. package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
  179. package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
  180. package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
  181. package/src/__snapshots__/Page.test.tsx.snap +13 -1
  182. package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
  183. package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
  184. package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
  185. package/src/benchmarks/importGraph.test.ts +71 -0
  186. package/src/benchmarks/importGraph.ts +136 -0
  187. package/src/benchmarks/importTiming.test.ts +42 -0
  188. package/src/benchmarks/importTiming.ts +86 -0
  189. package/src/bunSetup.ts +174 -32
  190. package/src/emojiCategories.test.ts +23 -0
  191. package/src/emojiCategories.ts +46 -0
  192. package/src/index.tsx +27 -13
  193. package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
  194. package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
  195. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
  196. package/src/lazyBoundaries/heavyOptionalExports.tsx +106 -0
  197. package/src/login/LoginScreen.test.tsx +9 -2
  198. package/src/login/LoginScreen.tsx +6 -2
  199. package/src/login/loginTypes.ts +2 -0
  200. package/src/table/TableDate.test.tsx +35 -1
  201. package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
@@ -0,0 +1,67 @@
1
+ import {describe, it, mock} from "bun:test";
2
+ import {act, fireEvent} from "@testing-library/react-native";
3
+ import {assert} from "chai";
4
+ import React from "react";
5
+
6
+ import {GPTMemoryModal} from "./GPTMemoryModal";
7
+ import {renderWithTheme} from "./test-utils";
8
+
9
+ // Button presses run through an async haptic call, so state updates land in a microtask after
10
+ // the event.
11
+ const press = async (element: Parameters<typeof fireEvent.press>[0]): Promise<void> => {
12
+ await act(async () => {
13
+ fireEvent.press(element);
14
+ });
15
+ };
16
+
17
+ describe("GPTMemoryModal", () => {
18
+ it("renders the title, subtitle, and the current memory", () => {
19
+ const {getByText, getByTestId, getByPlaceholderText} = renderWithTheme(
20
+ <GPTMemoryModal memory="Be concise." onDismiss={() => {}} onSave={() => {}} visible />
21
+ );
22
+
23
+ assert.isOk(getByText("System Memory"));
24
+ assert.isOk(getByText("Customize the system prompt for your AI assistant."));
25
+ assert.isOk(getByPlaceholderText("Enter system instructions..."));
26
+ assert.equal(getByTestId("gpt-memory-textarea").props.value, "Be concise.");
27
+ });
28
+
29
+ it("saves the edited memory and dismisses", async () => {
30
+ const onSave = mock((_memory: string) => {});
31
+ const onDismiss = mock(() => {});
32
+ const {getByTestId, getByText} = renderWithTheme(
33
+ <GPTMemoryModal memory="Old" onDismiss={onDismiss} onSave={onSave} visible />
34
+ );
35
+
36
+ fireEvent.changeText(getByTestId("gpt-memory-textarea"), "New instructions");
37
+ assert.equal(getByTestId("gpt-memory-textarea").props.value, "New instructions");
38
+
39
+ await press(getByText("Save"));
40
+
41
+ assert.equal(onSave.mock.calls.length, 1);
42
+ assert.deepEqual(onSave.mock.calls[0], ["New instructions"]);
43
+ assert.equal(onDismiss.mock.calls.length, 1);
44
+ });
45
+
46
+ it("cancels without saving", async () => {
47
+ const onSave = mock((_memory: string) => {});
48
+ const onDismiss = mock(() => {});
49
+ const {getByTestId, getByText} = renderWithTheme(
50
+ <GPTMemoryModal memory="Old" onDismiss={onDismiss} onSave={onSave} visible />
51
+ );
52
+
53
+ fireEvent.changeText(getByTestId("gpt-memory-textarea"), "Discarded");
54
+ await press(getByText("Cancel"));
55
+
56
+ assert.equal(onSave.mock.calls.length, 0);
57
+ assert.equal(onDismiss.mock.calls.length, 1);
58
+ });
59
+
60
+ it("renders nothing visible when not visible", () => {
61
+ const {queryByText} = renderWithTheme(
62
+ <GPTMemoryModal memory="" onDismiss={() => {}} onSave={() => {}} visible={false} />
63
+ );
64
+
65
+ assert.isNull(queryByText("System Memory"));
66
+ });
67
+ });
package/src/Heading.tsx CHANGED
@@ -1,12 +1,8 @@
1
- import {
2
- TitilliumWeb_600SemiBold,
3
- TitilliumWeb_700Bold,
4
- useFonts,
5
- } from "@expo-google-fonts/titillium-web";
6
- import type React from "react";
1
+ import React from "react";
7
2
  import {Text as NativeText, Platform, type StyleProp, type TextStyle} from "react-native";
8
3
 
9
4
  import type {HeadingProps} from "./Common";
5
+ import {useTerrenoFontsLoaded} from "./TerrenoFontProvider";
10
6
  import {useTheme} from "./Theme";
11
7
 
12
8
  const fontSizeAndWeightWeb = {
@@ -27,7 +23,7 @@ const fontSizeAndWeighMobile = {
27
23
 
28
24
  const fontSizes = Platform.OS === "web" ? fontSizeAndWeightWeb : fontSizeAndWeighMobile;
29
25
 
30
- export const Heading = ({
26
+ const HeadingComponent = ({
31
27
  align,
32
28
  children,
33
29
  color = "primary",
@@ -35,13 +31,7 @@ export const Heading = ({
35
31
  testID,
36
32
  }: HeadingProps): React.ReactElement => {
37
33
  const {theme} = useTheme();
38
-
39
- // TODO: make fonts part of theme.
40
- useFonts({
41
- heading: TitilliumWeb_600SemiBold,
42
- "heading-bold": TitilliumWeb_700Bold,
43
- "heading-semibold": TitilliumWeb_600SemiBold,
44
- });
34
+ useTerrenoFontsLoaded();
45
35
 
46
36
  const style: StyleProp<TextStyle> = {};
47
37
 
@@ -64,3 +54,7 @@ export const Heading = ({
64
54
  </NativeText>
65
55
  );
66
56
  };
57
+
58
+ HeadingComponent.displayName = "Heading";
59
+
60
+ export const Heading = React.memo(HeadingComponent);
@@ -1,9 +1,8 @@
1
1
  import {describe, expect, it, mock} from "bun:test";
2
- import {act, render} from "@testing-library/react-native";
2
+ import {act, fireEvent, render} from "@testing-library/react-native";
3
3
  import React, {createRef} from "react";
4
4
 
5
5
  import type {ActionSheet} from "./ActionSheet";
6
- import {Button} from "./Button";
7
6
  import {HeightActionSheet} from "./HeightActionSheet";
8
7
  import {ThemeProvider} from "./Theme";
9
8
 
@@ -88,18 +87,16 @@ describe("HeightActionSheet", () => {
88
87
  expect(handleChange).toHaveBeenCalled();
89
88
  });
90
89
 
91
- it("calls the Done button onClick handler directly", () => {
90
+ it("handles the Done button press", async () => {
92
91
  const actionSheetRef = createRef<ActionSheet>();
93
- const {UNSAFE_root} = render(
92
+ const {getByText} = render(
94
93
  <ThemeProvider>
95
94
  <HeightActionSheet actionSheetRef={actionSheetRef} onChange={() => {}} value="60" />
96
95
  </ThemeProvider>
97
96
  );
98
- const buttons = UNSAFE_root.findAllByType(Button as never);
99
- const doneBtn = buttons.find((b) => b.props.text === "Done");
100
- expect(doneBtn).toBeTruthy();
101
- act(() => {
102
- doneBtn!.props.onClick();
97
+ await act(async () => {
98
+ fireEvent.press(getByText("Done"));
99
+ await Promise.resolve();
103
100
  });
104
101
  });
105
102
  });
package/src/Hyperlink.tsx CHANGED
@@ -38,22 +38,7 @@ import * as mdurl from "mdurl";
38
38
  import React from "react";
39
39
  import {Linking, Platform, type StyleProp, Text, type TextStyle, View} from "react-native";
40
40
 
41
- import type {HyperlinkProps} from "./Common";
42
-
43
- interface LinkifyMatch {
44
- index: number;
45
- lastIndex: number;
46
- raw: string;
47
- schema: string;
48
- text: string;
49
- url: string;
50
- }
51
-
52
- interface LinkifyItLike {
53
- pretest: (text: string) => boolean;
54
- test: (text: string) => boolean;
55
- match: (text: string) => LinkifyMatch[] | null;
56
- }
41
+ import type {HyperlinkProps, LinkifyItLike, LinkifyMatch} from "./Common";
57
42
 
58
43
  const linkifyLib: LinkifyItLike = require("linkify-it")();
59
44
 
@@ -70,7 +55,7 @@ class HyperlinkComponent extends React.Component<HyperlinkProps> {
70
55
  return typeof (component.props as {children?: unknown}).children !== "string";
71
56
  };
72
57
 
73
- linkify = (component: React.ReactElement<{children: string; style?: unknown}>) => {
58
+ linkify = (component: React.ReactElement<{children: string; style?: StyleProp<TextStyle>}>) => {
74
59
  const linkifyIt = this.props.linkify || linkifyLib;
75
60
 
76
61
  if (!linkifyIt.pretest(component.props.children) || !linkifyIt.test(component.props.children))
@@ -158,7 +143,9 @@ class HyperlinkComponent extends React.Component<HyperlinkProps> {
158
143
  </Text>
159
144
  );
160
145
  if (displayName === "Text" && !this.isTextNested(child as React.ReactElement))
161
- return this.linkify(child as React.ReactElement<{children: string; style?: unknown}>);
146
+ return this.linkify(
147
+ child as React.ReactElement<{children: string; style?: StyleProp<TextStyle>}>
148
+ );
162
149
  return this.parse(child as React.ReactElement);
163
150
  })
164
151
  );
package/src/Icon.tsx CHANGED
@@ -1,11 +1,11 @@
1
1
  import FontAwesome6 from "@expo/vector-icons/FontAwesome6";
2
- import type {FC} from "react";
2
+ import {type FC, memo} from "react";
3
3
 
4
4
  import {type IconProps, iconSizeToNumber} from "./Common";
5
5
  import {useCustomIcon} from "./IconRegistry";
6
6
  import {useTheme} from "./Theme";
7
7
 
8
- export const Icon: FC<IconProps> = ({
8
+ const IconComponent: FC<IconProps> = ({
9
9
  color = "primary",
10
10
  size = "md",
11
11
  iconName,
@@ -39,3 +39,7 @@ export const Icon: FC<IconProps> = ({
39
39
  />
40
40
  );
41
41
  };
42
+
43
+ IconComponent.displayName = "Icon";
44
+
45
+ export const Icon = memo(IconComponent);
@@ -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
+ });
@@ -1,49 +1,72 @@
1
- import {describe, expect, it} from "bun:test";
1
+ import {describe, expect, it, mock} from "bun:test";
2
2
  import assert from "node:assert";
3
+ import {waitFor} from "@testing-library/react-native";
3
4
 
4
5
  import {MarkdownView} from "./MarkdownView";
5
6
  import {renderWithTheme} from "./test-utils";
6
7
 
7
8
  describe("MarkdownView", () => {
8
- it("renders correctly with simple text", () => {
9
+ it("renders correctly with simple text", async () => {
9
10
  const {toJSON} = renderWithTheme(<MarkdownView>Hello world</MarkdownView>);
11
+ await waitFor(() => {
12
+ expect(JSON.stringify(toJSON())).toContain("Hello world");
13
+ });
10
14
  expect(toJSON()).toMatchSnapshot();
11
15
  });
12
16
 
13
- it("renders markdown headings", () => {
17
+ it("renders markdown headings", async () => {
14
18
  const {toJSON} = renderWithTheme(
15
19
  <MarkdownView>{"# Heading 1\n## Heading 2\n### Heading 3"}</MarkdownView>
16
20
  );
21
+ await waitFor(() => {
22
+ expect(JSON.stringify(toJSON())).toContain("Heading 1");
23
+ });
17
24
  expect(toJSON()).toMatchSnapshot();
18
25
  });
19
26
 
20
- it("renders markdown bold and italic", () => {
27
+ it("renders markdown bold and italic", async () => {
21
28
  const {toJSON} = renderWithTheme(<MarkdownView>{"**bold** and *italic* text"}</MarkdownView>);
29
+ await waitFor(() => {
30
+ expect(JSON.stringify(toJSON())).toContain("bold");
31
+ });
22
32
  expect(toJSON()).toMatchSnapshot();
23
33
  });
24
34
 
25
- it("renders markdown lists", () => {
35
+ it("renders markdown lists", async () => {
26
36
  const {toJSON} = renderWithTheme(<MarkdownView>{"- Item 1\n- Item 2\n- Item 3"}</MarkdownView>);
37
+ await waitFor(() => {
38
+ expect(JSON.stringify(toJSON())).toContain("Item 1");
39
+ });
27
40
  expect(toJSON()).toMatchSnapshot();
28
41
  });
29
42
 
30
- it("renders with inverted colors", () => {
43
+ it("renders with inverted colors", async () => {
31
44
  const {toJSON} = renderWithTheme(<MarkdownView inverted>Inverted text colors</MarkdownView>);
45
+ await waitFor(() => {
46
+ expect(JSON.stringify(toJSON())).toContain("Inverted text colors");
47
+ });
32
48
  expect(toJSON()).toMatchSnapshot();
33
49
  });
34
50
 
35
- it("renders numbered lists", () => {
51
+ it("renders numbered lists", async () => {
36
52
  const {toJSON} = renderWithTheme(
37
53
  <MarkdownView>{"1. First\n2. Second\n3. Third"}</MarkdownView>
38
54
  );
55
+ await waitFor(() => {
56
+ expect(JSON.stringify(toJSON())).toContain("First");
57
+ });
39
58
  expect(toJSON()).toMatchSnapshot();
40
59
  });
41
60
 
42
- it("keeps long consent ordered list markers on one line", () => {
61
+ it("keeps long consent ordered list markers on one line", async () => {
43
62
  const longConsentList = Array.from({length: 17}, (_, index) => {
44
63
  return `${index + 1}. This consent item has enough text to wrap on narrow mobile screens.`;
45
64
  }).join("\n");
46
65
  const {toJSON} = renderWithTheme(<MarkdownView>{longConsentList}</MarkdownView>);
66
+ await waitFor(() => {
67
+ const serialized = JSON.stringify(toJSON());
68
+ expect(serialized).toContain("17");
69
+ });
47
70
  const serialized = JSON.stringify(toJSON());
48
71
 
49
72
  assert.ok(serialized.includes('"minWidth":32'));
@@ -52,7 +75,7 @@ describe("MarkdownView", () => {
52
75
  assert.ok(serialized.includes("17"));
53
76
  });
54
77
 
55
- it("uses explicit markdown paragraph line height for wrapped mobile text", () => {
78
+ it("uses explicit markdown paragraph line height for wrapped mobile text", async () => {
56
79
  const {toJSON} = renderWithTheme(
57
80
  <MarkdownView>
58
81
  {
@@ -60,19 +83,40 @@ describe("MarkdownView", () => {
60
83
  }
61
84
  </MarkdownView>
62
85
  );
86
+ await waitFor(() => {
87
+ const serialized = JSON.stringify(toJSON());
88
+ expect(serialized).toContain('"fontSize":14');
89
+ });
63
90
  const serialized = JSON.stringify(toJSON());
64
91
 
65
92
  assert.ok(serialized.includes('"fontSize":14'));
66
93
  assert.ok(serialized.includes('"lineHeight":20'));
67
94
  });
68
95
 
69
- it("renders code blocks", () => {
96
+ it("renders code blocks", async () => {
70
97
  const {toJSON} = renderWithTheme(<MarkdownView>{"```\ncode block\n```"}</MarkdownView>);
98
+ await waitFor(() => {
99
+ expect(JSON.stringify(toJSON())).toContain("code block");
100
+ });
71
101
  expect(toJSON()).toMatchSnapshot();
72
102
  });
73
103
 
74
- it("renders inline code", () => {
104
+ it("renders inline code", async () => {
75
105
  const {toJSON} = renderWithTheme(<MarkdownView>{"Use `inline code` here"}</MarkdownView>);
106
+ await waitFor(() => {
107
+ expect(JSON.stringify(toJSON())).toContain("inline code");
108
+ });
76
109
  expect(toJSON()).toMatchSnapshot();
77
110
  });
111
+
112
+ it("invokes onLoad after markdown content mounts", async () => {
113
+ const onLoad = mock(() => {});
114
+ const {getByText} = renderWithTheme(
115
+ <MarkdownView onLoad={onLoad}>Loaded markdown</MarkdownView>
116
+ );
117
+ await waitFor(() => {
118
+ expect(getByText("Loaded markdown")).toBeTruthy();
119
+ });
120
+ expect(onLoad).toHaveBeenCalled();
121
+ });
78
122
  });