@bigbinary/neetoui 3.2.75 → 3.2.78
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/.circleci/config.yml +8 -2
- package/formik.js +1 -1
- package/index.js +1 -1
- package/layouts.js +1 -1
- package/package.json +1 -1
- package/tests/ColorPicker.test.js +117 -0
- package/tests/EmailInput.test.js +1 -1
- package/tests/Switch.test.js +61 -0
- package/tests/Tab.test.js +60 -0
- package/tests/Toastr.test.js +217 -0
- package/tests/Tooltip.test.js +44 -0
package/package.json
CHANGED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
3
|
+
import { ColorPicker } from "../lib/components";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("ColorPicker", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
render(<ColorPicker color="#ffffff" />);
|
|
9
|
+
expect(screen.getByText("#ffffff")).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should trigger onChange when color is changed", () => {
|
|
13
|
+
const hex = "#000000";
|
|
14
|
+
const hsl = { a: 1, h: 0, l: 0, s: 0 };
|
|
15
|
+
const hsv = { a: 1, h: 0, v: 0, s: 0 };
|
|
16
|
+
const rgb = { a: 1, b: 0, g: 0, r: 0 };
|
|
17
|
+
const onChange = jest.fn((color) => {
|
|
18
|
+
expect(color.hex).toEqual(hex);
|
|
19
|
+
expect(color.hsl).toEqual(hsl);
|
|
20
|
+
expect(color.hsv).toEqual(hsv);
|
|
21
|
+
expect(color.rgb).toEqual(rgb);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
render(<ColorPicker color="#ffffff" onChange={onChange} />);
|
|
25
|
+
userEvent.click(screen.getByText("#ffffff"));
|
|
26
|
+
userEvent.paste(screen.getByRole("textbox"), "000000");
|
|
27
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should display color palette when colorPaletteProps is provided", () => {
|
|
31
|
+
render(<ColorPicker color="#ffffff" colorPaletteProps={{}} />);
|
|
32
|
+
userEvent.click(screen.getByText("#ffffff"));
|
|
33
|
+
expect(screen.getByTestId("color-palette")).toBeInTheDocument();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should trigger onChange when a color is selected from palette", () => {
|
|
37
|
+
const selectedColor = "#ffffff";
|
|
38
|
+
const DEFAULT_COLORS = {
|
|
39
|
+
"red-500": "#f56a58",
|
|
40
|
+
"yellow-500": "#f3cd82",
|
|
41
|
+
"green-500": "#00ba88",
|
|
42
|
+
"blue-500": "#276ef1",
|
|
43
|
+
};
|
|
44
|
+
const onChange = jest.fn();
|
|
45
|
+
render(
|
|
46
|
+
<ColorPicker
|
|
47
|
+
color={selectedColor}
|
|
48
|
+
colorPaletteProps={{
|
|
49
|
+
color: {
|
|
50
|
+
from: "red-500",
|
|
51
|
+
to: "red-500",
|
|
52
|
+
},
|
|
53
|
+
colorList: Object.keys(DEFAULT_COLORS).map((key) => ({
|
|
54
|
+
from: key,
|
|
55
|
+
to: key,
|
|
56
|
+
})),
|
|
57
|
+
onChange,
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
userEvent.click(screen.getByText("#ffffff"));
|
|
62
|
+
const paletteItems = screen.getAllByTestId("color-palette-item");
|
|
63
|
+
userEvent.click(paletteItems[0]);
|
|
64
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
65
|
+
expect(onChange).toHaveBeenCalledWith("red-500", "red-500");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should call onChange when user touches Heu slider", () => {
|
|
69
|
+
const touchStart = [{ pageX: 0, pageY: 0 }];
|
|
70
|
+
|
|
71
|
+
const hex = "#000000";
|
|
72
|
+
const hsl = { a: 1, h: 0, l: 0, s: 0 };
|
|
73
|
+
const hsv = { a: 1, h: 0, v: 0, s: 0 };
|
|
74
|
+
const rgb = { a: 1, b: 0, g: 0, r: 0 };
|
|
75
|
+
const onChange = jest.fn((color) => {
|
|
76
|
+
expect(color.hex).toEqual(hex);
|
|
77
|
+
expect(color.hsl).toEqual(hsl);
|
|
78
|
+
expect(color.hsv).toEqual(hsv);
|
|
79
|
+
expect(color.rgb).toEqual(rgb);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
render(<ColorPicker color="#ffffff" onChange={onChange} />);
|
|
83
|
+
userEvent.click(screen.getByText("#ffffff"));
|
|
84
|
+
|
|
85
|
+
fireEvent.touchStart(
|
|
86
|
+
screen.getByTestId("color-picker-hue").querySelector(".hue-horizontal"),
|
|
87
|
+
{ touches: touchStart }
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should call onChange when user touches Saturation selector", () => {
|
|
94
|
+
const touchStart = [{ pageX: 0, pageY: 0 }];
|
|
95
|
+
|
|
96
|
+
const hex = "#000000";
|
|
97
|
+
const hsl = { a: 1, h: 0, l: 0, s: 0 };
|
|
98
|
+
const hsv = { a: 1, h: 0, v: 0, s: 0 };
|
|
99
|
+
const rgb = { a: 1, b: 0, g: 0, r: 0 };
|
|
100
|
+
const onChange = jest.fn((color) => {
|
|
101
|
+
expect(color.hex).toEqual(hex);
|
|
102
|
+
expect(color.hsl).toEqual(hsl);
|
|
103
|
+
expect(color.hsv).toEqual(hsv);
|
|
104
|
+
expect(color.rgb).toEqual(rgb);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
render(<ColorPicker color="#ffffff" onChange={onChange} />);
|
|
108
|
+
userEvent.click(screen.getByText("#ffffff"));
|
|
109
|
+
|
|
110
|
+
fireEvent.touchStart(
|
|
111
|
+
screen.getByTestId("color-picker-saturation").querySelector(".saturation-black"),
|
|
112
|
+
{ touches: touchStart }
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
116
|
+
});
|
|
117
|
+
});
|
package/tests/EmailInput.test.js
CHANGED
|
@@ -157,7 +157,7 @@ describe("EmailInput", () => {
|
|
|
157
157
|
{ label: "test@example.com", value: "test@example.com", valid: true },
|
|
158
158
|
{ label: "invalidEmail", value: "invalidEmail" },
|
|
159
159
|
]}
|
|
160
|
-
filterInvalidEmails
|
|
160
|
+
filterInvalidEmails={{}}
|
|
161
161
|
error="Invalid email"
|
|
162
162
|
/>
|
|
163
163
|
);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Switch } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("Switch", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
const { getByRole } = render(<Switch />);
|
|
9
|
+
const switchButton = getByRole("checkbox");
|
|
10
|
+
expect(switchButton).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should be unchecked by default", () => {
|
|
14
|
+
const { getByRole } = render(<Switch />);
|
|
15
|
+
const switchButton = getByRole("checkbox");
|
|
16
|
+
expect(switchButton).not.toBeChecked();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should be checked on clicking the checkbox", () => {
|
|
20
|
+
const { getByRole } = render(<Switch />);
|
|
21
|
+
const switchButton = getByRole("checkbox");
|
|
22
|
+
userEvent.click(switchButton);
|
|
23
|
+
expect(switchButton).toBeChecked();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should render label", () => {
|
|
27
|
+
const { getByText } = render(<Switch label="Switch" />);
|
|
28
|
+
const label = getByText("Switch");
|
|
29
|
+
expect(label).toBeInTheDocument();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should render asterisk when required is set to true", () => {
|
|
33
|
+
const { getByText } = render(<Switch required label="Switch" />);
|
|
34
|
+
const asterisk = getByText("*");
|
|
35
|
+
expect(asterisk).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should display error message", () => {
|
|
39
|
+
const { getByText } = render(<Switch error="Error message" />);
|
|
40
|
+
const errorMessage = getByText("Error message");
|
|
41
|
+
expect(errorMessage).toBeInTheDocument();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should be disabled if disabled is true", () => {
|
|
45
|
+
const { getByRole } = render(<Switch disabled />);
|
|
46
|
+
const switchButton = getByRole("checkbox");
|
|
47
|
+
expect(switchButton).toBeDisabled();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should render check icon icon when checked is true", () => {
|
|
51
|
+
const { getByTestId } = render(<Switch checked />);
|
|
52
|
+
const checkIcon = getByTestId("check-icon");
|
|
53
|
+
expect(checkIcon).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should render close icon icon when checked is false", () => {
|
|
57
|
+
const { getByTestId } = render(<Switch checked={false} />);
|
|
58
|
+
const closeIcon = getByTestId("close-icon");
|
|
59
|
+
expect(closeIcon).toBeInTheDocument();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { Tab } from "../lib/components";
|
|
5
|
+
import { BrowserRouter } from "react-router-dom";
|
|
6
|
+
|
|
7
|
+
describe("Tab", () => {
|
|
8
|
+
it("should render without error", () => {
|
|
9
|
+
render(
|
|
10
|
+
<Tab>
|
|
11
|
+
<Tab.Item>Tab 1</Tab.Item>
|
|
12
|
+
<Tab.Item>Tab 2</Tab.Item>
|
|
13
|
+
</Tab>
|
|
14
|
+
);
|
|
15
|
+
expect(screen.getByText("Tab 1")).toBeInTheDocument();
|
|
16
|
+
expect(screen.getByText("Tab 2")).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should render a link when activeClassName is provided", () => {
|
|
20
|
+
render(<BrowserRouter>
|
|
21
|
+
<Tab>
|
|
22
|
+
<Tab.Item activeClassName="active" to="/route">Tab 1</Tab.Item>
|
|
23
|
+
<Tab.Item>Tab 2</Tab.Item>
|
|
24
|
+
</Tab>
|
|
25
|
+
</BrowserRouter>);
|
|
26
|
+
expect(screen.getByRole("link")).toBeInTheDocument();
|
|
27
|
+
expect(screen.getByRole("link")).toHaveAttribute("href", "/route");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should render icon when provided", () => {
|
|
31
|
+
render(<Tab>
|
|
32
|
+
<Tab.Item icon={() => <svg data-testid="svg-icon" />}>Tab 1</Tab.Item>
|
|
33
|
+
</Tab>);
|
|
34
|
+
expect(screen.getByTestId("svg-icon")).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should render icon when icon className is provided", () => {
|
|
38
|
+
render(<Tab>
|
|
39
|
+
<Tab.Item icon="icon">Tab 1</Tab.Item>
|
|
40
|
+
</Tab>);
|
|
41
|
+
expect(screen.getByTestId("tab-icon")).toBeInTheDocument();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should call onClick when clicked on Tab", () => {
|
|
45
|
+
const onClick = jest.fn();
|
|
46
|
+
render(<Tab>
|
|
47
|
+
<Tab.Item icon="icon" onClick={onClick}>Tab 1</Tab.Item>
|
|
48
|
+
</Tab>);
|
|
49
|
+
userEvent.click(screen.getByText("Tab 1"));
|
|
50
|
+
expect(onClick).toHaveBeenCalled();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should make the tab active when active prop is true", () => {
|
|
54
|
+
render(<Tab>
|
|
55
|
+
<Tab.Item active>Tab 1</Tab.Item>
|
|
56
|
+
<Tab.Item>Tab 2</Tab.Item>
|
|
57
|
+
</Tab>);
|
|
58
|
+
expect(screen.getByText("Tab 1")).toHaveClass("active");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Toastr, Button } from "../lib/components";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import { ToastContainer } from "react-toastify";
|
|
6
|
+
|
|
7
|
+
describe("Toastr", () => {
|
|
8
|
+
it("should render Info Toastr without error", async () => {
|
|
9
|
+
render(
|
|
10
|
+
<>
|
|
11
|
+
<ToastContainer/>
|
|
12
|
+
<Button
|
|
13
|
+
label="Info Toastr"
|
|
14
|
+
onClick={() => Toastr.info("This is an info toastr.")}
|
|
15
|
+
/>
|
|
16
|
+
</>
|
|
17
|
+
);
|
|
18
|
+
const button = screen.getByText("Info Toastr");
|
|
19
|
+
userEvent.click(button);
|
|
20
|
+
const infoToastr = await screen.findByText("This is an info toastr.");
|
|
21
|
+
expect(infoToastr).toBeInTheDocument();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should render Warning Toastr without error", async () => {
|
|
25
|
+
render(
|
|
26
|
+
<>
|
|
27
|
+
<ToastContainer/>
|
|
28
|
+
<Button
|
|
29
|
+
label="Warning Toastr"
|
|
30
|
+
onClick={() => Toastr.warning("This is a warning toastr.")}
|
|
31
|
+
/>
|
|
32
|
+
</>
|
|
33
|
+
);
|
|
34
|
+
const button = screen.getByText("Warning Toastr");
|
|
35
|
+
userEvent.click(button);
|
|
36
|
+
const warningToastr = await screen.findByText("This is a warning toastr.");
|
|
37
|
+
expect(warningToastr).toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should render Success Toastr without error", async () => {
|
|
41
|
+
render(
|
|
42
|
+
<>
|
|
43
|
+
<ToastContainer/>
|
|
44
|
+
<Button
|
|
45
|
+
label="Success Toastr"
|
|
46
|
+
onClick={() => Toastr.success("This is a success toastr.")}
|
|
47
|
+
/>
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
const button = screen.getByText("Success Toastr");
|
|
51
|
+
userEvent.click(button);
|
|
52
|
+
const successToastr = await screen.findByText("This is a success toastr.");
|
|
53
|
+
expect(successToastr).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should render Toastr with CTA without error", async () => {
|
|
57
|
+
render(
|
|
58
|
+
<>
|
|
59
|
+
<ToastContainer/>
|
|
60
|
+
<Button
|
|
61
|
+
label="Toastr with CTA"
|
|
62
|
+
onClick={() =>
|
|
63
|
+
Toastr.error(
|
|
64
|
+
Error("Ticket marked as spam."),
|
|
65
|
+
"Block Customer",
|
|
66
|
+
() => alert("Customer blocked successfully!")
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
/>
|
|
70
|
+
</>
|
|
71
|
+
);
|
|
72
|
+
const button = screen.getByText("Toastr with CTA");
|
|
73
|
+
userEvent.click(button);
|
|
74
|
+
const toastr = await screen.findByText("Ticket marked as spam.");
|
|
75
|
+
expect(toastr).toBeInTheDocument();
|
|
76
|
+
const alertMock = jest.spyOn(window,'alert').mockImplementation();
|
|
77
|
+
const callToAction = screen.getByText("Block Customer");
|
|
78
|
+
userEvent.click(callToAction);
|
|
79
|
+
expect(alertMock).toHaveBeenCalledTimes(1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should render Error Toastr without error", async () => {
|
|
83
|
+
render(
|
|
84
|
+
<>
|
|
85
|
+
<ToastContainer/>
|
|
86
|
+
<Button
|
|
87
|
+
label="Error Toastr"
|
|
88
|
+
onClick={() =>
|
|
89
|
+
Toastr.error(Error("Some error occured!"))
|
|
90
|
+
}
|
|
91
|
+
/>
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
const button = screen.getByText("Error Toastr");
|
|
95
|
+
userEvent.click(button);
|
|
96
|
+
const errorToastr = await screen.findByText("Some error occured!");
|
|
97
|
+
expect(errorToastr).toBeInTheDocument();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("should render a clickable message when the toastr has a link", async () => {
|
|
101
|
+
render(
|
|
102
|
+
<>
|
|
103
|
+
<ToastContainer/>
|
|
104
|
+
<Button
|
|
105
|
+
label="Info Toastr"
|
|
106
|
+
onClick={() => Toastr.info("https://github.com/bigbinary/neeto-ui")}
|
|
107
|
+
/>
|
|
108
|
+
</>
|
|
109
|
+
);
|
|
110
|
+
const button = screen.getByText("Info Toastr");
|
|
111
|
+
userEvent.click(button);
|
|
112
|
+
const link = await screen.findByRole("link");
|
|
113
|
+
expect(link).toHaveAttribute("href", "https://github.com/bigbinary/neeto-ui");
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it("should render plain text error toastr", async () => {
|
|
117
|
+
render(
|
|
118
|
+
<>
|
|
119
|
+
<ToastContainer/>
|
|
120
|
+
<Button
|
|
121
|
+
label="String Error"
|
|
122
|
+
onClick={() =>
|
|
123
|
+
Toastr.error("This is a plain text error toastr!")
|
|
124
|
+
}
|
|
125
|
+
/>
|
|
126
|
+
</>
|
|
127
|
+
);
|
|
128
|
+
const button = screen.getByText("String Error");
|
|
129
|
+
userEvent.click(button);
|
|
130
|
+
const errorToastr = await screen.findByText("This is a plain text error toastr!");
|
|
131
|
+
expect(errorToastr).toBeInTheDocument();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should render Axios Error Toastr without error", async () => {
|
|
135
|
+
const onAxiosStringError = () => {
|
|
136
|
+
try {
|
|
137
|
+
// Dummy axios error object
|
|
138
|
+
const axiosError = {
|
|
139
|
+
isAxiosError: true,
|
|
140
|
+
config: {
|
|
141
|
+
url: "https://api.github.com/users/org",
|
|
142
|
+
},
|
|
143
|
+
response: {
|
|
144
|
+
data: {
|
|
145
|
+
error: "Not Found",
|
|
146
|
+
},
|
|
147
|
+
status: 404,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
throw axiosError;
|
|
151
|
+
} catch (e) {
|
|
152
|
+
Toastr.error(e);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
render(
|
|
156
|
+
<>
|
|
157
|
+
<ToastContainer/>
|
|
158
|
+
<Button label="Throw an axios error" onClick={onAxiosStringError} />
|
|
159
|
+
</>
|
|
160
|
+
);
|
|
161
|
+
const button = screen.getByText("Throw an axios error");
|
|
162
|
+
userEvent.click(button);
|
|
163
|
+
const axiosError = await screen.findByText("Not Found");
|
|
164
|
+
expect(axiosError).toBeInTheDocument();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("should render Axios Error Toastr with array of error messages", async () => {
|
|
168
|
+
const onAxiosArrayError = () => {
|
|
169
|
+
try {
|
|
170
|
+
// Dummy axios error object
|
|
171
|
+
const axiosError = {
|
|
172
|
+
isAxiosError: true,
|
|
173
|
+
config: {
|
|
174
|
+
url: "https://api.github.com/users/org",
|
|
175
|
+
},
|
|
176
|
+
response: {
|
|
177
|
+
data: {
|
|
178
|
+
errors: ["A is required", "B is required"],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
throw axiosError;
|
|
183
|
+
} catch (e) {
|
|
184
|
+
Toastr.error(e);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
render(
|
|
188
|
+
<>
|
|
189
|
+
<ToastContainer/>
|
|
190
|
+
<Button
|
|
191
|
+
label="Throw an axios error with array of error messages"
|
|
192
|
+
onClick={onAxiosArrayError}
|
|
193
|
+
/>
|
|
194
|
+
</>
|
|
195
|
+
);
|
|
196
|
+
const button = screen.getByText("Throw an axios error with array of error messages");
|
|
197
|
+
userEvent.click(button);
|
|
198
|
+
const axiosError = await screen.findByText("A is required B is required");
|
|
199
|
+
expect(axiosError).toBeInTheDocument();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("should render Error Toastr with 'Something went wrong.' when there is no message passed explicitly", async () => {
|
|
203
|
+
render(
|
|
204
|
+
<>
|
|
205
|
+
<ToastContainer/>
|
|
206
|
+
<Button
|
|
207
|
+
label="Error Toastr"
|
|
208
|
+
onClick={() => Toastr.error()}
|
|
209
|
+
/>
|
|
210
|
+
</>
|
|
211
|
+
);
|
|
212
|
+
const button = screen.getByText("Error Toastr");
|
|
213
|
+
userEvent.click(button);
|
|
214
|
+
const errorToastr = await screen.findByText("Something went wrong.");
|
|
215
|
+
expect(errorToastr).toBeInTheDocument();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Tooltip, Typography } from "../lib/components";
|
|
3
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("Tooltip", () => {
|
|
7
|
+
it("should render on hover ", () => {
|
|
8
|
+
render(
|
|
9
|
+
<Tooltip content="Tooltip">
|
|
10
|
+
<Typography>Text</Typography>
|
|
11
|
+
</Tooltip>
|
|
12
|
+
);
|
|
13
|
+
const text = screen.getByText("Text")
|
|
14
|
+
userEvent.hover(text)
|
|
15
|
+
const tooltip = screen.getByText("Tooltip")
|
|
16
|
+
expect(tooltip).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should not render when user stops hovering", async () => {
|
|
20
|
+
render(
|
|
21
|
+
<Tooltip content="Tooltip" >
|
|
22
|
+
<Typography>Text</Typography>
|
|
23
|
+
</Tooltip>
|
|
24
|
+
);
|
|
25
|
+
const text = screen.getByText("Text")
|
|
26
|
+
userEvent.hover(text)
|
|
27
|
+
const tooltip = screen.getByText("Tooltip")
|
|
28
|
+
userEvent.unhover(text)
|
|
29
|
+
await waitFor(() => expect(tooltip).not.toBeVisible())
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should auto hide tooltip after n milliseconds", async () => {
|
|
33
|
+
render(
|
|
34
|
+
<Tooltip content="Tooltip" hideAfter={100}>
|
|
35
|
+
<Typography>Text</Typography>
|
|
36
|
+
</Tooltip>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const text = screen.getByText("Text")
|
|
40
|
+
userEvent.hover(text)
|
|
41
|
+
const tooltip = screen.getByText("Tooltip")
|
|
42
|
+
await waitFor(() => expect(tooltip).not.toBeVisible())
|
|
43
|
+
});
|
|
44
|
+
});
|