@terreno/ui 0.22.2 → 0.23.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 (97) hide show
  1. package/README.md +27 -0
  2. package/dist/Accordion.js +3 -3
  3. package/dist/Accordion.js.map +1 -1
  4. package/dist/BooleanField.js +6 -4
  5. package/dist/BooleanField.js.map +1 -1
  6. package/dist/Box.js +3 -2
  7. package/dist/Box.js.map +1 -1
  8. package/dist/CheckBox.js +2 -2
  9. package/dist/CheckBox.js.map +1 -1
  10. package/dist/Common.d.ts +40 -57
  11. package/dist/Common.js +1 -0
  12. package/dist/Common.js.map +1 -1
  13. package/dist/CustomSelectField.js +5 -3
  14. package/dist/CustomSelectField.js.map +1 -1
  15. package/dist/DataTable.js +18 -12
  16. package/dist/DataTable.js.map +1 -1
  17. package/dist/DateTimeField.js +5 -3
  18. package/dist/DateTimeField.js.map +1 -1
  19. package/dist/Link.js +2 -2
  20. package/dist/Link.js.map +1 -1
  21. package/dist/MarkdownEditor.js +14 -2
  22. package/dist/MarkdownEditor.js.map +1 -1
  23. package/dist/MarkdownEditorField.js +18 -4
  24. package/dist/MarkdownEditorField.js.map +1 -1
  25. package/dist/Modal.js +10 -6
  26. package/dist/Modal.js.map +1 -1
  27. package/dist/MultiselectField.js +5 -3
  28. package/dist/MultiselectField.js.map +1 -1
  29. package/dist/Page.js +1 -1
  30. package/dist/Page.js.map +1 -1
  31. package/dist/Pagination.js +2 -2
  32. package/dist/Pagination.js.map +1 -1
  33. package/dist/SegmentedControl.js +5 -3
  34. package/dist/SegmentedControl.js.map +1 -1
  35. package/dist/SelectField.js +5 -3
  36. package/dist/SelectField.js.map +1 -1
  37. package/dist/SocialLoginButton.js +2 -1
  38. package/dist/SocialLoginButton.js.map +1 -1
  39. package/dist/Spinner.js +3 -2
  40. package/dist/Spinner.js.map +1 -1
  41. package/dist/TextField.js +6 -4
  42. package/dist/TextField.js.map +1 -1
  43. package/dist/fieldElements/FieldError.d.ts +1 -0
  44. package/dist/fieldElements/FieldError.js +3 -2
  45. package/dist/fieldElements/FieldError.js.map +1 -1
  46. package/dist/fieldElements/FieldHelperText.d.ts +1 -0
  47. package/dist/fieldElements/FieldHelperText.js +3 -2
  48. package/dist/fieldElements/FieldHelperText.js.map +1 -1
  49. package/dist/fieldElements/FieldTitle.d.ts +1 -0
  50. package/dist/fieldElements/FieldTitle.js +4 -3
  51. package/dist/fieldElements/FieldTitle.js.map +1 -1
  52. package/dist/testing/index.d.ts +2 -0
  53. package/dist/testing/index.js +3 -0
  54. package/dist/testing/index.js.map +1 -0
  55. package/dist/testing/resolveTestId.d.ts +39 -0
  56. package/dist/testing/resolveTestId.js +97 -0
  57. package/dist/testing/resolveTestId.js.map +1 -0
  58. package/dist/testing/types.d.ts +59 -0
  59. package/dist/testing/types.js +2 -0
  60. package/dist/testing/types.js.map +1 -0
  61. package/package.json +1 -1
  62. package/src/Accordion.tsx +3 -1
  63. package/src/BooleanField.tsx +13 -3
  64. package/src/Box.tsx +3 -2
  65. package/src/CheckBox.tsx +7 -1
  66. package/src/Common.ts +62 -60
  67. package/src/CustomSelectField.tsx +8 -1
  68. package/src/DataTable.tsx +40 -3
  69. package/src/DateTimeField.tsx +10 -3
  70. package/src/Link.tsx +2 -1
  71. package/src/MarkdownEditor.tsx +52 -27
  72. package/src/MarkdownEditorField.tsx +37 -16
  73. package/src/Modal.tsx +13 -0
  74. package/src/MultiselectField.tsx +8 -3
  75. package/src/Page.tsx +1 -0
  76. package/src/Pagination.tsx +2 -1
  77. package/src/SegmentedControl.tsx +15 -2
  78. package/src/SelectField.tsx +8 -3
  79. package/src/SocialLoginButton.tsx +2 -1
  80. package/src/Spinner.tsx +3 -2
  81. package/src/TextField.tsx +8 -5
  82. package/src/__snapshots__/AddressField.test.tsx.snap +4 -0
  83. package/src/__snapshots__/BooleanField.test.tsx.snap +4 -0
  84. package/src/__snapshots__/Field.test.tsx.snap +8 -0
  85. package/src/__snapshots__/Link.test.tsx.snap +1 -0
  86. package/src/__snapshots__/Page.test.tsx.snap +21 -0
  87. package/src/__snapshots__/SegmentedControl.test.tsx.snap +4 -0
  88. package/src/__snapshots__/UnifiedAddressAutoComplete.test.tsx.snap +1 -0
  89. package/src/fieldElements/FieldError.tsx +7 -2
  90. package/src/fieldElements/FieldHelperText.tsx +4 -2
  91. package/src/fieldElements/FieldTitle.tsx +4 -1
  92. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +4 -0
  93. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +5 -0
  94. package/src/testing/index.ts +2 -0
  95. package/src/testing/resolveTestId.test.ts +130 -0
  96. package/src/testing/resolveTestId.ts +142 -0
  97. package/src/testing/types.ts +67 -0
@@ -0,0 +1,130 @@
1
+ import {describe, expect, it} from "bun:test";
2
+
3
+ import {
4
+ resolveDataTableRowTestID,
5
+ resolveFieldTestIDs,
6
+ resolveModalTestIDs,
7
+ resolveSegmentedControlTestIDs,
8
+ resolveSegmentedControlTestIDsFromProps,
9
+ resolveTestID,
10
+ toDomTestProps,
11
+ toTestProps,
12
+ } from "./resolveTestId";
13
+
14
+ describe("resolveTestID", () => {
15
+ it("returns base when part is omitted", () => {
16
+ expect(resolveTestID("login")).toBe("login");
17
+ });
18
+
19
+ it("joins base and part with a dot", () => {
20
+ expect(resolveTestID("login", "email")).toBe("login.email");
21
+ expect(resolveTestID("login.email", "input")).toBe("login.email.input");
22
+ });
23
+
24
+ it("returns undefined when base is absent", () => {
25
+ expect(resolveTestID(undefined, "input")).toBeUndefined();
26
+ });
27
+ });
28
+
29
+ describe("toTestProps", () => {
30
+ it("returns testID for React Native components", () => {
31
+ expect(toTestProps("submit")).toEqual({testID: "submit"});
32
+ });
33
+
34
+ it("returns empty object when id is absent", () => {
35
+ expect(toTestProps(undefined)).toEqual({});
36
+ });
37
+ });
38
+
39
+ describe("toDomTestProps", () => {
40
+ it("returns data-testid for DOM elements", () => {
41
+ expect(toDomTestProps("submit")).toEqual({"data-testid": "submit"});
42
+ });
43
+ });
44
+
45
+ describe("resolveFieldTestIDs", () => {
46
+ it("applies dot-suffix defaults", () => {
47
+ expect(resolveFieldTestIDs("signup.email")).toEqual({
48
+ error: "signup.email.error",
49
+ helper: "signup.email.helper",
50
+ input: "signup.email",
51
+ label: "signup.email.label",
52
+ });
53
+ });
54
+
55
+ it("allows testIDs overrides", () => {
56
+ expect(
57
+ resolveFieldTestIDs("signup.email", {
58
+ input: "custom-input",
59
+ label: "custom-label",
60
+ })
61
+ ).toEqual({
62
+ error: "signup.email.error",
63
+ helper: "signup.email.helper",
64
+ input: "custom-input",
65
+ label: "custom-label",
66
+ });
67
+ });
68
+ });
69
+
70
+ describe("resolveModalTestIDs", () => {
71
+ it("applies dot-suffix defaults", () => {
72
+ expect(resolveModalTestIDs("confirm-delete")).toEqual({
73
+ dismiss: "confirm-delete.dismiss",
74
+ primaryButton: "confirm-delete.primary",
75
+ root: "confirm-delete",
76
+ secondaryButton: "confirm-delete.secondary",
77
+ title: "confirm-delete.title",
78
+ });
79
+ });
80
+ });
81
+
82
+ describe("resolveDataTableRowTestID", () => {
83
+ it("appends row key to row test id base", () => {
84
+ expect(resolveDataTableRowTestID("users-table.row", "abc123")).toBe("users-table.row-abc123");
85
+ });
86
+
87
+ it("returns undefined when base is absent", () => {
88
+ expect(resolveDataTableRowTestID(undefined, "abc123")).toBeUndefined();
89
+ });
90
+ });
91
+
92
+ describe("resolveSegmentedControlTestIDs", () => {
93
+ it("applies dot-suffix defaults", () => {
94
+ expect(resolveSegmentedControlTestIDs("schedule.nav")).toEqual({
95
+ nextButton: "schedule.nav.next",
96
+ previousButton: "schedule.nav.previous",
97
+ root: "schedule.nav",
98
+ });
99
+ });
100
+
101
+ it("allows testIDs overrides", () => {
102
+ expect(
103
+ resolveSegmentedControlTestIDs("schedule.nav", {
104
+ nextButton: "custom-next",
105
+ previousButton: "custom-previous",
106
+ })
107
+ ).toEqual({
108
+ nextButton: "custom-next",
109
+ previousButton: "custom-previous",
110
+ root: "schedule.nav",
111
+ });
112
+ });
113
+ });
114
+
115
+ describe("resolveSegmentedControlTestIDsFromProps", () => {
116
+ it("resolves using component props", () => {
117
+ expect(
118
+ resolveSegmentedControlTestIDsFromProps({
119
+ testID: "schedule.nav",
120
+ testIDs: {
121
+ root: "custom-root",
122
+ },
123
+ })
124
+ ).toEqual({
125
+ nextButton: "schedule.nav.next",
126
+ previousButton: "schedule.nav.previous",
127
+ root: "custom-root",
128
+ });
129
+ });
130
+ });
@@ -0,0 +1,142 @@
1
+ import {Platform} from "react-native";
2
+
3
+ import type {
4
+ DataTableTestIDs,
5
+ FieldTestIDs,
6
+ ModalTestIDs,
7
+ ResolvedDataTableTestIDs,
8
+ ResolvedFieldTestIDs,
9
+ ResolvedModalTestIDs,
10
+ ResolvedSegmentedControlTestIDs,
11
+ SegmentedControlTestIDs,
12
+ WithTestID,
13
+ } from "./types";
14
+
15
+ /** Build a dot-suffixed test id, e.g. `login.email` + `input` → `login.email.input`. */
16
+ export const resolveTestID = (base: string | undefined, part?: string): string | undefined => {
17
+ if (!base) {
18
+ return undefined;
19
+ }
20
+ if (!part) {
21
+ return base;
22
+ }
23
+ return `${base}.${part}`;
24
+ };
25
+
26
+ /** React Native / RN Web test props (`testID` maps to `data-testid` on web). */
27
+ export const toTestProps = (id: string | undefined): {testID?: string} => {
28
+ if (!id) {
29
+ return {};
30
+ }
31
+ return {testID: id};
32
+ };
33
+
34
+ /** Plain DOM test props for web-only components. */
35
+ export const toDomTestProps = (id: string | undefined): {"data-testid"?: string} => {
36
+ if (!id) {
37
+ return {};
38
+ }
39
+ return {"data-testid": id};
40
+ };
41
+
42
+ /** Cross-platform test props — RN uses `testID`, web DOM uses `data-testid`. */
43
+ export const toPlatformTestProps = (
44
+ id: string | undefined
45
+ ): {testID?: string; "data-testid"?: string} => {
46
+ if (!id) {
47
+ return {};
48
+ }
49
+ if (Platform.OS === "web") {
50
+ return {"data-testid": id};
51
+ }
52
+ return {testID: id};
53
+ };
54
+
55
+ /** Resolve compound field test ids with dot-suffix defaults. */
56
+ export const resolveFieldTestIDs = (
57
+ baseTestID: string | undefined,
58
+ testIDs?: FieldTestIDs
59
+ ): ResolvedFieldTestIDs => {
60
+ return {
61
+ error: testIDs?.error ?? resolveTestID(baseTestID, "error"),
62
+ helper: testIDs?.helper ?? resolveTestID(baseTestID, "helper"),
63
+ input: testIDs?.input ?? baseTestID,
64
+ label: testIDs?.label ?? resolveTestID(baseTestID, "label"),
65
+ };
66
+ };
67
+
68
+ /** Resolve field test ids from component props. */
69
+ export const resolveFieldTestIDsFromProps = (
70
+ props: WithTestID & {testIDs?: FieldTestIDs}
71
+ ): ResolvedFieldTestIDs => {
72
+ return resolveFieldTestIDs(props.testID, props.testIDs);
73
+ };
74
+
75
+ /** Resolve compound modal test ids with dot-suffix defaults. */
76
+ export const resolveModalTestIDs = (
77
+ baseTestID: string | undefined,
78
+ testIDs?: ModalTestIDs
79
+ ): ResolvedModalTestIDs => {
80
+ return {
81
+ dismiss: testIDs?.dismiss ?? resolveTestID(baseTestID, "dismiss"),
82
+ primaryButton: testIDs?.primaryButton ?? resolveTestID(baseTestID, "primary"),
83
+ root: testIDs?.root ?? baseTestID,
84
+ secondaryButton: testIDs?.secondaryButton ?? resolveTestID(baseTestID, "secondary"),
85
+ title: testIDs?.title ?? resolveTestID(baseTestID, "title"),
86
+ };
87
+ };
88
+
89
+ export const resolveModalTestIDsFromProps = (
90
+ props: WithTestID & {testIDs?: ModalTestIDs}
91
+ ): ResolvedModalTestIDs => {
92
+ return resolveModalTestIDs(props.testID, props.testIDs);
93
+ };
94
+
95
+ /** Resolve compound DataTable test ids with dot-suffix defaults. */
96
+ export const resolveDataTableTestIDs = (
97
+ baseTestID: string | undefined,
98
+ testIDs?: DataTableTestIDs
99
+ ): ResolvedDataTableTestIDs => {
100
+ return {
101
+ body: testIDs?.body ?? resolveTestID(baseTestID, "body"),
102
+ header: testIDs?.header ?? resolveTestID(baseTestID, "header"),
103
+ pagination: testIDs?.pagination ?? resolveTestID(baseTestID, "pagination"),
104
+ root: testIDs?.root ?? baseTestID,
105
+ row: testIDs?.row ?? resolveTestID(baseTestID, "row"),
106
+ };
107
+ };
108
+
109
+ export const resolveDataTableTestIDsFromProps = (
110
+ props: WithTestID & {testIDs?: DataTableTestIDs}
111
+ ): ResolvedDataTableTestIDs => {
112
+ return resolveDataTableTestIDs(props.testID, props.testIDs);
113
+ };
114
+
115
+ /** Row test id for DataTable — use with a stable row key, not row index alone. */
116
+ export const resolveDataTableRowTestID = (
117
+ rowTestIDBase: string | undefined,
118
+ rowKey: string | number
119
+ ): string | undefined => {
120
+ if (!rowTestIDBase) {
121
+ return undefined;
122
+ }
123
+ return `${rowTestIDBase}-${rowKey}`;
124
+ };
125
+
126
+ /** Resolve compound SegmentedControl test ids with dot-suffix defaults. */
127
+ export const resolveSegmentedControlTestIDs = (
128
+ baseTestID: string | undefined,
129
+ testIDs?: SegmentedControlTestIDs
130
+ ): ResolvedSegmentedControlTestIDs => {
131
+ return {
132
+ nextButton: testIDs?.nextButton ?? resolveTestID(baseTestID, "next"),
133
+ previousButton: testIDs?.previousButton ?? resolveTestID(baseTestID, "previous"),
134
+ root: testIDs?.root ?? baseTestID,
135
+ };
136
+ };
137
+
138
+ export const resolveSegmentedControlTestIDsFromProps = (
139
+ props: WithTestID & {testIDs?: SegmentedControlTestIDs}
140
+ ): ResolvedSegmentedControlTestIDs => {
141
+ return resolveSegmentedControlTestIDs(props.testID, props.testIDs);
142
+ };
@@ -0,0 +1,67 @@
1
+ /** Shared test id surface for @terreno/ui components. */
2
+ export interface WithTestID {
3
+ /** Root test id for the primary interactive element or container. */
4
+ testID?: string;
5
+ }
6
+
7
+ /** Sub-element test ids for compound form fields. */
8
+ export interface FieldTestIDs {
9
+ label?: string;
10
+ input?: string;
11
+ error?: string;
12
+ helper?: string;
13
+ }
14
+
15
+ /** Sub-element test ids for Modal. */
16
+ export interface ModalTestIDs {
17
+ root?: string;
18
+ title?: string;
19
+ primaryButton?: string;
20
+ secondaryButton?: string;
21
+ dismiss?: string;
22
+ }
23
+
24
+ /** Sub-element test ids for DataTable. */
25
+ export interface DataTableTestIDs {
26
+ root?: string;
27
+ header?: string;
28
+ body?: string;
29
+ row?: string;
30
+ pagination?: string;
31
+ }
32
+
33
+ /** Sub-element test ids for SegmentedControl. */
34
+ export interface SegmentedControlTestIDs {
35
+ root?: string;
36
+ previousButton?: string;
37
+ nextButton?: string;
38
+ }
39
+
40
+ export interface ResolvedFieldTestIDs {
41
+ label?: string;
42
+ input?: string;
43
+ error?: string;
44
+ helper?: string;
45
+ }
46
+
47
+ export interface ResolvedModalTestIDs {
48
+ root?: string;
49
+ title?: string;
50
+ primaryButton?: string;
51
+ secondaryButton?: string;
52
+ dismiss?: string;
53
+ }
54
+
55
+ export interface ResolvedDataTableTestIDs {
56
+ root?: string;
57
+ header?: string;
58
+ body?: string;
59
+ row?: string;
60
+ pagination?: string;
61
+ }
62
+
63
+ export interface ResolvedSegmentedControlTestIDs {
64
+ root?: string;
65
+ previousButton?: string;
66
+ nextButton?: string;
67
+ }