ferns-ui 1.9.1 → 1.11.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/dist/Accordion.js +1 -1
- package/dist/Accordion.js.map +1 -1
- package/dist/Accordion.test.d.ts +1 -0
- package/dist/Accordion.test.js +71 -0
- package/dist/Accordion.test.js.map +1 -0
- package/dist/AddressField.test.d.ts +1 -0
- package/dist/AddressField.test.js +65 -0
- package/dist/AddressField.test.js.map +1 -0
- package/dist/Avatar.js +2 -2
- package/dist/Avatar.js.map +1 -1
- package/dist/Avatar.test.d.ts +1 -0
- package/dist/Avatar.test.js +131 -0
- package/dist/Avatar.test.js.map +1 -0
- package/dist/Badge.d.ts +1 -1
- package/dist/Badge.js +3 -3
- package/dist/Badge.js.map +1 -1
- package/dist/Badge.test.d.ts +1 -0
- package/dist/Badge.test.js +76 -0
- package/dist/Badge.test.js.map +1 -0
- package/dist/Box.test.d.ts +1 -0
- package/dist/Box.test.js +528 -0
- package/dist/Box.test.js.map +1 -0
- package/dist/Common.d.ts +100 -1
- package/dist/Common.js.map +1 -1
- package/dist/DateTimeField.js +15 -2
- package/dist/DateTimeField.js.map +1 -1
- package/dist/InfoModalIcon.js +1 -1
- package/dist/InfoModalIcon.js.map +1 -1
- package/dist/SectionDivider.d.ts +2 -0
- package/dist/SectionDivider.js +12 -0
- package/dist/SectionDivider.js.map +1 -0
- package/dist/Slider.d.ts +3 -0
- package/dist/Slider.js +94 -0
- package/dist/Slider.js.map +1 -0
- package/dist/Text.js +2 -0
- package/dist/Text.js.map +1 -1
- package/dist/TextField.test.js +9 -9
- package/dist/TextField.test.js.map +1 -1
- package/dist/Tooltip.js +2 -0
- package/dist/Tooltip.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/setupTests.js +40 -2
- package/dist/setupTests.js.map +1 -1
- package/dist/test-utils.js.map +1 -1
- package/package.json +2 -1
- package/src/Accordion.test.tsx +104 -0
- package/src/Accordion.tsx +1 -0
- package/src/AddressField.test.tsx +89 -0
- package/src/Avatar.test.tsx +163 -0
- package/src/Avatar.tsx +2 -0
- package/src/Badge.test.tsx +116 -0
- package/src/Badge.tsx +3 -1
- package/src/Box.test.tsx +665 -0
- package/src/Common.ts +114 -1
- package/src/DateTimeField.tsx +15 -2
- package/src/InfoModalIcon.tsx +1 -0
- package/src/SectionDivider.tsx +18 -0
- package/src/Slider.tsx +205 -0
- package/src/Text.tsx +2 -0
- package/src/TextField.test.tsx +59 -71
- package/src/Tooltip.tsx +2 -0
- package/src/__snapshots__/Accordion.test.tsx.snap +120 -0
- package/src/__snapshots__/AddressField.test.tsx.snap +464 -0
- package/src/__snapshots__/Avatar.test.tsx.snap +78 -0
- package/src/__snapshots__/Badge.test.tsx.snap +44 -0
- package/src/__snapshots__/Box.test.tsx.snap +159 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +12 -0
- package/src/__snapshots__/TextField.test.tsx.snap +38 -1
- package/src/index.tsx +2 -0
- package/src/setupTests.ts +45 -2
- package/src/test-utils.tsx +1 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import {Badge} from "./Badge";
|
|
4
|
+
import {renderWithTheme} from "./test-utils";
|
|
5
|
+
|
|
6
|
+
describe("Badge", () => {
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
value: "Test",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
it("renders correctly with default props", () => {
|
|
12
|
+
const {toJSON} = renderWithTheme(<Badge {...defaultProps} />);
|
|
13
|
+
expect(toJSON()).toMatchSnapshot();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("renders text value correctly", () => {
|
|
17
|
+
const {getByText} = renderWithTheme(<Badge {...defaultProps} />);
|
|
18
|
+
expect(getByText("Test")).toBeTruthy();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("renders number value correctly", () => {
|
|
22
|
+
const {getByText} = renderWithTheme(<Badge value={42} />);
|
|
23
|
+
expect(getByText("42")).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("truncates large numbers with maxValue", () => {
|
|
27
|
+
const {getByText} = renderWithTheme(<Badge maxValue={100} value={150} variant="numberOnly" />);
|
|
28
|
+
expect(getByText("100+")).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("does not truncate numbers below maxValue", () => {
|
|
32
|
+
const {getByText} = renderWithTheme(<Badge maxValue={100} value={50} variant="numberOnly" />);
|
|
33
|
+
expect(getByText("50")).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("applies correct status colors", () => {
|
|
37
|
+
const statuses = ["error", "warning", "info", "success", "neutral"] as const;
|
|
38
|
+
|
|
39
|
+
statuses.forEach((status) => {
|
|
40
|
+
let {getByTestId} = renderWithTheme(
|
|
41
|
+
<Badge {...defaultProps} status={status} testID="badge" />
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Test primary variant
|
|
45
|
+
const badge = getByTestId("badge");
|
|
46
|
+
expect(badge).toHaveStyle({backgroundColor: expect.any(String)});
|
|
47
|
+
|
|
48
|
+
// Test secondary variant
|
|
49
|
+
({getByTestId} = renderWithTheme(
|
|
50
|
+
<Badge {...defaultProps} secondary status={status} testID="badge-secondary" />
|
|
51
|
+
));
|
|
52
|
+
const secondaryBadge = getByTestId("badge-secondary");
|
|
53
|
+
expect(secondaryBadge).toHaveStyle({backgroundColor: expect.any(String)});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("renders icon when iconName is provided", () => {
|
|
58
|
+
const {getByTestId} = renderWithTheme(
|
|
59
|
+
<Badge {...defaultProps} iconName="check" testID="badge-with-icon" />
|
|
60
|
+
);
|
|
61
|
+
expect(getByTestId("icon")).toBeTruthy();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("renders icon only when variant is iconOnly", () => {
|
|
65
|
+
const {getByTestId, queryByText} = renderWithTheme(
|
|
66
|
+
<Badge {...defaultProps} iconName="check" testID="icon-only-badge" variant="iconOnly" />
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(getByTestId("icon")).toBeTruthy();
|
|
70
|
+
expect(queryByText("Test")).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("applies custom colors when status is custom", () => {
|
|
74
|
+
const customColors = {
|
|
75
|
+
customBackgroundColor: "#123456",
|
|
76
|
+
customTextColor: "#ffffff",
|
|
77
|
+
customBorderColor: "#654321",
|
|
78
|
+
customIconColor: "#ffcc00",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const {getByTestId} = renderWithTheme(
|
|
82
|
+
<Badge
|
|
83
|
+
{...defaultProps}
|
|
84
|
+
iconName="star"
|
|
85
|
+
secondary
|
|
86
|
+
status="custom"
|
|
87
|
+
testID="custom-badge"
|
|
88
|
+
{...(customColors as any)}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const badge = getByTestId("custom-badge");
|
|
93
|
+
expect(badge).toHaveStyle({
|
|
94
|
+
backgroundColor: customColors.customBackgroundColor,
|
|
95
|
+
borderColor: customColors.customBorderColor,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("applies correct border radius based on variant", () => {
|
|
100
|
+
// Default variant
|
|
101
|
+
let {getByTestId} = renderWithTheme(<Badge {...defaultProps} testID="default-badge" />);
|
|
102
|
+
expect(getByTestId("default-badge")).toHaveStyle({borderRadius: expect.any(Number)});
|
|
103
|
+
|
|
104
|
+
// Icon only variant
|
|
105
|
+
({getByTestId} = renderWithTheme(
|
|
106
|
+
<Badge {...defaultProps} iconName="check" testID="icon-only-badge" variant="iconOnly" />
|
|
107
|
+
));
|
|
108
|
+
expect(getByTestId("icon-only-badge")).toHaveStyle({borderRadius: expect.any(Number)});
|
|
109
|
+
|
|
110
|
+
// Number only variant
|
|
111
|
+
({getByTestId} = renderWithTheme(
|
|
112
|
+
<Badge {...defaultProps} testID="number-only-badge" variant="numberOnly" />
|
|
113
|
+
));
|
|
114
|
+
expect(getByTestId("number-only-badge")).toHaveStyle({borderRadius: expect.any(Number)});
|
|
115
|
+
});
|
|
116
|
+
});
|
package/src/Badge.tsx
CHANGED
|
@@ -17,6 +17,7 @@ export const Badge = ({
|
|
|
17
17
|
customBorderColor,
|
|
18
18
|
customIconColor,
|
|
19
19
|
customIconName,
|
|
20
|
+
testID,
|
|
20
21
|
}: BadgeProps): React.ReactElement => {
|
|
21
22
|
const {theme} = useTheme();
|
|
22
23
|
const isIconOnly = variant === "iconOnly";
|
|
@@ -110,9 +111,10 @@ export const Badge = ({
|
|
|
110
111
|
isIconOnly && {height: 16, width: 16},
|
|
111
112
|
secondary && {borderWidth: 1, borderColor},
|
|
112
113
|
]}
|
|
114
|
+
testID={testID}
|
|
113
115
|
>
|
|
114
116
|
{Boolean(variant !== "numberOnly" && iconName) && (
|
|
115
|
-
<View style={{marginRight: variant === "iconOnly" ? 0 : theme.spacing.sm}}>
|
|
117
|
+
<View style={{marginRight: variant === "iconOnly" ? 0 : theme.spacing.sm}} testID="icon">
|
|
116
118
|
<Icon color={iconColor} iconName={customIconName ?? iconName!} size="xs" />
|
|
117
119
|
</View>
|
|
118
120
|
)}
|