@bigbinary/neetoui 3.2.61 → 3.2.62
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 +23 -0
- package/formik.js +1 -1
- package/index.js +1 -1
- package/jest-setup.js +1 -0
- package/layouts.js +1 -1
- package/package.json +3 -3
- package/tests/Button.test.js +72 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neetoui",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.62",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"author": "BigBinary",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"@storybook/manager-webpack5": "^6.4.19",
|
|
50
50
|
"@storybook/preset-scss": "^1.0.3",
|
|
51
51
|
"@storybook/react": "^6.4.19",
|
|
52
|
-
"@testing-library/jest-dom": "^5.
|
|
53
|
-
"@testing-library/react": "^12.
|
|
52
|
+
"@testing-library/jest-dom": "^5.16.2",
|
|
53
|
+
"@testing-library/react": "^12.1.3",
|
|
54
54
|
"@testing-library/user-event": "^13.1.9",
|
|
55
55
|
"autoprefixer": "^9.0.0",
|
|
56
56
|
"babel-eslint": "^10.1.0",
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Button } from "../lib/components";
|
|
3
|
+
import { render, fireEvent } from "@testing-library/react";
|
|
4
|
+
import { BrowserRouter } from "react-router-dom";
|
|
5
|
+
|
|
6
|
+
describe("Button", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
const { getByText } = render(<Button label="Button" />);
|
|
9
|
+
expect(getByText("Button")).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should call onClick on button click", () => {
|
|
13
|
+
const onClick = jest.fn();
|
|
14
|
+
const { getByText } = render(<Button label="Button" onClick={onClick} />);
|
|
15
|
+
fireEvent.click(getByText("Button"));
|
|
16
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should not call onClick on button click when disabled", () => {
|
|
20
|
+
const onClick = jest.fn();
|
|
21
|
+
const { getByText } = render(
|
|
22
|
+
<Button label="Button" onClick={onClick} disabled />
|
|
23
|
+
);
|
|
24
|
+
fireEvent.click(getByText("Button"));
|
|
25
|
+
expect(onClick).toHaveBeenCalledTimes(0);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should not call onClick on button click when loading", () => {
|
|
29
|
+
const onClick = jest.fn();
|
|
30
|
+
const { getByText } = render(
|
|
31
|
+
<Button label="Button" onClick={onClick} loading />
|
|
32
|
+
);
|
|
33
|
+
fireEvent.click(getByText("Button"));
|
|
34
|
+
expect(onClick).toHaveBeenCalledTimes(0);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should show tooltip when button is hovered", () => {
|
|
38
|
+
const { getByText } = render(
|
|
39
|
+
<Button label="Button" tooltipProps={{ content: "Tooltip" }} />
|
|
40
|
+
);
|
|
41
|
+
fireEvent.mouseEnter(getByText("Button"), { bubbles: true });
|
|
42
|
+
expect(getByText("Tooltip")).toBeInTheDocument();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should show icon when icon string is provided", () => {
|
|
46
|
+
const { getByTestId } = render(<Button icon="check" />);
|
|
47
|
+
expect(getByTestId("class-icon")).toBeInTheDocument();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should show icon when icon component is provided", () => {
|
|
51
|
+
const { getByTestId } = render(
|
|
52
|
+
<Button icon={() => <svg data-testid="svg-icon" />} />
|
|
53
|
+
);
|
|
54
|
+
expect(getByTestId("svg-icon")).toBeInTheDocument();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should render a link when `href` prop is given", () => {
|
|
58
|
+
const { getByRole } = render(
|
|
59
|
+
<Button label="Link" href="https://example.com" />
|
|
60
|
+
);
|
|
61
|
+
expect(getByRole("link")).toHaveAttribute("href", "https://example.com");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should render a router link when `to` prop is given", () => {
|
|
65
|
+
const { getByRole } = render(
|
|
66
|
+
<BrowserRouter>
|
|
67
|
+
<Button label="Router Link" to="/some-path" />
|
|
68
|
+
</BrowserRouter>
|
|
69
|
+
);
|
|
70
|
+
expect(getByRole("link")).toHaveAttribute("href", "/some-path");
|
|
71
|
+
});
|
|
72
|
+
});
|