@madie/madie-design-system 1.2.62 → 2.0.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/.eslintrc.js +1 -1
- package/.storybook/.babelrc +2 -1
- package/.storybook/main.js +3 -11
- package/components/AutoComplete/AutoComplete.jsx +1 -1
- package/components/Button/Button.stories.js +0 -2
- package/components/DateField/DateField.jsx +1 -1
- package/components/DateField/DateField.stories.jsx +23 -10
- package/components/DateTimeField/DateTimeField.jsx +6 -2
- package/components/DateTimeField/DateTimeField.stories.jsx +29 -19
- package/components/Instant/Instant.stories.js +14 -6
- package/components/MadieAlert/MadieAlert.stories.js +35 -29
- package/components/MadieAlert/index.jsx +5 -5
- package/components/MadieConfirmDialog/MadieConfirmDialog.stories.js +17 -27
- package/components/MadieDeleteDialog/MadieDeleteDialog.stories.js +9 -18
- package/components/MadieDialog/MadieDialog.stories.js +45 -116
- package/components/MadieDialog/index.jsx +4 -2
- package/components/MadieDiscardDialog/MadieDiscardDialog.stories.js +5 -7
- package/components/MadieSpinner/MadieSpinner.stories.js +1 -3
- package/components/MadieTooltip/MadieTooltip.stories.js +7 -2
- package/components/Modal/Modal.stories.js +18 -89
- package/components/NotificationBanner/NotificationBanner.stories.js +17 -11
- package/components/NotificationBanner/index.js +3 -3
- package/components/NumberInput/NumberInput.stories.js +51 -63
- package/components/Popover/Popover.stories.js +6 -14
- package/components/Popover/index.js +2 -2
- package/components/RadioButton/RadioButton.jsx +4 -2
- package/components/RadioButton/RadioButton.stories.jsx +6 -2
- package/components/ReadOnlyTextField/ReadOnlyTextField.stories.js +4 -3
- package/components/ReadOnlyTextField/index.jsx +1 -1
- package/components/RichTextEditor/RichTextEditor.stories.js +10 -8
- package/components/RichTextEditor/index.jsx +14 -15
- package/components/Search/Search.stories.js +2 -4
- package/components/Select/Select.stories.js +59 -160
- package/components/Select/index.jsx +1 -1
- package/components/Tabs/Tabs.stories.js +78 -210
- package/components/TextArea/TextArea.stories.js +88 -108
- package/components/TextArea/index.jsx +1 -1
- package/components/TextField/TextField.stories.js +101 -124
- package/components/TextField/index.jsx +1 -1
- package/components/TimeField/TimeField.stories.js +18 -8
- package/components/Toast/Toast.stories.js +42 -102
- package/components/TruncateText/TruncateText.stories.js +22 -17
- package/components/hooks/useGetConfig.js +2 -2
- package/components/index.js +0 -24
- package/dist/browser.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.js +182 -51
- package/dist/react/index.js.LICENSE.txt +27 -24
- package/dist/react/index.js.map +1 -1
- package/eslint.config.js +56 -0
- package/index.js +7 -9
- package/package.json +43 -75
- package/test/components/Accordion.test.js +1 -1
- package/test/components/AutoComplete.test.js +11 -6
- package/test/components/Button.test.js +7 -3
- package/test/components/DateField.test.js +25 -29
- package/test/components/DateTimeField.test.js +21 -25
- package/test/components/Instant.test.js +1 -1
- package/test/components/MadieAlert.test.js +22 -22
- package/test/components/MadieConfirmDialog.test.js +42 -64
- package/test/components/MadieDeleteDialog.test.js +51 -69
- package/test/components/MadieDialog.test.js +13 -13
- package/test/components/MadieDiscardDialog.test.js +28 -45
- package/test/components/MadieSpinner.test.js +12 -17
- package/test/components/Modal.test.js +115 -0
- package/test/components/Pagination.test.js +2 -2
- package/test/components/RadioButton.test.js +7 -7
- package/test/components/ReadOnlyTextField.test.js +4 -2
- package/test/components/RichTextEditor.test.js +90 -6
- package/test/components/Search.test.js +75 -0
- package/test/components/Select.test.js +97 -107
- package/test/components/Tabs.test.js +22 -24
- package/test/components/TextArea.test.js +78 -92
- package/test/components/TextField.test.js +128 -147
- package/test/components/Toast.test.js +67 -78
- package/test/components/TruncateText.test.js +75 -0
- package/test/components/index.test.js +23 -0
- package/webpack.config.js +0 -1
- package/.eslintignore +0 -5
- package/components/Alert/Alert.stories.js +0 -70
- package/components/Alert/index.js +0 -55
- package/components/Breadcrumb/Breadcrumb.md +0 -28
- package/components/Breadcrumb/Breadcrumb.stories.js +0 -76
- package/components/Breadcrumb/index.js +0 -92
- package/components/CalloutBox/CalloutBox.stories.js +0 -94
- package/components/CalloutBox/index.js +0 -109
- package/components/Card/Card.stories.js +0 -163
- package/components/Card/index.js +0 -144
- package/components/Dropdown/Dropdown.stories.js +0 -94
- package/components/Dropdown/index.js +0 -85
- package/components/Error/Collapsible.jsx +0 -93
- package/components/Error/ErrorUI.jsx +0 -31
- package/components/Error/error.js +0 -26
- package/components/FlashNotification/FlashNotificationUI.jsx +0 -91
- package/components/FlashNotification/index.js +0 -30
- package/components/Footer/Footer.stories.js +0 -20
- package/components/Footer/FooterUI.jsx +0 -137
- package/components/Footer/LegacyFooterUI.jsx +0 -204
- package/components/Footer/SocialLinks.jsx +0 -63
- package/components/Footer/Subscribe.jsx +0 -34
- package/components/Footer/footer.js +0 -30
- package/components/Infotip/Infotip.jsx +0 -75
- package/components/Infotip/Infotip.stories.js +0 -52
- package/components/Infotip/InfotipIcon.jsx +0 -41
- package/components/Infotip/index.js +0 -3
- package/components/Link/Link.stories.js +0 -82
- package/components/Link/index.js +0 -61
- package/components/Spinner/index.js +0 -9
- package/components/TextInput/TextInput.stories.js +0 -118
- package/components/TextInput/index.js +0 -137
- package/components/Tooltip/Tooltip.jsx +0 -88
- package/components/Tooltip/Tooltip.stories.js +0 -80
- package/components/Tooltip/index.js +0 -3
- package/components/Tooltip/position.js +0 -76
- package/test/components/ErrorUI.test.js +0 -32
- package/test/components/FooterUI.test.js +0 -122
- package/test/components/Infotip.test.js +0 -76
- package/test/components/Tooltip.test.js +0 -147
|
@@ -1,55 +1,46 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { act } from "react";
|
|
2
2
|
import "@testing-library/jest-dom";
|
|
3
3
|
import { describe, expect, test } from "@jest/globals";
|
|
4
4
|
import TextField from "../../components/TextField/index";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
findByTestId,
|
|
8
|
-
render,
|
|
9
|
-
fireEvent,
|
|
10
|
-
screen,
|
|
11
|
-
} from "@testing-library/react";
|
|
5
|
+
import { render, fireEvent, screen, waitFor } from "@testing-library/react";
|
|
12
6
|
import userEvent from "@testing-library/user-event";
|
|
13
7
|
|
|
14
8
|
describe("TextField", () => {
|
|
9
|
+
const { findByTestId, getByTestId, findByText, getByText } = screen;
|
|
15
10
|
test("Textfield exists, and simulates input correctly", async () => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
userEvent.type(textNode, "newVal");
|
|
33
|
-
Simulate.change(textNode);
|
|
11
|
+
render(
|
|
12
|
+
<TextField
|
|
13
|
+
placeholder="test Name"
|
|
14
|
+
required
|
|
15
|
+
label="test Name"
|
|
16
|
+
id="testName"
|
|
17
|
+
inputProps={{ "data-testid": "test-name-input" }}
|
|
18
|
+
data-testid="test-name-text-field"
|
|
19
|
+
size="small"
|
|
20
|
+
/>,
|
|
21
|
+
);
|
|
22
|
+
expect(await findByTestId("test-name-text-field")).toBeInTheDocument();
|
|
23
|
+
const textNode = await getByTestId("test-name-input");
|
|
24
|
+
userEvent.type(textNode, "newVal");
|
|
25
|
+
fireEvent.change(textNode);
|
|
26
|
+
await waitFor(() => {
|
|
34
27
|
expect(textNode.value).toBe("newVal");
|
|
35
28
|
});
|
|
36
29
|
});
|
|
37
30
|
test("Textfield renders with helper text", async () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
expect(helperText).toBeInTheDocument();
|
|
52
|
-
});
|
|
31
|
+
render(
|
|
32
|
+
<TextField
|
|
33
|
+
placeholder="test Name"
|
|
34
|
+
helperText="helper text"
|
|
35
|
+
label="test Name"
|
|
36
|
+
id="testName"
|
|
37
|
+
inputProps={{ "data-testid": "test-name-input" }}
|
|
38
|
+
data-testid="test-name-text-field"
|
|
39
|
+
size="small"
|
|
40
|
+
/>,
|
|
41
|
+
);
|
|
42
|
+
const helperText = await findByText("helper text");
|
|
43
|
+
expect(helperText).toBeInTheDocument();
|
|
53
44
|
});
|
|
54
45
|
test("renders TextField for disabled mode", async () => {
|
|
55
46
|
render(
|
|
@@ -59,139 +50,129 @@ describe("TextField", () => {
|
|
|
59
50
|
helperText="helper text"
|
|
60
51
|
label="test Name"
|
|
61
52
|
id="testName"
|
|
62
|
-
inputProps={{"data-testid": "test-name-input"}}
|
|
53
|
+
inputProps={{ "data-testid": "test-name-input" }}
|
|
63
54
|
data-testid="test-name-text-field"
|
|
64
55
|
size="small"
|
|
65
56
|
value="test value"
|
|
66
|
-
|
|
57
|
+
/>,
|
|
67
58
|
);
|
|
68
59
|
const textField = await screen.findByRole("textbox");
|
|
69
60
|
expect(textField).toHaveTextContent("test value");
|
|
70
61
|
expect(textField).toHaveAttribute("readOnly");
|
|
71
62
|
});
|
|
72
63
|
test("HelperText renders errored", async () => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
expect(helperText).toBeInTheDocument();
|
|
88
|
-
});
|
|
64
|
+
const { findByText } = render(
|
|
65
|
+
<TextField
|
|
66
|
+
error
|
|
67
|
+
placeholder="test Name"
|
|
68
|
+
helperText="helper text"
|
|
69
|
+
label="test Name"
|
|
70
|
+
id="testName"
|
|
71
|
+
inputProps={{ "data-testid": "test-name-input" }}
|
|
72
|
+
data-testid="test-name-text-field"
|
|
73
|
+
size="small"
|
|
74
|
+
/>,
|
|
75
|
+
);
|
|
76
|
+
const helperText = await findByText("helper text");
|
|
77
|
+
expect(helperText).toBeInTheDocument();
|
|
89
78
|
});
|
|
90
79
|
|
|
91
80
|
test("tooltip text renders, can be seen and removed.", async () => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const tooltipTrigger = await findByTestId(
|
|
106
|
-
"testName-tooltip-button"
|
|
107
|
-
);
|
|
81
|
+
render(
|
|
82
|
+
<TextField
|
|
83
|
+
placeholder="test Name"
|
|
84
|
+
helperText="helper text"
|
|
85
|
+
label="test Name"
|
|
86
|
+
id="testName"
|
|
87
|
+
tooltipText="tooltip text"
|
|
88
|
+
inputProps={{ "data-testid": "test-name-input" }}
|
|
89
|
+
data-testid="test-name-text-field"
|
|
90
|
+
size="small"
|
|
91
|
+
/>,
|
|
92
|
+
);
|
|
93
|
+
const tooltipTrigger = await findByTestId("testName-tooltip-button");
|
|
108
94
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
95
|
+
// click and escape
|
|
96
|
+
act(() => {
|
|
97
|
+
fireEvent.click(tooltipTrigger);
|
|
98
|
+
});
|
|
99
|
+
expect(getByText("tooltip text")).toBeInTheDocument();
|
|
100
|
+
act(() => {
|
|
101
|
+
fireEvent.keyDown(getByText(/tooltip text/i), {
|
|
102
|
+
key: "Escape",
|
|
103
|
+
code: "Escape",
|
|
104
|
+
keyCode: 27,
|
|
105
|
+
charCode: 27,
|
|
121
106
|
});
|
|
122
|
-
|
|
107
|
+
});
|
|
108
|
+
expect(getByTestId("testName-tooltip")).toHaveClass("hidden");
|
|
123
109
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
110
|
+
// enter and leave
|
|
111
|
+
act(() => {
|
|
112
|
+
fireEvent.mouseEnter(getByTestId("testName-tooltip-button"));
|
|
113
|
+
});
|
|
114
|
+
expect(getByTestId("testName-tooltip")).not.toHaveClass("hidden");
|
|
115
|
+
act(() => {
|
|
116
|
+
fireEvent.mouseLeave(getByTestId("testName-tooltip-button"));
|
|
117
|
+
});
|
|
118
|
+
expect(getByTestId("testName-tooltip")).toHaveClass("hidden");
|
|
133
119
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
120
|
+
// focus, blur
|
|
121
|
+
act(() => {
|
|
122
|
+
fireEvent.focus(getByTestId("testName-tooltip-button"));
|
|
123
|
+
});
|
|
124
|
+
expect(getByTestId("testName-tooltip")).not.toHaveClass("hidden");
|
|
139
125
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
143
|
-
expect(getByTestId("testName-tooltip")).toHaveClass("hidden");
|
|
126
|
+
act(() => {
|
|
127
|
+
fireEvent.blur(getByTestId("testName-tooltip-button"));
|
|
144
128
|
});
|
|
129
|
+
expect(getByTestId("testName-tooltip")).toHaveClass("hidden");
|
|
145
130
|
});
|
|
146
131
|
|
|
147
132
|
test("Textfield has different color for label", async () => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
userEvent.type(textNode, "newVal");
|
|
167
|
-
Simulate.change(textNode);
|
|
133
|
+
render(
|
|
134
|
+
<TextField
|
|
135
|
+
placeholder="test Name"
|
|
136
|
+
required
|
|
137
|
+
label="test Name"
|
|
138
|
+
labelColor={"#1976d2"}
|
|
139
|
+
id="testName"
|
|
140
|
+
inputProps={{ "data-testid": "test-name-input" }}
|
|
141
|
+
data-testid="test-name-text-field"
|
|
142
|
+
size="small"
|
|
143
|
+
/>,
|
|
144
|
+
);
|
|
145
|
+
screen.debug(undefined, 60000);
|
|
146
|
+
expect(await findByTestId("test-name-text-field")).toBeInTheDocument();
|
|
147
|
+
const textNode = await getByTestId("test-name-input");
|
|
148
|
+
userEvent.type(textNode, "newVal");
|
|
149
|
+
fireEvent.change(textNode);
|
|
150
|
+
await waitFor(() => {
|
|
168
151
|
expect(textNode.value).toBe("newVal");
|
|
169
152
|
});
|
|
170
153
|
});
|
|
171
154
|
|
|
172
155
|
test("Max Length renders", async () => {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
userEvent.type(textNode, "newVal");
|
|
191
|
-
Simulate.change(textNode);
|
|
156
|
+
render(
|
|
157
|
+
<TextField
|
|
158
|
+
placeholder="test Name"
|
|
159
|
+
required
|
|
160
|
+
label="test Name"
|
|
161
|
+
id="testName"
|
|
162
|
+
inputProps={{ "data-testid": "test-name-input" }}
|
|
163
|
+
data-testid="test-name-text-field"
|
|
164
|
+
size="small"
|
|
165
|
+
maxLength={10}
|
|
166
|
+
/>,
|
|
167
|
+
);
|
|
168
|
+
expect(await findByTestId("test-name-text-field")).toBeInTheDocument();
|
|
169
|
+
const textNode = await getByTestId("test-name-input");
|
|
170
|
+
userEvent.type(textNode, "newVal");
|
|
171
|
+
fireEvent.change(textNode);
|
|
172
|
+
await waitFor(() => {
|
|
192
173
|
expect(textNode.value).toBe("newVal");
|
|
193
|
-
const maxLength = await findByText("/10 Characters");
|
|
194
|
-
expect(maxLength).toBeInTheDocument();
|
|
195
174
|
});
|
|
175
|
+
const maxLength = await findByText("/10 Characters");
|
|
176
|
+
expect(maxLength).toBeInTheDocument();
|
|
196
177
|
});
|
|
197
178
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import "@testing-library/jest-dom";
|
|
2
2
|
import { describe, expect, test } from "@jest/globals";
|
|
3
3
|
import Toast from "../../components/Toast/index";
|
|
4
|
-
import {
|
|
5
|
-
import { render, fireEvent, waitFor } from "@testing-library/react";
|
|
4
|
+
import { render, fireEvent, waitFor, screen } from "@testing-library/react";
|
|
6
5
|
|
|
7
6
|
import React, { useState } from "react";
|
|
8
7
|
|
|
@@ -20,105 +19,95 @@ const ToastTester = (toastProps) => {
|
|
|
20
19
|
open={toastOpen}
|
|
21
20
|
onClose={() => setToastOpen(false)}
|
|
22
21
|
{...toastProps}
|
|
22
|
+
autoHideDuration={500}
|
|
23
23
|
/>
|
|
24
24
|
</div>
|
|
25
25
|
);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
describe("Toast", () => {
|
|
29
|
+
const { getByTestId, findByTestId, queryByText } = screen;
|
|
29
30
|
test("Danger toast renders correctly and disappears", async () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
).not.toBeVisible();
|
|
48
|
-
});
|
|
31
|
+
render(
|
|
32
|
+
<ToastTester
|
|
33
|
+
toastKey="toast-key"
|
|
34
|
+
testId="danger-toast"
|
|
35
|
+
toastType="danger"
|
|
36
|
+
autoHideDuration={1000}
|
|
37
|
+
message="Something has gone wrong. Please try again"
|
|
38
|
+
/>,
|
|
39
|
+
);
|
|
40
|
+
const result = await findByTestId("toast-tester");
|
|
41
|
+
fireEvent.click(result);
|
|
42
|
+
const dangerToast = await getByTestId("danger-toast");
|
|
43
|
+
expect(dangerToast).toBeInTheDocument();
|
|
44
|
+
await waitFor(() => {
|
|
45
|
+
expect(
|
|
46
|
+
queryByText("Something has gone wrong. Please try again"),
|
|
47
|
+
).not.toBeVisible();
|
|
49
48
|
});
|
|
50
49
|
});
|
|
51
50
|
|
|
52
51
|
test("Success toast renders correctly and disappears", async () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
expect(
|
|
69
|
-
queryByText("Something has completed")
|
|
70
|
-
).not.toBeVisible();
|
|
71
|
-
});
|
|
52
|
+
render(
|
|
53
|
+
<ToastTester
|
|
54
|
+
toastKey="toast-key"
|
|
55
|
+
testId="success-toast"
|
|
56
|
+
toastType="success"
|
|
57
|
+
autoHideDuration={1000}
|
|
58
|
+
message="Something has completed"
|
|
59
|
+
/>,
|
|
60
|
+
);
|
|
61
|
+
const result = await findByTestId("toast-tester");
|
|
62
|
+
fireEvent.click(result);
|
|
63
|
+
const dangerToast = await getByTestId("success-toast");
|
|
64
|
+
expect(dangerToast).toBeInTheDocument();
|
|
65
|
+
await waitFor(() => {
|
|
66
|
+
expect(queryByText("Something has completed")).not.toBeVisible();
|
|
72
67
|
});
|
|
73
68
|
});
|
|
74
69
|
|
|
75
70
|
test("Info toast renders correctly and disappears", async () => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
expect(
|
|
92
|
-
queryByText("Something has completed")
|
|
93
|
-
).not.toBeVisible();
|
|
94
|
-
});
|
|
71
|
+
render(
|
|
72
|
+
<ToastTester
|
|
73
|
+
toastKey="toast-key"
|
|
74
|
+
testId="info-toast"
|
|
75
|
+
toastType="info"
|
|
76
|
+
autoHideDuration={1000}
|
|
77
|
+
message="Something has completed"
|
|
78
|
+
/>,
|
|
79
|
+
);
|
|
80
|
+
const result = await findByTestId("toast-tester");
|
|
81
|
+
fireEvent.click(result);
|
|
82
|
+
const dangerToast = await getByTestId("info-toast");
|
|
83
|
+
expect(dangerToast).toBeInTheDocument();
|
|
84
|
+
await waitFor(() => {
|
|
85
|
+
expect(queryByText("Something has completed")).not.toBeVisible();
|
|
95
86
|
});
|
|
96
87
|
});
|
|
97
88
|
|
|
98
89
|
test("Warning toast renders correctly and disappears", async () => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
expect(queryByText("Something went wrong")).not.toBeVisible();
|
|
115
|
-
});
|
|
90
|
+
render(
|
|
91
|
+
<ToastTester
|
|
92
|
+
toastKey="toast-key"
|
|
93
|
+
testId="warning-toast"
|
|
94
|
+
toastType="warning"
|
|
95
|
+
autoHideDuration={1000}
|
|
96
|
+
message="Something went wrong"
|
|
97
|
+
/>,
|
|
98
|
+
);
|
|
99
|
+
const result = await findByTestId("toast-tester");
|
|
100
|
+
fireEvent.click(result);
|
|
101
|
+
const dangerToast = await getByTestId("warning-toast");
|
|
102
|
+
expect(dangerToast).toBeInTheDocument();
|
|
103
|
+
await waitFor(() => {
|
|
104
|
+
expect(queryByText("Something went wrong")).not.toBeVisible();
|
|
116
105
|
});
|
|
117
106
|
});
|
|
118
107
|
|
|
119
108
|
it("It renders as expected with basic props and triggers on Close on click", async () => {
|
|
120
109
|
const onClose = jest.fn();
|
|
121
|
-
|
|
110
|
+
render(
|
|
122
111
|
<Toast
|
|
123
112
|
testId="test-toast"
|
|
124
113
|
message="Something went wrong"
|
|
@@ -126,7 +115,7 @@ describe("Toast", () => {
|
|
|
126
115
|
closeButtonProps={{
|
|
127
116
|
"data-testid": "close-button",
|
|
128
117
|
}}
|
|
129
|
-
|
|
118
|
+
/>,
|
|
130
119
|
);
|
|
131
120
|
|
|
132
121
|
expect(getByTestId("test-toast")).toBeInTheDocument();
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
3
|
+
import { TruncateText } from "../../components";
|
|
4
|
+
|
|
5
|
+
describe("TruncateText", () => {
|
|
6
|
+
const longText =
|
|
7
|
+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
|
|
8
|
+
"Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
|
|
9
|
+
|
|
10
|
+
const shortText = "Short text";
|
|
11
|
+
|
|
12
|
+
it("returns null when text is empty", () => {
|
|
13
|
+
const { container } = render(
|
|
14
|
+
<TruncateText text="" dataTestId="test" />,
|
|
15
|
+
);
|
|
16
|
+
expect(container.firstChild).toBeNull();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("returns null when text is only whitespace", () => {
|
|
20
|
+
const { container } = render(
|
|
21
|
+
<TruncateText text=" " dataTestId="test" />,
|
|
22
|
+
);
|
|
23
|
+
expect(container.firstChild).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("renders full text when shorter than maxLength", () => {
|
|
27
|
+
render(
|
|
28
|
+
<TruncateText text={shortText} maxLength={20} dataTestId="test" />,
|
|
29
|
+
);
|
|
30
|
+
expect(screen.getByTestId("test-content")).toHaveTextContent(shortText);
|
|
31
|
+
expect(screen.queryByTestId("test-toggle-button")).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("renders truncated text and handles on click", () => {
|
|
35
|
+
render(
|
|
36
|
+
<TruncateText text={longText} maxLength={20} dataTestId="test" />,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const content = screen.getByTestId("test-content");
|
|
40
|
+
expect(content).toBeInTheDocument();
|
|
41
|
+
expect(content).toHaveTextContent(longText.slice(0, 20));
|
|
42
|
+
|
|
43
|
+
const toggleBtn = screen.getByTestId("test-toggle-button");
|
|
44
|
+
expect(toggleBtn).toBeInTheDocument();
|
|
45
|
+
expect(toggleBtn).toHaveTextContent("Show more");
|
|
46
|
+
|
|
47
|
+
fireEvent.click(toggleBtn);
|
|
48
|
+
|
|
49
|
+
expect(screen.getByTestId("test-content")).toHaveTextContent(longText);
|
|
50
|
+
expect(screen.getByTestId("test-toggle-button")).toHaveTextContent(
|
|
51
|
+
"Show less",
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
fireEvent.click(toggleBtn);
|
|
55
|
+
|
|
56
|
+
expect(screen.getByTestId("test-content")).toHaveTextContent(
|
|
57
|
+
longText.slice(0, 20),
|
|
58
|
+
);
|
|
59
|
+
expect(screen.getByTestId("test-toggle-button")).toHaveTextContent(
|
|
60
|
+
"Show more",
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("applies custom fontSize", () => {
|
|
65
|
+
render(
|
|
66
|
+
<TruncateText
|
|
67
|
+
text={shortText}
|
|
68
|
+
dataTestId="font-test"
|
|
69
|
+
fontSize="2rem"
|
|
70
|
+
/>,
|
|
71
|
+
);
|
|
72
|
+
const content = screen.getByTestId("font-test-content");
|
|
73
|
+
expect(content).toHaveStyle("font-size: 2rem");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import "@testing-library/jest-dom";
|
|
3
|
+
import { describe, expect } from "@jest/globals";
|
|
4
|
+
import { render, screen } from "@testing-library/react";
|
|
5
|
+
import QppStyleComponents from "../../index";
|
|
6
|
+
|
|
7
|
+
describe("QppStyleComponents. Should be unused it's not hosted and meant only to be used with storybook.", () => {
|
|
8
|
+
describe("errorPage", () => {
|
|
9
|
+
it("renders the error page with the correct text and test ID", () => {
|
|
10
|
+
const Wrapper = () => QppStyleComponents.errorPage({});
|
|
11
|
+
render(<Wrapper />);
|
|
12
|
+
expect(screen.getByTestId("error-page")).toBeInTheDocument();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe("footer", () => {
|
|
17
|
+
it("renders the unused footer div with the correct test ID", () => {
|
|
18
|
+
render(QppStyleComponents.footer());
|
|
19
|
+
const footer = screen.getByTestId("unused");
|
|
20
|
+
expect(footer).toBeInTheDocument();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
package/webpack.config.js
CHANGED
|
@@ -2,7 +2,6 @@ const path = require("path");
|
|
|
2
2
|
const webpack = require("webpack");
|
|
3
3
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
4
4
|
const TerserPlugin = require("terser-webpack-plugin");
|
|
5
|
-
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
|
6
5
|
|
|
7
6
|
const pkg = require("./package.json");
|
|
8
7
|
const entry = ["./index.js"];
|