@terreno/ui 0.30.0 → 0.31.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.
- package/LICENSE +21 -203
- package/dist/Common.d.ts +39 -0
- package/dist/Common.js.map +1 -1
- package/dist/EditableCard.d.ts +3 -0
- package/dist/EditableCard.js +23 -0
- package/dist/EditableCard.js.map +1 -0
- package/dist/Theme.js +1 -0
- package/dist/Theme.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/ActionSheet.test.tsx +80 -37
- package/src/Common.ts +47 -0
- package/src/ConsentHistory.test.tsx +64 -1
- package/src/ConsentNavigator.test.tsx +6 -8
- package/src/DataTable.test.tsx +15 -21
- package/src/DateTimeField.test.tsx +36 -0
- package/src/DraggableList.test.tsx +377 -0
- package/src/EditableCard.test.tsx +69 -0
- package/src/EditableCard.tsx +73 -0
- package/src/PickerSelect.test.tsx +23 -12
- package/src/SidebarNavigation.test.tsx +339 -0
- package/src/TapToEdit.test.tsx +8 -14
- package/src/Theme.tsx +1 -0
- package/src/Tooltip.test.tsx +1 -0
- package/src/__snapshots__/Card.test.tsx.snap +1 -0
- package/src/__snapshots__/EditableCard.test.tsx.snap +242 -0
- package/src/bunSetup.ts +6 -2
- package/src/generateConsentHistoryPdf.test.ts +253 -0
- package/src/index.tsx +1 -0
package/src/Common.ts
CHANGED
|
@@ -219,6 +219,7 @@ export interface TextThemeConfig {
|
|
|
219
219
|
export interface SurfaceThemeConfig {
|
|
220
220
|
base: keyof ThemePrimitiveColors;
|
|
221
221
|
primary: keyof ThemePrimitiveColors;
|
|
222
|
+
secondaryExtraLight: keyof ThemePrimitiveColors;
|
|
222
223
|
secondaryLight: keyof ThemePrimitiveColors;
|
|
223
224
|
secondaryDark: keyof ThemePrimitiveColors;
|
|
224
225
|
secondaryExtraDark: keyof ThemePrimitiveColors;
|
|
@@ -287,6 +288,7 @@ export interface TextTheme {
|
|
|
287
288
|
export interface SurfaceTheme {
|
|
288
289
|
base: string;
|
|
289
290
|
primary: string;
|
|
291
|
+
secondaryExtraLight: string;
|
|
290
292
|
secondaryLight: string;
|
|
291
293
|
secondaryDark: string;
|
|
292
294
|
secondaryExtraDark: string;
|
|
@@ -685,6 +687,51 @@ export type CardProps = BoxProps & {
|
|
|
685
687
|
imageHeight?: number;
|
|
686
688
|
};
|
|
687
689
|
|
|
690
|
+
export type EditableCardProps = BoxProps & {
|
|
691
|
+
/**
|
|
692
|
+
* The name of an icon shown before the title.
|
|
693
|
+
*/
|
|
694
|
+
iconName?: IconName;
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* The title of the summarized information.
|
|
698
|
+
*/
|
|
699
|
+
title?: string;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Props for a badge rendered next to the title.
|
|
703
|
+
*/
|
|
704
|
+
badge?: BadgeProps;
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* The summarized information itself, displayed below the title.
|
|
708
|
+
*/
|
|
709
|
+
description?: string;
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Secondary text displayed below the description, in a muted style.
|
|
713
|
+
*/
|
|
714
|
+
helperText?: string;
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Callback invoked when the edit button is pressed. The edit button is only rendered when this
|
|
718
|
+
* is provided.
|
|
719
|
+
*/
|
|
720
|
+
onEdit?: () => void | Promise<void>;
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Accessibility label for the edit button.
|
|
724
|
+
* @default "Edit"
|
|
725
|
+
*/
|
|
726
|
+
editAccessibilityLabel?: string;
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* If true, the card is highlighted to draw attention to it, e.g. for content that needs review.
|
|
730
|
+
* @default false
|
|
731
|
+
*/
|
|
732
|
+
attention?: boolean;
|
|
733
|
+
};
|
|
734
|
+
|
|
688
735
|
export interface ErrorBoundaryProps {
|
|
689
736
|
onError?: (error: Error, stack: string) => void;
|
|
690
737
|
children?: ReactNode;
|
|
@@ -1,5 +1,44 @@
|
|
|
1
|
-
import {describe, expect, it, mock} from "bun:test";
|
|
1
|
+
import {afterAll, describe, expect, it, mock} from "bun:test";
|
|
2
2
|
import {act, fireEvent, waitFor} from "@testing-library/react-native";
|
|
3
|
+
import {Pressable} from "react-native";
|
|
4
|
+
|
|
5
|
+
// The download control is an IconButton wrapped in a Tooltip, which does not
|
|
6
|
+
// render its trigger in the test renderer. Mock it to a plain pressable that
|
|
7
|
+
// forwards onClick and testID, matching the InfoTooltipButton test pattern.
|
|
8
|
+
mock.module("./IconButton", () => ({
|
|
9
|
+
IconButton: ({
|
|
10
|
+
onClick,
|
|
11
|
+
testID,
|
|
12
|
+
loading,
|
|
13
|
+
}: {
|
|
14
|
+
onClick?: () => void;
|
|
15
|
+
testID?: string;
|
|
16
|
+
loading?: boolean;
|
|
17
|
+
}) => <Pressable disabled={loading} onPress={onClick} testID={testID} />,
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
// Stub jsPDF so exercising the download handler does not write a PDF file to
|
|
21
|
+
// disk. Methods are no-ops; splitTextToSize returns an empty line set.
|
|
22
|
+
class StubJsPdf {
|
|
23
|
+
setFontSize(): void {}
|
|
24
|
+
setFont(): void {}
|
|
25
|
+
setDrawColor(): void {}
|
|
26
|
+
setTextColor(): void {}
|
|
27
|
+
text(): void {}
|
|
28
|
+
line(): void {}
|
|
29
|
+
addPage(): void {}
|
|
30
|
+
addImage(): void {}
|
|
31
|
+
splitTextToSize(): string[] {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
save(): void {}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
mock.module("jspdf", () => ({jsPDF: StubJsPdf}));
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
mock.module("./IconButton", () => ({IconButton: mock(() => null)}));
|
|
41
|
+
});
|
|
3
42
|
|
|
4
43
|
import {ConsentHistory} from "./ConsentHistory";
|
|
5
44
|
import {renderWithTheme} from "./test-utils";
|
|
@@ -158,4 +197,28 @@ describe("ConsentHistory", () => {
|
|
|
158
197
|
);
|
|
159
198
|
expect(getByTestId("consent-history-item-entry-1")).toBeTruthy();
|
|
160
199
|
});
|
|
200
|
+
|
|
201
|
+
it("invokes PDF generation and resets the loading state after a download", async () => {
|
|
202
|
+
const originalError = console.error;
|
|
203
|
+
console.error = mock(() => {}) as unknown as typeof console.error;
|
|
204
|
+
try {
|
|
205
|
+
const {getByTestId} = renderWithTheme(
|
|
206
|
+
<ConsentHistory api={createApi({data: [makeEntry()]})} />
|
|
207
|
+
);
|
|
208
|
+
fireEvent.press(getByTestId("consent-history-item-toggle-entry-1"));
|
|
209
|
+
|
|
210
|
+
await act(async () => {
|
|
211
|
+
fireEvent.press(getByTestId("consent-history-download-entry-1"));
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// The button remains mounted after the async handler settles (loading
|
|
215
|
+
// state was toggled back off), regardless of whether PDF generation
|
|
216
|
+
// succeeded or threw in the headless test environment.
|
|
217
|
+
await waitFor(() => {
|
|
218
|
+
expect(getByTestId("consent-history-download-entry-1")).toBeTruthy();
|
|
219
|
+
});
|
|
220
|
+
} finally {
|
|
221
|
+
console.error = originalError;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
161
224
|
});
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// noExplicitAny: test mock typing
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
4
2
|
import React from "react";
|
|
5
3
|
import {Pressable} from "react-native";
|
|
@@ -186,7 +184,7 @@ describe("ConsentNavigator", () => {
|
|
|
186
184
|
};
|
|
187
185
|
|
|
188
186
|
const {getByText} = renderWithTheme(
|
|
189
|
-
<ConsentNavigator api={api
|
|
187
|
+
<ConsentNavigator api={api}>
|
|
190
188
|
<Text>App Content</Text>
|
|
191
189
|
</ConsentNavigator>
|
|
192
190
|
);
|
|
@@ -212,7 +210,7 @@ describe("ConsentNavigator", () => {
|
|
|
212
210
|
};
|
|
213
211
|
|
|
214
212
|
const {getByText} = renderWithTheme(
|
|
215
|
-
<ConsentNavigator api={api
|
|
213
|
+
<ConsentNavigator api={api}>
|
|
216
214
|
<Text>App Content</Text>
|
|
217
215
|
</ConsentNavigator>
|
|
218
216
|
);
|
|
@@ -239,7 +237,7 @@ describe("ConsentNavigator", () => {
|
|
|
239
237
|
};
|
|
240
238
|
|
|
241
239
|
const {getByTestId, getByText} = renderWithTheme(
|
|
242
|
-
<ConsentNavigator api={api
|
|
240
|
+
<ConsentNavigator api={api} onError={onError}>
|
|
243
241
|
<Text>App Content</Text>
|
|
244
242
|
</ConsentNavigator>
|
|
245
243
|
);
|
|
@@ -284,7 +282,7 @@ describe("ConsentNavigator", () => {
|
|
|
284
282
|
};
|
|
285
283
|
|
|
286
284
|
const {getByTestId} = renderWithTheme(
|
|
287
|
-
<ConsentNavigator api={api
|
|
285
|
+
<ConsentNavigator api={api}>
|
|
288
286
|
<Text>App Content</Text>
|
|
289
287
|
</ConsentNavigator>
|
|
290
288
|
);
|
|
@@ -321,7 +319,7 @@ describe("ConsentNavigator", () => {
|
|
|
321
319
|
};
|
|
322
320
|
|
|
323
321
|
const {getByTestId} = renderWithTheme(
|
|
324
|
-
<ConsentNavigator api={api
|
|
322
|
+
<ConsentNavigator api={api} onError={onError}>
|
|
325
323
|
<Text>App Content</Text>
|
|
326
324
|
</ConsentNavigator>
|
|
327
325
|
);
|
|
@@ -361,7 +359,7 @@ describe("ConsentNavigator", () => {
|
|
|
361
359
|
};
|
|
362
360
|
|
|
363
361
|
const {getByTestId} = renderWithTheme(
|
|
364
|
-
<ConsentNavigator api={api
|
|
362
|
+
<ConsentNavigator api={api}>
|
|
365
363
|
<Text>App Content</Text>
|
|
366
364
|
</ConsentNavigator>
|
|
367
365
|
);
|
package/src/DataTable.test.tsx
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// noExplicitAny: test mock typing
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
4
2
|
import {act} from "@testing-library/react-native";
|
|
5
3
|
|
|
@@ -8,6 +6,8 @@ import {DataTable} from "./DataTable";
|
|
|
8
6
|
import {Text} from "./Text";
|
|
9
7
|
import {renderWithTheme} from "./test-utils";
|
|
10
8
|
|
|
9
|
+
type MoreContentComponent = NonNullable<DataTableProps["moreContentComponent"]>;
|
|
10
|
+
|
|
11
11
|
describe("DataTable", () => {
|
|
12
12
|
const sampleColumns = [
|
|
13
13
|
{columnType: "text", title: "Name", width: 150},
|
|
@@ -112,13 +112,9 @@ describe("DataTable", () => {
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
it("renders with more content component", () => {
|
|
115
|
-
const MoreContent = ({rowIndex}
|
|
115
|
+
const MoreContent: MoreContentComponent = ({rowIndex}) => <Text>Row {rowIndex} details</Text>;
|
|
116
116
|
const {toJSON} = renderWithTheme(
|
|
117
|
-
<DataTable
|
|
118
|
-
columns={sampleColumns}
|
|
119
|
-
data={sampleData}
|
|
120
|
-
moreContentComponent={MoreContent as unknown as DataTableProps["moreContentComponent"]}
|
|
121
|
-
/>
|
|
117
|
+
<DataTable columns={sampleColumns} data={sampleData} moreContentComponent={MoreContent} />
|
|
122
118
|
);
|
|
123
119
|
expect(toJSON()).toMatchSnapshot();
|
|
124
120
|
});
|
|
@@ -266,7 +262,7 @@ describe("DataTable", () => {
|
|
|
266
262
|
});
|
|
267
263
|
|
|
268
264
|
it("renders with custom column component map", () => {
|
|
269
|
-
const CustomComponent = ({cellData}
|
|
265
|
+
const CustomComponent: DataTableCustomComponentMap[string] = ({cellData}) => (
|
|
270
266
|
<Text>Custom: {String(cellData.value)}</Text>
|
|
271
267
|
);
|
|
272
268
|
const customColumns = [{columnType: "custom", title: "Custom Col", width: 150}];
|
|
@@ -274,7 +270,7 @@ describe("DataTable", () => {
|
|
|
274
270
|
const {getByText} = renderWithTheme(
|
|
275
271
|
<DataTable
|
|
276
272
|
columns={customColumns}
|
|
277
|
-
customColumnComponentMap={{custom: CustomComponent
|
|
273
|
+
customColumnComponentMap={{custom: CustomComponent}}
|
|
278
274
|
data={customData}
|
|
279
275
|
/>
|
|
280
276
|
);
|
|
@@ -300,16 +296,16 @@ describe("DataTable", () => {
|
|
|
300
296
|
});
|
|
301
297
|
|
|
302
298
|
it("renders with moreContentExtraData", () => {
|
|
303
|
-
const MoreContent = ({rowIndex, extraInfo}
|
|
299
|
+
const MoreContent: MoreContentComponent = ({rowIndex, extraInfo}) => (
|
|
304
300
|
<Text>
|
|
305
|
-
Row {rowIndex}: {extraInfo}
|
|
301
|
+
Row {rowIndex}: {String(extraInfo)}
|
|
306
302
|
</Text>
|
|
307
303
|
);
|
|
308
304
|
const {toJSON} = renderWithTheme(
|
|
309
305
|
<DataTable
|
|
310
306
|
columns={sampleColumns}
|
|
311
307
|
data={sampleData}
|
|
312
|
-
moreContentComponent={MoreContent
|
|
308
|
+
moreContentComponent={MoreContent}
|
|
313
309
|
moreContentExtraData={[{extraInfo: "info1"}, {extraInfo: "info2"}, {extraInfo: "info3"}]}
|
|
314
310
|
/>
|
|
315
311
|
);
|
|
@@ -317,13 +313,11 @@ describe("DataTable", () => {
|
|
|
317
313
|
});
|
|
318
314
|
|
|
319
315
|
it("opens and dismisses more content modal via MoreButtonCell press", async () => {
|
|
320
|
-
const MoreContent = ({rowIndex}
|
|
316
|
+
const MoreContent: MoreContentComponent = ({rowIndex}) => (
|
|
317
|
+
<Text>Detail for row {rowIndex}</Text>
|
|
318
|
+
);
|
|
321
319
|
const {UNSAFE_getAllByType} = renderWithTheme(
|
|
322
|
-
<DataTable
|
|
323
|
-
columns={sampleColumns}
|
|
324
|
-
data={sampleData}
|
|
325
|
-
moreContentComponent={MoreContent as any}
|
|
326
|
-
/>
|
|
320
|
+
<DataTable columns={sampleColumns} data={sampleData} moreContentComponent={MoreContent} />
|
|
327
321
|
);
|
|
328
322
|
|
|
329
323
|
const {Pressable: PressableComp} = require("react-native");
|
|
@@ -352,7 +346,7 @@ describe("DataTable", () => {
|
|
|
352
346
|
});
|
|
353
347
|
|
|
354
348
|
it("renders with customColumnComponentMap", () => {
|
|
355
|
-
const CustomCell = ({cellData}
|
|
349
|
+
const CustomCell: DataTableCustomComponentMap[string] = ({cellData}) => (
|
|
356
350
|
<Text>Custom: {String(cellData.value)}</Text>
|
|
357
351
|
);
|
|
358
352
|
const customColumns = [
|
|
@@ -363,7 +357,7 @@ describe("DataTable", () => {
|
|
|
363
357
|
const {getByText} = renderWithTheme(
|
|
364
358
|
<DataTable
|
|
365
359
|
columns={customColumns}
|
|
366
|
-
customColumnComponentMap={{custom: CustomCell}
|
|
360
|
+
customColumnComponentMap={{custom: CustomCell}}
|
|
367
361
|
data={customData}
|
|
368
362
|
/>
|
|
369
363
|
);
|
|
@@ -11,7 +11,9 @@ import {
|
|
|
11
11
|
mock,
|
|
12
12
|
} from "bun:test";
|
|
13
13
|
import {act, userEvent} from "@testing-library/react-native";
|
|
14
|
+
import {assert} from "chai";
|
|
14
15
|
import {DateTime} from "luxon";
|
|
16
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
15
17
|
|
|
16
18
|
import {DateTimeField} from "./DateTimeField";
|
|
17
19
|
import {renderWithTheme, setupComponentTest, teardownComponentTest} from "./test-utils";
|
|
@@ -1310,6 +1312,40 @@ describe("DateTimeField", () => {
|
|
|
1310
1312
|
});
|
|
1311
1313
|
});
|
|
1312
1314
|
|
|
1315
|
+
describe("TimezonePicker onChange", () => {
|
|
1316
|
+
it("forwards the picked timezone to onTimezoneChange and emits a new value", async () => {
|
|
1317
|
+
setDesktop();
|
|
1318
|
+
const mockTzChange = mock(() => {});
|
|
1319
|
+
const {UNSAFE_root} = renderWithTheme(
|
|
1320
|
+
<DateTimeField
|
|
1321
|
+
onChange={mockOnChange}
|
|
1322
|
+
onTimezoneChange={mockTzChange}
|
|
1323
|
+
timezone="America/New_York"
|
|
1324
|
+
type="time"
|
|
1325
|
+
value="2023-05-15T15:30:00.000Z"
|
|
1326
|
+
/>
|
|
1327
|
+
);
|
|
1328
|
+
|
|
1329
|
+
// Select the rendered TimezonePicker itself rather than any ancestor that happens to
|
|
1330
|
+
// have an onTimezoneChange prop, so the component's own handler runs.
|
|
1331
|
+
const pickers = UNSAFE_root.findAll((node: ReactTestInstance) =>
|
|
1332
|
+
Boolean((node.props as {shortTimezone?: boolean}).shortTimezone)
|
|
1333
|
+
);
|
|
1334
|
+
assert.isAbove(pickers.length, 0);
|
|
1335
|
+
await act(async () => {
|
|
1336
|
+
pickers[0].props.onChange("America/Chicago");
|
|
1337
|
+
});
|
|
1338
|
+
|
|
1339
|
+
assert.isTrue(mockTzChange.mock.calls.some((call) => call[0] === "America/Chicago"));
|
|
1340
|
+
// The picked timezone is applied to the current segments and emitted.
|
|
1341
|
+
assert.isAbove(mockOnChange.mock.calls.length, 0);
|
|
1342
|
+
assert.equal(
|
|
1343
|
+
mockOnChange.mock.calls[mockOnChange.mock.calls.length - 1][0],
|
|
1344
|
+
"2023-05-15T16:30:00.000Z"
|
|
1345
|
+
);
|
|
1346
|
+
});
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1313
1349
|
describe("minute validation in validateField", () => {
|
|
1314
1350
|
it("should validate minute field for datetime type via hour change triggering revalidation", async () => {
|
|
1315
1351
|
setDesktop();
|