@terreno/ui 57.20.0 → 58.0.0-beta.1
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.
- package/.ai/guidelines/core.md +1 -1
- package/CHANGELOG.md +93 -0
- package/dist/ActionSheet.d.ts +9 -9
- package/dist/ActionSheet.d.ts.map +1 -1
- package/dist/ActionSheet.js +11 -4
- package/dist/ActionSheet.js.map +1 -1
- package/dist/AnnouncementNavigator.d.ts +7 -1
- package/dist/AnnouncementNavigator.d.ts.map +1 -1
- package/dist/AnnouncementNavigator.js +15 -16
- package/dist/AnnouncementNavigator.js.map +1 -1
- package/dist/Avatar.d.ts.map +1 -1
- package/dist/Avatar.js +1 -1
- package/dist/Avatar.js.map +1 -1
- package/dist/Box.d.ts.map +1 -1
- package/dist/Box.js +3 -1
- package/dist/Box.js.map +1 -1
- package/dist/Common.d.ts +71 -39
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.d.ts.map +1 -1
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/ConsentNavigator.d.ts +5 -3
- package/dist/ConsentNavigator.d.ts.map +1 -1
- package/dist/ConsentNavigator.js +4 -4
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/CustomSelectField.js.map +1 -1
- package/dist/DataTable.d.ts.map +1 -1
- package/dist/DataTable.js +37 -12
- package/dist/DataTable.js.map +1 -1
- package/dist/DateTimeField.js +6 -6
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DropdownPanel.d.ts +0 -5
- package/dist/DropdownPanel.d.ts.map +1 -1
- package/dist/DropdownPanel.js +0 -5
- package/dist/DropdownPanel.js.map +1 -1
- package/dist/FilterAccordion.d.ts.map +1 -1
- package/dist/FilterAccordion.js.map +1 -1
- package/dist/FilterBoolean.d.ts.map +1 -1
- package/dist/FilterBoolean.js.map +1 -1
- package/dist/FilterSelectMenu.js +1 -1
- package/dist/FilterSelectMenu.js.map +1 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts.map +1 -1
- package/dist/Heading.js +6 -12
- package/dist/Heading.js.map +1 -1
- package/dist/HeightField.d.ts.map +1 -1
- package/dist/HeightField.js +9 -9
- package/dist/HeightField.js.map +1 -1
- package/dist/Hyperlink.d.ts.map +1 -1
- package/dist/Hyperlink.js +6 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Image.d.ts +1 -1
- package/dist/MarkdownEditorField.d.ts.map +1 -1
- package/dist/MarkdownEditorField.js +1 -1
- package/dist/MarkdownEditorField.js.map +1 -1
- package/dist/OfflineBanner.d.ts +3 -2
- package/dist/OfflineBanner.d.ts.map +1 -1
- package/dist/OfflineBanner.js +3 -2
- package/dist/OfflineBanner.js.map +1 -1
- package/dist/OtpField.d.ts.map +1 -1
- package/dist/OtpField.js +4 -4
- package/dist/OtpField.js.map +1 -1
- package/dist/PickerSelect.d.ts +4 -4
- package/dist/PickerSelect.d.ts.map +1 -1
- package/dist/PickerSelect.js +9 -9
- package/dist/PickerSelect.js.map +1 -1
- package/dist/ProvisionalConsentSigner.d.ts +3 -2
- package/dist/ProvisionalConsentSigner.d.ts.map +1 -1
- package/dist/ProvisionalConsentSigner.js +2 -2
- package/dist/ProvisionalConsentSigner.js.map +1 -1
- package/dist/SidebarNavigation.js +2 -2
- package/dist/SidebarNavigation.js.map +1 -1
- package/dist/SidebarNavigation.native.js +2 -2
- package/dist/SidebarNavigation.native.js.map +1 -1
- package/dist/Skeleton.js.map +1 -1
- package/dist/TapToEdit.d.ts +1 -1
- package/dist/TapToEdit.d.ts.map +1 -1
- package/dist/TapToEdit.js.map +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +27 -50
- package/dist/Text.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +4 -4
- package/dist/TextField.js.map +1 -1
- package/dist/Theme.d.ts.map +1 -1
- package/dist/Theme.js +16 -0
- package/dist/Theme.js.map +1 -1
- package/dist/ThumbsUpDownFeedback.d.ts.map +1 -1
- package/dist/ThumbsUpDownFeedback.js.map +1 -1
- package/dist/ToastNotifications.d.ts.map +1 -1
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +1 -1
- package/dist/WebAddressAutocomplete.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +3 -3
- package/dist/WebDropdownMenu.d.ts.map +1 -1
- package/dist/WebDropdownMenu.js +1 -1
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/announcementPlatform.d.ts +5 -0
- package/dist/announcementPlatform.d.ts.map +1 -1
- package/dist/announcementPlatform.js +9 -0
- package/dist/announcementPlatform.js.map +1 -1
- package/dist/asks/AskCard.d.ts +2 -2
- package/dist/asks/AskCard.d.ts.map +1 -1
- package/dist/dataTableColumnWidths.d.ts +76 -0
- package/dist/dataTableColumnWidths.d.ts.map +1 -0
- package/dist/dataTableColumnWidths.js +181 -0
- package/dist/dataTableColumnWidths.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/requestClient.d.ts +71 -0
- package/dist/requestClient.d.ts.map +1 -0
- package/dist/requestClient.js +139 -0
- package/dist/requestClient.js.map +1 -0
- package/dist/security/PasswordCard.d.ts.map +1 -1
- package/dist/security/PasswordCard.js.map +1 -1
- package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -1
- package/dist/security/TwoFactorSettingsCard.js +1 -1
- package/dist/security/TwoFactorSettingsCard.js.map +1 -1
- package/dist/signUp/SignUpScreen.js.map +1 -1
- package/dist/table/Table.d.ts.map +1 -1
- package/dist/table/Table.js.map +1 -1
- package/dist/table/TableTitle.d.ts.map +1 -1
- package/dist/table/TableTitle.js +2 -1
- package/dist/table/TableTitle.js.map +1 -1
- package/dist/textFontSizes.d.ts +12 -0
- package/dist/textFontSizes.d.ts.map +1 -0
- package/dist/textFontSizes.js +21 -0
- package/dist/textFontSizes.js.map +1 -0
- package/dist/useAcknowledgeAnnouncement.d.ts +8 -63
- package/dist/useAcknowledgeAnnouncement.d.ts.map +1 -1
- package/dist/useAcknowledgeAnnouncement.js +31 -80
- package/dist/useAcknowledgeAnnouncement.js.map +1 -1
- package/dist/useAnnouncements.d.ts +14 -47
- package/dist/useAnnouncements.d.ts.map +1 -1
- package/dist/useAnnouncements.js +30 -57
- package/dist/useAnnouncements.js.map +1 -1
- package/dist/useConsentForms.d.ts +6 -38
- package/dist/useConsentForms.d.ts.map +1 -1
- package/dist/useConsentForms.js +25 -48
- package/dist/useConsentForms.js.map +1 -1
- package/dist/useProvisionalConsent.d.ts +7 -58
- package/dist/useProvisionalConsent.d.ts.map +1 -1
- package/dist/useProvisionalConsent.js +57 -67
- package/dist/useProvisionalConsent.js.map +1 -1
- package/dist/useSubmitConsent.d.ts +9 -39
- package/dist/useSubmitConsent.d.ts.map +1 -1
- package/dist/useSubmitConsent.js +10 -39
- package/dist/useSubmitConsent.js.map +1 -1
- package/package.json +40 -38
- package/src/ActionSheet.test.tsx +13 -13
- package/src/ActionSheet.tsx +18 -5
- package/src/AddressField.test.tsx +9 -3
- package/src/AnnouncementNavigator.test.tsx +219 -319
- package/src/AnnouncementNavigator.tsx +25 -20
- package/src/Avatar.tsx +2 -9
- package/src/Badge.test.tsx +1 -1
- package/src/Banner.test.tsx +0 -1
- package/src/Box.test.tsx +85 -77
- package/src/Box.tsx +4 -2
- package/src/Button.test.tsx +11 -6
- package/src/Card.test.tsx +2 -2
- package/src/Common.ts +79 -44
- package/src/ConflictSheet.test.tsx +5 -5
- package/src/ConsentFormScreen.test.tsx +3 -1
- package/src/ConsentFormScreen.tsx +2 -1
- package/src/ConsentNavigator.test.tsx +166 -243
- package/src/ConsentNavigator.tsx +9 -13
- package/src/CustomSelectField.test.tsx +16 -4
- package/src/CustomSelectField.tsx +3 -3
- package/src/DataTable.test.tsx +73 -5
- package/src/DataTable.tsx +72 -19
- package/src/DataTableVirtualizationRegression.test.tsx +1 -0
- package/src/DateTimeActionSheet.test.tsx +2 -0
- package/src/DateTimeField.test.tsx +3 -12
- package/src/DateTimeField.tsx +10 -10
- package/src/DismissButton.test.tsx +22 -4
- package/src/DropdownPanel.tsx +0 -6
- package/src/EmailField.test.tsx +13 -22
- package/src/EmojiSelector.test.tsx +2 -2
- package/src/ErrorBoundary.test.tsx +5 -3
- package/src/Field.test.tsx +20 -44
- package/src/FilterAccordion.tsx +3 -3
- package/src/FilterBoolean.tsx +3 -3
- package/src/FilterSelectMenu.tsx +1 -1
- package/src/GPTChat.test.tsx +24 -16
- package/src/GPTChat.tsx +10 -9
- package/src/Heading.test.tsx +1 -1
- package/src/Heading.tsx +7 -14
- package/src/HeightField.tsx +17 -10
- package/src/Hyperlink.tsx +6 -3
- package/src/Icon.test.tsx +2 -2
- package/src/Image.test.tsx +1 -1
- package/src/Link.test.tsx +13 -6
- package/src/MarkdownEditorField.tsx +10 -2
- package/src/MarkdownView.test.tsx +10 -6
- package/src/MobileAddressAutoComplete.test.tsx +2 -1
- package/src/Modal.test.tsx +10 -3
- package/src/ModalSheet.test.tsx +11 -10
- package/src/MultiselectField.test.tsx +17 -3
- package/src/NumberField.test.tsx +14 -14
- package/src/NumberPickerActionSheet.test.tsx +1 -1
- package/src/OfflineBanner.tsx +3 -2
- package/src/OpenAPIContext.test.tsx +4 -4
- package/src/OpenAPIRenderRegression.test.tsx +1 -1
- package/src/OtpField.tsx +6 -5
- package/src/P0RenderRegression.test.tsx +7 -1
- package/src/P1RenderRegression.test.tsx +1 -0
- package/src/P2ButtonRenderRegression.test.tsx +1 -0
- package/src/Page.test.tsx +1 -1
- package/src/PhoneNumberField.test.tsx +14 -38
- package/src/PickerSelect.tsx +12 -11
- package/src/Popover.test.tsx +2 -2
- package/src/ProvisionalConsentSigner.test.tsx +140 -113
- package/src/ProvisionalConsentSigner.tsx +5 -4
- package/src/RadioField.test.tsx +7 -2
- package/src/SegmentedControl.test.tsx +21 -12
- package/src/SidebarNavigation.native.tsx +2 -2
- package/src/SidebarNavigation.test.tsx +18 -6
- package/src/SidebarNavigation.tsx +2 -2
- package/src/Signature.test.tsx +20 -23
- package/src/Skeleton.tsx +1 -1
- package/src/Slider.test.tsx +1 -1
- package/src/SplitPage.test.tsx +15 -5
- package/src/TapToEdit.test.tsx +40 -17
- package/src/TapToEdit.tsx +1 -1
- package/src/TerrenoFontProvider.test.tsx +1 -1
- package/src/Text.test.tsx +4 -4
- package/src/Text.tsx +25 -51
- package/src/TextField.test.tsx +82 -9
- package/src/TextField.tsx +6 -5
- package/src/Theme.test.tsx +49 -0
- package/src/Theme.tsx +16 -0
- package/src/ThumbsUpDownFeedback.tsx +3 -3
- package/src/Toast.test.tsx +5 -5
- package/src/ToastNotifications.test.tsx +73 -70
- package/src/ToastNotifications.tsx +3 -2
- package/src/ToastNotifications.webModal.test.tsx +6 -3
- package/src/Tooltip.test.tsx +3 -3
- package/src/Tooltip.tsx +2 -1
- package/src/UnifiedAddressAutoComplete.test.tsx +1 -1
- package/src/UserInactivity.test.tsx +1 -0
- package/src/WebAddressAutocomplete.test.tsx +12 -12
- package/src/WebAddressAutocomplete.tsx +3 -3
- package/src/WebDropdownMenu.test.tsx +16 -15
- package/src/WebDropdownMenu.tsx +16 -5
- package/src/__snapshots__/Card.test.tsx.snap +1 -1
- package/src/__snapshots__/DataTable.test.tsx.snap +13 -0
- package/src/__snapshots__/DismissButton.test.tsx.snap +3 -3
- package/src/__snapshots__/Field.test.tsx.snap +4 -2
- package/src/__snapshots__/Heading.test.tsx.snap +1 -1
- package/src/__snapshots__/Image.test.tsx.snap +1 -1
- package/src/__snapshots__/Page.test.tsx.snap +2 -2
- package/src/__snapshots__/Text.test.tsx.snap +1 -1
- package/src/announcementPlatform.ts +10 -0
- package/src/asks/AskCard.test.tsx +20 -15
- package/src/asks/AskCard.tsx +2 -2
- package/src/asks/AskFiles.test.tsx +5 -1
- package/src/asks/askFileRefs.test.ts +1 -1
- package/src/asks/askSummary.test.ts +2 -2
- package/src/benchmarks/importTiming.ts +1 -1
- package/src/blocks/BlocksView.test.tsx +20 -11
- package/src/bunSetup.ts +43 -1
- package/src/dataTableColumnWidths.test.ts +266 -0
- package/src/dataTableColumnWidths.ts +272 -0
- package/src/dataTableFilters.test.tsx +1 -1
- package/src/index.tsx +9 -2
- package/src/isolated/ListDetailLayout.isolated.tsx +2 -4
- package/src/login/LoginScreen.test.tsx +6 -6
- package/src/login/LoginScreen.tsx +2 -2
- package/src/requestClient.test.ts +288 -0
- package/src/requestClient.ts +228 -0
- package/src/security/PasswordCard.test.tsx +3 -3
- package/src/security/PasswordCard.tsx +7 -5
- package/src/security/TwoFactorSettingsCard.tsx +10 -3
- package/src/signUp/SignUpScreen.test.tsx +4 -4
- package/src/signUp/SignUpScreen.tsx +2 -2
- package/src/table/Table.tsx +1 -2
- package/src/table/TableTitle.tsx +2 -1
- package/src/table/tableContext.test.tsx +5 -5
- package/src/test-utils.tsx +132 -1
- package/src/testing/reactDomServer.d.ts +7 -0
- package/src/textFontSizes.ts +31 -0
- package/src/useAcknowledgeAnnouncement.test.ts +101 -193
- package/src/useAcknowledgeAnnouncement.ts +69 -147
- package/src/useAnnouncements.test.ts +122 -186
- package/src/useAnnouncements.ts +49 -105
- package/src/useConsentForms.test.ts +59 -112
- package/src/useConsentForms.ts +37 -87
- package/src/useProvisionalConsent.test.ts +74 -150
- package/src/useProvisionalConsent.ts +79 -125
- package/src/useSubmitConsent.test.ts +59 -85
- package/src/useSubmitConsent.ts +22 -77
|
@@ -57,7 +57,7 @@ describe("askFileRefs", () => {
|
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
assert.equal(ref.mimeType, "text/csv");
|
|
60
|
-
assert.isTrue(ref.url
|
|
60
|
+
assert.isTrue(ref.url?.startsWith("data:text/csv;base64,"));
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
it("reads a picked file into a data URL of its declared type, with its byte size", async () => {
|
|
@@ -3,7 +3,7 @@ import type {ChoiceAskInput, ConfirmAskInput, FormAskInput} from "@terreno/block
|
|
|
3
3
|
import {assert} from "chai";
|
|
4
4
|
|
|
5
5
|
import {askSummary} from "./askSummary";
|
|
6
|
-
import type {ChatAsk} from "./askTypes";
|
|
6
|
+
import type {ChatAsk, ChatAskState} from "./askTypes";
|
|
7
7
|
|
|
8
8
|
const PLAN_INPUT: ChoiceAskInput = {
|
|
9
9
|
options: [
|
|
@@ -15,7 +15,7 @@ const PLAN_INPUT: ChoiceAskInput = {
|
|
|
15
15
|
select: "one",
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const planAsk = (state: Partial<
|
|
18
|
+
const planAsk = (state: Partial<ChatAskState> & {input?: ChoiceAskInput}): ChatAsk => ({
|
|
19
19
|
input: PLAN_INPUT,
|
|
20
20
|
kind: "choice",
|
|
21
21
|
status: "answered",
|
|
@@ -28,7 +28,7 @@ describe("fresh import timing", () => {
|
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
`;
|
|
31
|
-
const childEnv = {...process.env, TZ: "America/New_York"};
|
|
31
|
+
const childEnv: NodeJS.ProcessEnv = {...process.env, TZ: "America/New_York"};
|
|
32
32
|
delete childEnv.BUN_OPTIONS;
|
|
33
33
|
writeFileSync(PROBE_FILE, probeSource, "utf8");
|
|
34
34
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {afterEach, describe, expect, it, jest, mock} from "bun:test";
|
|
2
2
|
import {readdirSync, readFileSync} from "node:fs";
|
|
3
3
|
import {join} from "node:path";
|
|
4
|
-
import type {Block} from "@terreno/blocks";
|
|
4
|
+
import type {Block, BlocksDocument} from "@terreno/blocks";
|
|
5
5
|
import {act, fireEvent, waitFor} from "@testing-library/react-native";
|
|
6
6
|
import {setStringAsync} from "expo-clipboard";
|
|
7
7
|
import {ActivityIndicator, Image as NativeImage, ScrollView, StyleSheet} from "react-native";
|
|
@@ -14,6 +14,11 @@ import {renderWithTheme} from "../test-utils";
|
|
|
14
14
|
import {BlocksView} from "./BlocksView";
|
|
15
15
|
import {renderBlock} from "./blockRenderers";
|
|
16
16
|
|
|
17
|
+
/** Treats a document assembled field by field, as untyped model JSON arrives, as a BlocksDocument. */
|
|
18
|
+
const untypedDocument = (fields: Record<string, unknown>): BlocksDocument => {
|
|
19
|
+
return fields as unknown as BlocksDocument;
|
|
20
|
+
};
|
|
21
|
+
|
|
17
22
|
const ACTIONS = `v: 1
|
|
18
23
|
datasets:
|
|
19
24
|
signups:
|
|
@@ -357,8 +362,9 @@ blocks:
|
|
|
357
362
|
data: lamb
|
|
358
363
|
`;
|
|
359
364
|
type StyledNode = {parent: StyledNode | null; props: {style?: unknown}};
|
|
360
|
-
const flatStyle = (node: StyledNode): {textAlign?: string; width?: number} =>
|
|
365
|
+
const flatStyle = (node: StyledNode): {height?: number; textAlign?: string; width?: number} =>
|
|
361
366
|
(StyleSheet.flatten(node.props.style as never) ?? {}) as {
|
|
367
|
+
height?: number;
|
|
362
368
|
textAlign?: string;
|
|
363
369
|
width?: number;
|
|
364
370
|
};
|
|
@@ -771,9 +777,10 @@ blocks:
|
|
|
771
777
|
block.type = "html";
|
|
772
778
|
block.title = "Invoice preview";
|
|
773
779
|
block.html = "<h1>Invoice #1042</h1>";
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
780
|
+
const fields: Record<string, unknown> = {};
|
|
781
|
+
fields.v = 1;
|
|
782
|
+
fields.blocks = [block];
|
|
783
|
+
const document = untypedDocument(fields);
|
|
777
784
|
|
|
778
785
|
const off = renderWithTheme(<BlocksView document={document} />);
|
|
779
786
|
expect(off.getByText("HTML preview is turned off.")).toBeTruthy();
|
|
@@ -804,9 +811,10 @@ blocks:
|
|
|
804
811
|
details.type = "details";
|
|
805
812
|
details.title = "Invoice notes";
|
|
806
813
|
details.text = "Twelve seats, billed monthly.";
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
814
|
+
const fields: Record<string, unknown> = {};
|
|
815
|
+
fields.v = 1;
|
|
816
|
+
fields.blocks = [callout, picture, details];
|
|
817
|
+
const document = untypedDocument(fields);
|
|
810
818
|
|
|
811
819
|
const {getByText} = renderWithTheme(<BlocksView document={document} />);
|
|
812
820
|
|
|
@@ -821,9 +829,10 @@ blocks:
|
|
|
821
829
|
block.type = "image";
|
|
822
830
|
block.alt = "Pixel";
|
|
823
831
|
block.src = "https://evil.test/pixel.png";
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
|
|
832
|
+
const fields: Record<string, unknown> = {};
|
|
833
|
+
fields.v = 1;
|
|
834
|
+
fields.blocks = [block];
|
|
835
|
+
const document = untypedDocument(fields);
|
|
827
836
|
|
|
828
837
|
const blocked = renderWithTheme(<BlocksView document={document} />);
|
|
829
838
|
expect(blocked.getByText(/IMAGE_HOST_NOT_ALLOWED|allowed host/)).toBeTruthy();
|
package/src/bunSetup.ts
CHANGED
|
@@ -158,7 +158,7 @@ const createSimpleFlatList = () => {
|
|
|
158
158
|
const createVirtualizedFlatList = (): React.ForwardRefExoticComponent<
|
|
159
159
|
MockFlatListProps & React.RefAttributes<unknown>
|
|
160
160
|
> =>
|
|
161
|
-
React.forwardRef((props, ref) => {
|
|
161
|
+
React.forwardRef((props: MockFlatListProps, ref) => {
|
|
162
162
|
const {
|
|
163
163
|
data,
|
|
164
164
|
renderItem,
|
|
@@ -662,11 +662,53 @@ if (typeof globalThis.expo === "undefined") {
|
|
|
662
662
|
EventEmitter: EventEmitterClass,
|
|
663
663
|
NativeModule: class NativeModule {},
|
|
664
664
|
SharedObject: class SharedObject {},
|
|
665
|
+
SharedRef: class SharedRef {},
|
|
665
666
|
// noExplicitAny: globalThis.expo is typed by expo-modules-core with many native-only APIs
|
|
666
667
|
// that aren't needed for these mocks, so we cast through unknown to satisfy the type.
|
|
667
668
|
} as unknown as typeof globalThis.expo;
|
|
668
669
|
}
|
|
669
670
|
|
|
671
|
+
// Expo 58's published expo-modules-core compiles the type-only SharedRef
|
|
672
|
+
// declaration to `export {}`. Real expo-router internals (Screen → useNavigation)
|
|
673
|
+
// require expo-constants, which then imports expo-modules-core and crashes bun.
|
|
674
|
+
// Mock both packages so tests never load that empty module.
|
|
675
|
+
const MockCodedError = class CodedError extends Error {
|
|
676
|
+
code: string;
|
|
677
|
+
constructor(code: string, message: string) {
|
|
678
|
+
super(message);
|
|
679
|
+
this.code = code;
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
const MockSharedRef = class SharedRef {};
|
|
683
|
+
mock.module("expo-constants", () => ({
|
|
684
|
+
default: {
|
|
685
|
+
executionEnvironment: "bare",
|
|
686
|
+
expoConfig: {extra: {router: {}}},
|
|
687
|
+
},
|
|
688
|
+
ExecutionEnvironment: {
|
|
689
|
+
Bare: "bare",
|
|
690
|
+
Standalone: "standalone",
|
|
691
|
+
StoreClient: "storeClient",
|
|
692
|
+
},
|
|
693
|
+
}));
|
|
694
|
+
mock.module("expo-modules-core", () => ({
|
|
695
|
+
CodedError: MockCodedError,
|
|
696
|
+
EventEmitter: class EventEmitter {},
|
|
697
|
+
NativeModule: class NativeModule {},
|
|
698
|
+
requireNativeModule: mock(() => ({})),
|
|
699
|
+
requireOptionalNativeModule: mock(() => null),
|
|
700
|
+
SharedObject: class SharedObject {},
|
|
701
|
+
SharedRef: MockSharedRef,
|
|
702
|
+
}));
|
|
703
|
+
mock.module("expo-modules-core/build/ts-declarations/SharedRef", () => ({
|
|
704
|
+
SharedRef: MockSharedRef,
|
|
705
|
+
}));
|
|
706
|
+
mock.module("expo-router/build/views/Screen", () => ({
|
|
707
|
+
isScreen: mock(() => false),
|
|
708
|
+
Screen: ({children, ...props}: MockComponentProps) =>
|
|
709
|
+
React.createElement("Screen", props, children),
|
|
710
|
+
}));
|
|
711
|
+
|
|
670
712
|
// Mock expo-router
|
|
671
713
|
const mockNavigationFonts = {
|
|
672
714
|
bold: {fontFamily: "System", fontWeight: "600"},
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {Platform} from "react-native";
|
|
3
|
+
|
|
4
|
+
import type {DataTableCellData, DataTableColumn} from "./Common";
|
|
5
|
+
import {
|
|
6
|
+
createDataTableTextMeasurer,
|
|
7
|
+
DATA_TABLE_AUTO_CUSTOM_CONTENT_WIDTH,
|
|
8
|
+
DATA_TABLE_AUTO_MAX_COLUMN_WIDTH,
|
|
9
|
+
DATA_TABLE_AUTO_MIN_COLUMN_WIDTH,
|
|
10
|
+
DATA_TABLE_AUTO_WIDTH_SAMPLE_ROWS,
|
|
11
|
+
DATA_TABLE_CELL_HORIZONTAL_PADDING,
|
|
12
|
+
estimateDataTableTextWidth,
|
|
13
|
+
fitDataTableColumnWidths,
|
|
14
|
+
getDataTableNaturalWidths,
|
|
15
|
+
type MeasureDataTableText,
|
|
16
|
+
} from "./dataTableColumnWidths";
|
|
17
|
+
|
|
18
|
+
// One pixel per character keeps expected widths easy to read.
|
|
19
|
+
const measureText: MeasureDataTableText = ({text}) => text.length;
|
|
20
|
+
const formatDate = (value: unknown): string => `date:${String(value)}`;
|
|
21
|
+
const PAD = DATA_TABLE_CELL_HORIZONTAL_PADDING;
|
|
22
|
+
|
|
23
|
+
const naturalWidths = (
|
|
24
|
+
columns: DataTableColumn[],
|
|
25
|
+
data: DataTableCellData[][],
|
|
26
|
+
extra: Partial<Parameters<typeof getDataTableNaturalWidths>[0]> = {}
|
|
27
|
+
): number[] =>
|
|
28
|
+
getDataTableNaturalWidths({
|
|
29
|
+
columns,
|
|
30
|
+
data,
|
|
31
|
+
defaultTextSize: "md",
|
|
32
|
+
formatDate,
|
|
33
|
+
measureText,
|
|
34
|
+
...extra,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("getDataTableNaturalWidths", () => {
|
|
38
|
+
it("keeps an explicit width", () => {
|
|
39
|
+
const widths = naturalWidths(
|
|
40
|
+
[{columnType: "text", title: "Name", width: 222}],
|
|
41
|
+
[[{value: "x".repeat(500)}]]
|
|
42
|
+
);
|
|
43
|
+
expect(widths).toEqual([222]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("sizes to the content when it is wider than the title", () => {
|
|
47
|
+
const content = "c".repeat(120);
|
|
48
|
+
const widths = naturalWidths([{columnType: "text", title: "Name"}], [[{value: content}]]);
|
|
49
|
+
expect(widths).toEqual([120 + PAD]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("sizes to the title and its header icons when they are wider than the content", () => {
|
|
53
|
+
const title = "t".repeat(100);
|
|
54
|
+
const widths = naturalWidths(
|
|
55
|
+
[{columnType: "text", infoModalText: "Help", sortable: true, title}],
|
|
56
|
+
[[{value: "a"}]]
|
|
57
|
+
);
|
|
58
|
+
// Sort icon (24) and info icon (26) sit next to the title.
|
|
59
|
+
expect(widths).toEqual([100 + 24 + 26 + PAD]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("clamps to the minimum and maximum auto widths", () => {
|
|
63
|
+
const widths = naturalWidths(
|
|
64
|
+
[
|
|
65
|
+
{columnType: "text", title: "A"},
|
|
66
|
+
{columnType: "text", title: "B"},
|
|
67
|
+
],
|
|
68
|
+
[[{value: "a"}, {value: "b".repeat(2000)}]]
|
|
69
|
+
);
|
|
70
|
+
expect(widths).toEqual([DATA_TABLE_AUTO_MIN_COLUMN_WIDTH, DATA_TABLE_AUTO_MAX_COLUMN_WIDTH]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("measures dates as they are formatted", () => {
|
|
74
|
+
const widths = naturalWidths(
|
|
75
|
+
[{columnType: "date", title: "D"}],
|
|
76
|
+
[[{value: "2026-01-01T00:00:00.000Z".repeat(4)}]]
|
|
77
|
+
);
|
|
78
|
+
expect(widths).toEqual([formatDate("2026-01-01T00:00:00.000Z".repeat(4)).length + PAD]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("gives a custom column a default content width when its value is not text", () => {
|
|
82
|
+
const widths = naturalWidths([{columnType: "pill", title: "P"}], [[{value: {a: 1}}]], {
|
|
83
|
+
customColumnTypes: new Set(["pill"]),
|
|
84
|
+
});
|
|
85
|
+
expect(widths).toEqual([DATA_TABLE_AUTO_CUSTOM_CONTENT_WIDTH + PAD]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("samples at most a fixed number of rows, spread across the data", () => {
|
|
89
|
+
const spy = mock(measureText);
|
|
90
|
+
const data = Array.from({length: 10_000}, (_, index) => [{value: `row ${index}`}]);
|
|
91
|
+
naturalWidths([{columnType: "text", title: "Name"}], data, {measureText: spy});
|
|
92
|
+
// One call for the header, one per sampled row.
|
|
93
|
+
expect(spy).toHaveBeenCalledTimes(DATA_TABLE_AUTO_WIDTH_SAMPLE_ROWS + 1);
|
|
94
|
+
const measuredRows = spy.mock.calls.slice(1).map(([args]) => args.text);
|
|
95
|
+
// 10,000 rows / 50 samples = every 200th row, so the last sample is row 9,800.
|
|
96
|
+
expect(measuredRows[0]).toBe("row 0");
|
|
97
|
+
expect(measuredRows.at(-1)).toBe("row 9800");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("getDataTableNaturalWidths header and cell extras", () => {
|
|
102
|
+
it("makes room for the filter button only on web when filters are wired up", () => {
|
|
103
|
+
const column: DataTableColumn = {
|
|
104
|
+
columnType: "text",
|
|
105
|
+
filter: {field: "status", kind: "text"},
|
|
106
|
+
title: "t".repeat(100),
|
|
107
|
+
};
|
|
108
|
+
const originalOS = Platform.OS;
|
|
109
|
+
try {
|
|
110
|
+
Platform.OS = "web";
|
|
111
|
+
expect(naturalWidths([column], [[{value: "a"}]], {hasFilters: true})).toEqual([
|
|
112
|
+
100 + 40 + PAD,
|
|
113
|
+
]);
|
|
114
|
+
expect(naturalWidths([column], [[{value: "a"}]], {hasFilters: false})).toEqual([100 + PAD]);
|
|
115
|
+
Platform.OS = "ios";
|
|
116
|
+
expect(naturalWidths([column], [[{value: "a"}]], {hasFilters: true})).toEqual([100 + PAD]);
|
|
117
|
+
} finally {
|
|
118
|
+
Platform.OS = originalOS;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("sizes a boolean column to its icon rather than its value", () => {
|
|
123
|
+
const widths = naturalWidths(
|
|
124
|
+
[{columnType: "boolean", title: "B"}],
|
|
125
|
+
[[{value: "a very long value that is never drawn as text"}]]
|
|
126
|
+
);
|
|
127
|
+
expect(widths).toEqual([DATA_TABLE_AUTO_MIN_COLUMN_WIDTH]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("skips missing cells and non-text values in plain columns", () => {
|
|
131
|
+
const widths = naturalWidths([{columnType: "text", title: "T"}], [[], [{value: {a: 1}}]]);
|
|
132
|
+
expect(widths).toEqual([DATA_TABLE_AUTO_MIN_COLUMN_WIDTH]);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
interface FakeCanvas {
|
|
137
|
+
fonts: string[];
|
|
138
|
+
texts: string[];
|
|
139
|
+
getContext: (kind: string) => unknown;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const fakeCanvas = (width: number): FakeCanvas => {
|
|
143
|
+
const canvas: FakeCanvas = {
|
|
144
|
+
fonts: [],
|
|
145
|
+
getContext: () => ({
|
|
146
|
+
set font(value: string) {
|
|
147
|
+
canvas.fonts.push(value);
|
|
148
|
+
},
|
|
149
|
+
measureText: (text: string) => {
|
|
150
|
+
canvas.texts.push(text);
|
|
151
|
+
return {width};
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
texts: [],
|
|
155
|
+
};
|
|
156
|
+
return canvas;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
describe("createDataTableTextMeasurer", () => {
|
|
160
|
+
const header = {fontSize: 10, isHeader: true, text: "Name"};
|
|
161
|
+
const cell = {fontSize: 16, isHeader: false, text: "Ada Lovelace"};
|
|
162
|
+
|
|
163
|
+
it("estimates when not on web", () => {
|
|
164
|
+
const getDocument = mock(() => ({createElement: () => fakeCanvas(99)}));
|
|
165
|
+
const measure = createDataTableTextMeasurer({getDocument, isWeb: () => false});
|
|
166
|
+
expect(measure(cell)).toBe(estimateDataTableTextWidth(cell));
|
|
167
|
+
expect(getDocument).not.toHaveBeenCalled();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("measures with one cached canvas on web, using the header and cell fonts", () => {
|
|
171
|
+
const canvas = fakeCanvas(41.2);
|
|
172
|
+
const createElement = mock(() => canvas);
|
|
173
|
+
const measure = createDataTableTextMeasurer({
|
|
174
|
+
getDocument: () => ({createElement}),
|
|
175
|
+
isWeb: () => true,
|
|
176
|
+
});
|
|
177
|
+
expect(measure(header)).toBe(42);
|
|
178
|
+
expect(measure(cell)).toBe(42);
|
|
179
|
+
expect(createElement).toHaveBeenCalledTimes(1);
|
|
180
|
+
expect(canvas.fonts).toEqual([
|
|
181
|
+
"700 10px text-bold, Nunito, sans-serif",
|
|
182
|
+
"400 16px text-regular, Nunito, sans-serif",
|
|
183
|
+
]);
|
|
184
|
+
// Headers render uppercase, so they are measured that way.
|
|
185
|
+
expect(canvas.texts).toEqual(["NAME", "Ada Lovelace"]);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("falls back to the estimate when the canvas is a stub that measures 0", () => {
|
|
189
|
+
const measure = createDataTableTextMeasurer({
|
|
190
|
+
getDocument: () => ({createElement: () => fakeCanvas(0)}),
|
|
191
|
+
isWeb: () => true,
|
|
192
|
+
});
|
|
193
|
+
expect(measure(cell)).toBe(estimateDataTableTextWidth(cell));
|
|
194
|
+
expect(measure({...cell, text: ""})).toBe(0);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("estimates when there is no document, no canvas context, or canvas creation throws", () => {
|
|
198
|
+
const noDocument = createDataTableTextMeasurer({
|
|
199
|
+
getDocument: () => undefined,
|
|
200
|
+
isWeb: () => true,
|
|
201
|
+
});
|
|
202
|
+
const noContext = createDataTableTextMeasurer({
|
|
203
|
+
getDocument: () => ({createElement: () => ({})}),
|
|
204
|
+
isWeb: () => true,
|
|
205
|
+
});
|
|
206
|
+
const getDocument = mock(() => ({
|
|
207
|
+
createElement: (): unknown => {
|
|
208
|
+
throw new Error("no canvas");
|
|
209
|
+
},
|
|
210
|
+
}));
|
|
211
|
+
const throwing = createDataTableTextMeasurer({getDocument, isWeb: () => true});
|
|
212
|
+
for (const measure of [noDocument, noContext, throwing]) {
|
|
213
|
+
expect(measure(cell)).toBe(estimateDataTableTextWidth(cell));
|
|
214
|
+
}
|
|
215
|
+
// A failed lookup is cached rather than retried on every cell.
|
|
216
|
+
throwing(cell);
|
|
217
|
+
expect(getDocument).toHaveBeenCalledTimes(1);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("defaults to the global document and Platform.OS", () => {
|
|
221
|
+
const measure = createDataTableTextMeasurer();
|
|
222
|
+
expect(measure(cell)).toBeGreaterThan(0);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe("fitDataTableColumnWidths", () => {
|
|
227
|
+
it("keeps natural widths before the container is measured", () => {
|
|
228
|
+
const columns: DataTableColumn[] = [{columnType: "text", title: "A"}];
|
|
229
|
+
expect(fitDataTableColumnWidths({availableWidth: 0, columns, naturalWidths: [100]})).toEqual([
|
|
230
|
+
100,
|
|
231
|
+
]);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("grows auto columns in proportion to fill the container exactly", () => {
|
|
235
|
+
const columns: DataTableColumn[] = [
|
|
236
|
+
{columnType: "text", title: "A"},
|
|
237
|
+
{columnType: "text", title: "B", width: 100},
|
|
238
|
+
{columnType: "text", title: "C"},
|
|
239
|
+
];
|
|
240
|
+
const widths = fitDataTableColumnWidths({
|
|
241
|
+
availableWidth: 1001,
|
|
242
|
+
columns,
|
|
243
|
+
naturalWidths: [100, 100, 300],
|
|
244
|
+
});
|
|
245
|
+
expect(widths[1]).toBe(100);
|
|
246
|
+
expect(widths[0]).toBe(100 + Math.floor((501 * 100) / 400));
|
|
247
|
+
expect(widths.reduce((sum, width) => sum + width, 0)).toBe(1001);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("keeps natural widths when the columns overflow the container", () => {
|
|
251
|
+
const columns: DataTableColumn[] = [
|
|
252
|
+
{columnType: "text", title: "A"},
|
|
253
|
+
{columnType: "text", title: "B"},
|
|
254
|
+
];
|
|
255
|
+
expect(
|
|
256
|
+
fitDataTableColumnWidths({availableWidth: 300, columns, naturalWidths: [200, 200]})
|
|
257
|
+
).toEqual([200, 200]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("never changes explicit widths, even with room to spare", () => {
|
|
261
|
+
const columns: DataTableColumn[] = [{columnType: "text", title: "A", width: 120}];
|
|
262
|
+
expect(fitDataTableColumnWidths({availableWidth: 900, columns, naturalWidths: [120]})).toEqual([
|
|
263
|
+
120,
|
|
264
|
+
]);
|
|
265
|
+
});
|
|
266
|
+
});
|