dhre-component-lib 0.0.1 → 0.0.3
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/jest.config.ts +1 -1
- package/package.json +9 -6
- package/src/components/Avatar/Avatar.test.tsx +52 -0
- package/src/components/Avatar/__snapshots__/Avatar.test.tsx.snap +9 -0
- package/src/components/Badge/Badge.test.tsx +63 -0
- package/src/components/Badge/__snapshots__/Badge.test.tsx.snap +9 -0
- package/src/components/BreadCrumb/BreadCrumb.test.tsx +90 -0
- package/src/components/BreadCrumb/index.ts +1 -0
- package/src/components/Button/Button.test.tsx +62 -0
- package/src/components/Button/__snapshots__/Button.test.tsx.snap +9 -0
- package/src/components/Checkbox/Checkbox.test.tsx +71 -43
- package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +17 -0
- package/src/components/{Circular_Progress → CircularProgress}/CircularProgress.tsx +1 -1
- package/src/components/Divider/Divider.test.tsx +35 -10
- package/src/components/InputTextField/InputTextField.test.tsx +103 -33
- package/src/components/InputTextField/InputTextField.tsx +7 -5
- package/src/components/Link/Link.test.tsx +44 -36
- package/src/components/Link/Link.tsx +1 -1
- package/src/components/Map/Directions.tsx +36 -0
- package/src/components/Map/GoogleMap.module.scss +5 -0
- package/src/components/Map/GoogleMap.tsx +186 -0
- package/src/components/Map/GoogleMapsLoader.tsx +12 -0
- package/src/components/Map/index.ts +2 -0
- package/src/components/Modal/Modal.css +26 -0
- package/src/components/Modal/Modal.test.tsx +53 -34
- package/src/components/Modal/Modal.tsx +15 -6
- package/src/components/PdfView/PdfView.css +70 -0
- package/src/components/PdfView/PdfView.test.tsx +27 -63
- package/src/components/PdfView/PdfView.tsx +53 -41
- package/src/components/Progress/Progress.test.tsx +34 -26
- package/src/components/Progress/Progress.tsx +2 -2
- package/src/components/RadioButton/RadioButton.test.tsx +59 -30
- package/src/components/Switch/Switch.test.tsx +83 -0
- package/src/components/Tag/Tag.test.tsx +57 -0
- package/src/components/Tag/__snapshots__/Tag.test.tsx.snap +9 -0
- package/src/components/Tooltip/Tooltip.test.tsx +73 -0
- package/src/components/Tooltip/__snapshots__/Tooltip.test.tsx.snap +22 -0
- package/src/components/index.ts +5 -2
- package/src/typings.d.ts +1 -0
- package/tsconfig.json +17 -18
- /package/src/components/{Circular_Progress → CircularProgress}/CircularProgress.css +0 -0
- /package/src/components/{Circular_Progress → CircularProgress}/CircularProgress.test.tsx +0 -0
- /package/src/components/{Circular_Progress → CircularProgress}/index.ts +0 -0
package/jest.config.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dhre-component-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
7
|
-
"rollup": "rollup -c"
|
|
7
|
+
"rollup": "rollup -c",
|
|
8
|
+
"test:coverage": "jest --coverage"
|
|
8
9
|
},
|
|
9
10
|
"author": "",
|
|
10
11
|
"license": "ISC",
|
|
11
12
|
"description": "",
|
|
12
13
|
"devDependencies": {
|
|
14
|
+
"@babel/core": "^7.25.2",
|
|
15
|
+
"@babel/preset-env": "^7.25.4",
|
|
13
16
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
14
17
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
15
18
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
16
|
-
"@testing-library/jest-dom": "^6.
|
|
19
|
+
"@testing-library/jest-dom": "^6.5.0",
|
|
20
|
+
"@testing-library/react": "^16.0.1",
|
|
17
21
|
"@types/jest": "^29.5.12",
|
|
18
|
-
"@types/react": "^18.3.
|
|
22
|
+
"@types/react": "^18.3.5",
|
|
19
23
|
"@types/testing-library__jest-dom": "^6.0.0",
|
|
20
24
|
"jest": "^29.7.0",
|
|
21
25
|
"jest-dom": "^4.0.0",
|
|
@@ -25,7 +29,7 @@
|
|
|
25
29
|
"rollup": "^4.18.1",
|
|
26
30
|
"rollup-plugin-dts": "^6.1.1",
|
|
27
31
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
28
|
-
"ts-jest": "^29.2.
|
|
32
|
+
"ts-jest": "^29.2.5",
|
|
29
33
|
"ts-node": "^10.9.2",
|
|
30
34
|
"typescript": "^5.5.3"
|
|
31
35
|
},
|
|
@@ -34,7 +38,6 @@
|
|
|
34
38
|
"@emotion/styled": "^11.13.0",
|
|
35
39
|
"@mui/icons-material": "^5.16.7",
|
|
36
40
|
"@mui/material": "^5.16.7",
|
|
37
|
-
"@testing-library/react": "^16.0.0",
|
|
38
41
|
"tslib": "^2.6.3"
|
|
39
42
|
},
|
|
40
43
|
"peerDependencies": {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import Avatar, { AvatarProps } from './Avatar';
|
|
5
|
+
|
|
6
|
+
describe('Avatar Component', () => {
|
|
7
|
+
const defaultProps: AvatarProps = {
|
|
8
|
+
src: 'test-image.jpg',
|
|
9
|
+
alt: 'Test Avatar',
|
|
10
|
+
imgClassName: 'avatar-class',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
it('renders the image with the provided src and alt attributes', () => {
|
|
14
|
+
render(<Avatar {...defaultProps} />);
|
|
15
|
+
|
|
16
|
+
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
17
|
+
|
|
18
|
+
expect(imgElement).toHaveAttribute('src', defaultProps.src);
|
|
19
|
+
expect(imgElement).toHaveAttribute('alt', defaultProps.alt);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('applies the correct className to the image', () => {
|
|
23
|
+
render(<Avatar {...defaultProps} />);
|
|
24
|
+
|
|
25
|
+
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
26
|
+
|
|
27
|
+
expect(imgElement).toHaveClass(defaultProps.imgClassName);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('handles the onClick event correctly', () => {
|
|
31
|
+
const handleClick = jest.fn();
|
|
32
|
+
render(<Avatar {...defaultProps} handleClick={handleClick} />);
|
|
33
|
+
|
|
34
|
+
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
35
|
+
fireEvent.click(imgElement);
|
|
36
|
+
|
|
37
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('does not crash without handleClick prop', () => {
|
|
41
|
+
render(<Avatar {...defaultProps} />);
|
|
42
|
+
|
|
43
|
+
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
44
|
+
expect(() => fireEvent.click(imgElement)).not.toThrow();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('matches snapshot for default rendering', () => {
|
|
48
|
+
const { container } = render(<Avatar {...defaultProps} />);
|
|
49
|
+
|
|
50
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import Badge, { BadgeProps } from './Badge';
|
|
5
|
+
|
|
6
|
+
describe('Badge Component', () => {
|
|
7
|
+
const defaultProps: BadgeProps = {
|
|
8
|
+
content: 'Test Badge',
|
|
9
|
+
badgeClassName: 'badge-class',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
it('renders the badge with the provided content', () => {
|
|
13
|
+
render(<Badge {...defaultProps} />);
|
|
14
|
+
|
|
15
|
+
const badgeElement = screen.getByText(defaultProps.content as string);
|
|
16
|
+
|
|
17
|
+
expect(badgeElement).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('applies the correct className to the badge', () => {
|
|
21
|
+
render(<Badge {...defaultProps} />);
|
|
22
|
+
|
|
23
|
+
const badgeElement = screen.getByText(defaultProps.content as string);
|
|
24
|
+
|
|
25
|
+
expect(badgeElement).toHaveClass(defaultProps.badgeClassName);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('handles the onClick event correctly', () => {
|
|
29
|
+
const handleClick = jest.fn();
|
|
30
|
+
render(<Badge {...defaultProps} handleClick={handleClick} />);
|
|
31
|
+
|
|
32
|
+
const badgeElement = screen.getByText(defaultProps.content as string);
|
|
33
|
+
fireEvent.click(badgeElement);
|
|
34
|
+
|
|
35
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('does not crash without handleClick prop', () => {
|
|
39
|
+
render(<Badge {...defaultProps} />);
|
|
40
|
+
|
|
41
|
+
const badgeElement = screen.getByText(defaultProps.content as string);
|
|
42
|
+
expect(() => fireEvent.click(badgeElement)).not.toThrow();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('renders correctly with numeric content', () => {
|
|
46
|
+
const numericProps: BadgeProps = {
|
|
47
|
+
...defaultProps,
|
|
48
|
+
content: 99,
|
|
49
|
+
};
|
|
50
|
+
render(<Badge {...numericProps} />);
|
|
51
|
+
|
|
52
|
+
const badgeElement = screen.getByText(numericProps.content.toString());
|
|
53
|
+
|
|
54
|
+
expect(badgeElement).toBeInTheDocument();
|
|
55
|
+
expect(badgeElement).toHaveTextContent('99');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('matches snapshot for default rendering', () => {
|
|
59
|
+
const { container } = render(<Badge {...defaultProps} />);
|
|
60
|
+
|
|
61
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import Breadcrumb from './BreadCrumb';
|
|
5
|
+
|
|
6
|
+
describe('Breadcrumb', () => {
|
|
7
|
+
it('should render with given props', () => {
|
|
8
|
+
const items = [
|
|
9
|
+
{ label: 'Home', handleClick: () => {} },
|
|
10
|
+
{ label: 'Library' },
|
|
11
|
+
{ label: 'Data' },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
render(
|
|
15
|
+
<Breadcrumb
|
|
16
|
+
items={items}
|
|
17
|
+
breadcrumbClassName="breadcrumb-class"
|
|
18
|
+
itemClassName="item-class"
|
|
19
|
+
separator=">"
|
|
20
|
+
separatorClassName="separator-class"
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Check if breadcrumb container is rendered
|
|
25
|
+
const breadcrumb = screen.getByRole('navigation');
|
|
26
|
+
expect(breadcrumb).toBeInTheDocument();
|
|
27
|
+
expect(breadcrumb).toHaveClass('breadcrumb-class');
|
|
28
|
+
|
|
29
|
+
// Check if breadcrumb items are rendered
|
|
30
|
+
items.forEach((item) => {
|
|
31
|
+
const itemElement = screen.getByText(item.label);
|
|
32
|
+
expect(itemElement).toBeInTheDocument();
|
|
33
|
+
expect(itemElement).toHaveClass('item-class');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Check if separators are rendered
|
|
37
|
+
const separators = screen.getAllByText('>');
|
|
38
|
+
expect(separators.length).toBe(items.length - 1);
|
|
39
|
+
separators.forEach(separator => expect(separator).toHaveClass('separator-class'));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should call handleClick when a breadcrumb item is clicked', () => {
|
|
43
|
+
const handleClick = jest.fn();
|
|
44
|
+
const items = [
|
|
45
|
+
{ label: 'Home', handleClick },
|
|
46
|
+
{ label: 'Library' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
render(
|
|
50
|
+
<Breadcrumb
|
|
51
|
+
items={items}
|
|
52
|
+
breadcrumbClassName="breadcrumb-class"
|
|
53
|
+
itemClassName="item-class"
|
|
54
|
+
separator=">"
|
|
55
|
+
separatorClassName="separator-class"
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const homeItem = screen.getByText('Home');
|
|
60
|
+
fireEvent.click(homeItem);
|
|
61
|
+
|
|
62
|
+
expect(handleClick).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should render without separators if none are provided', () => {
|
|
66
|
+
const items = [
|
|
67
|
+
{ label: 'Home' },
|
|
68
|
+
{ label: 'Library' },
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
render(
|
|
72
|
+
<Breadcrumb
|
|
73
|
+
items={items}
|
|
74
|
+
breadcrumbClassName="breadcrumb-class"
|
|
75
|
+
itemClassName="item-class"
|
|
76
|
+
separator="" // Pass an empty string for separator
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Check if breadcrumb items are rendered
|
|
81
|
+
items.forEach((item) => {
|
|
82
|
+
const itemElement = screen.getByText(item.label);
|
|
83
|
+
expect(itemElement).toBeInTheDocument();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Check that no separators are present by querying with the separator class name
|
|
87
|
+
const separators = screen.queryAllByRole('presentation');
|
|
88
|
+
expect(separators.length).toBe(0);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./BreadCrumb";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import Button, { ButtonProps } from './Button';
|
|
5
|
+
|
|
6
|
+
describe('Button Component', () => {
|
|
7
|
+
let handleClick: jest.Mock;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
handleClick = jest.fn(); // Initialize the mock function before each test
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const renderButton = (props: Partial<ButtonProps> = {}) => {
|
|
14
|
+
const defaultProps: ButtonProps = {
|
|
15
|
+
label: 'Click Me',
|
|
16
|
+
labelClassName: 'button-class',
|
|
17
|
+
handleClick, // Use the mocked handleClick function here
|
|
18
|
+
...props, // Allow overriding props for specific tests
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return render(<Button {...defaultProps} />);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
it('renders the button with the correct label', () => {
|
|
25
|
+
renderButton();
|
|
26
|
+
|
|
27
|
+
const buttonElement = screen.getByText('Click Me');
|
|
28
|
+
|
|
29
|
+
expect(buttonElement).toBeInTheDocument();
|
|
30
|
+
expect(buttonElement.tagName).toBe('BUTTON');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('applies the correct className to the button', () => {
|
|
34
|
+
renderButton();
|
|
35
|
+
|
|
36
|
+
const buttonElement = screen.getByText('Click Me');
|
|
37
|
+
|
|
38
|
+
expect(buttonElement).toHaveClass('button-class');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('calls the handleClick function when the button is clicked', () => {
|
|
42
|
+
renderButton();
|
|
43
|
+
|
|
44
|
+
const buttonElement = screen.getByText('Click Me');
|
|
45
|
+
|
|
46
|
+
fireEvent.click(buttonElement);
|
|
47
|
+
|
|
48
|
+
expect(handleClick).toHaveBeenCalledTimes(1); // Ensure the mock function is called once
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('renders correctly without crashing', () => {
|
|
52
|
+
const { container } = renderButton();
|
|
53
|
+
|
|
54
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('does not call handleClick when the button is not clicked', () => {
|
|
58
|
+
renderButton();
|
|
59
|
+
|
|
60
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -1,61 +1,89 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { render, fireEvent } from
|
|
3
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import CustomCheckbox from './Checkbox';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
it("should render with default props", () => {
|
|
14
|
-
const { getByRole } = render(<Checkbox />);
|
|
15
|
-
const checkboxElement = getByRole("checkbox");
|
|
6
|
+
interface CustomCheckboxProps {
|
|
7
|
+
label?: string;
|
|
8
|
+
checked?: boolean;
|
|
9
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
10
|
+
className?: string;
|
|
11
|
+
checkboxClassName?: string;
|
|
12
|
+
labelClassName?: string;
|
|
13
|
+
}
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
describe('CustomCheckbox Component', () => {
|
|
16
|
+
let handleChange: jest.Mock;
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
// Function to generate default props for each test
|
|
19
|
+
const getDefaultProps = (): CustomCheckboxProps => ({
|
|
20
|
+
label: 'Accept Terms',
|
|
21
|
+
checked: false,
|
|
22
|
+
onChange: handleChange,
|
|
23
|
+
className: 'custom-container',
|
|
24
|
+
checkboxClassName: 'custom-checkbox',
|
|
25
|
+
labelClassName: 'custom-label',
|
|
21
26
|
});
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const checkboxElement = getByRole("checkbox");
|
|
26
|
-
|
|
27
|
-
expect(checkboxElement).toBeChecked();
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
handleChange = jest.fn(); // Reset the mock function before each test
|
|
28
30
|
});
|
|
29
31
|
|
|
30
|
-
it(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const checkboxElement = getByRole(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
expect(
|
|
38
|
-
expect(handleChange).toHaveBeenCalledWith(expect.any(Object), true);
|
|
32
|
+
it('renders the checkbox with a label', () => {
|
|
33
|
+
render(<CustomCheckbox {...getDefaultProps()} />);
|
|
34
|
+
|
|
35
|
+
const checkboxElement = screen.getByRole('checkbox');
|
|
36
|
+
const labelElement = screen.getByText('Accept Terms');
|
|
37
|
+
|
|
38
|
+
expect(checkboxElement).toBeInTheDocument();
|
|
39
|
+
expect(labelElement).toBeInTheDocument();
|
|
39
40
|
});
|
|
40
41
|
|
|
41
|
-
it(
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
it('applies the correct className to the checkbox container', () => {
|
|
43
|
+
render(<CustomCheckbox {...getDefaultProps()} />);
|
|
44
|
+
|
|
45
|
+
const container = screen.getByRole('checkbox').parentElement;
|
|
46
|
+
|
|
47
|
+
expect(container).toHaveClass('custom-container');
|
|
48
|
+
});
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
it('applies the correct className to the checkbox', () => {
|
|
51
|
+
render(<CustomCheckbox {...getDefaultProps()} />);
|
|
52
|
+
|
|
53
|
+
const checkboxElement = screen.getByRole('checkbox');
|
|
54
|
+
|
|
55
|
+
expect(checkboxElement).toHaveClass('custom-checkbox');
|
|
46
56
|
});
|
|
47
57
|
|
|
48
|
-
it(
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
it('applies the correct className to the label', () => {
|
|
59
|
+
render(<CustomCheckbox {...getDefaultProps()} />);
|
|
60
|
+
|
|
61
|
+
const labelElement = screen.getByText('Accept Terms');
|
|
62
|
+
|
|
63
|
+
expect(labelElement).toHaveClass('custom-label');
|
|
64
|
+
});
|
|
51
65
|
|
|
52
|
-
|
|
66
|
+
it('checks the checkbox based on the checked prop', () => {
|
|
67
|
+
render(<CustomCheckbox {...getDefaultProps()} checked={true} />);
|
|
68
|
+
|
|
69
|
+
const checkboxElement = screen.getByRole('checkbox');
|
|
70
|
+
|
|
71
|
+
expect(checkboxElement).toBeChecked();
|
|
53
72
|
});
|
|
54
73
|
|
|
55
|
-
it(
|
|
56
|
-
|
|
57
|
-
|
|
74
|
+
it('calls the onChange function when the checkbox state changes', () => {
|
|
75
|
+
render(<CustomCheckbox {...getDefaultProps()} checked={false} />);
|
|
76
|
+
|
|
77
|
+
const checkboxElement = screen.getByRole('checkbox');
|
|
78
|
+
|
|
79
|
+
fireEvent.click(checkboxElement); // Toggle the checkbox
|
|
80
|
+
|
|
81
|
+
expect(handleChange).toHaveBeenCalledTimes(1);
|
|
82
|
+
});
|
|
58
83
|
|
|
59
|
-
|
|
84
|
+
it('renders correctly without crashing', () => {
|
|
85
|
+
const { container } = render(<CustomCheckbox {...getDefaultProps()} />);
|
|
86
|
+
|
|
87
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
60
88
|
});
|
|
61
89
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`CustomCheckbox Component renders correctly without crashing 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
class="custom-container"
|
|
6
|
+
>
|
|
7
|
+
<input
|
|
8
|
+
class="custom-checkbox"
|
|
9
|
+
type="checkbox"
|
|
10
|
+
/>
|
|
11
|
+
<label
|
|
12
|
+
class="custom-label"
|
|
13
|
+
>
|
|
14
|
+
Accept Terms
|
|
15
|
+
</label>
|
|
16
|
+
</div>
|
|
17
|
+
`;
|
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { render } from "@testing-library/react";
|
|
3
|
-
import
|
|
3
|
+
import CustomDivider from "./Divider";
|
|
4
|
+
import { DIVIDER_ORIENTATION } from "../Enum";
|
|
4
5
|
|
|
5
|
-
describe("
|
|
6
|
-
it("
|
|
7
|
-
const {
|
|
8
|
-
expect(
|
|
6
|
+
describe("CustomDivider Component", () => {
|
|
7
|
+
it("renders without crashing", () => {
|
|
8
|
+
const { container } = render(<CustomDivider />);
|
|
9
|
+
expect(container.firstChild).toBeTruthy();
|
|
9
10
|
});
|
|
10
11
|
|
|
11
|
-
it("
|
|
12
|
-
const { container } = render(<
|
|
13
|
-
|
|
12
|
+
it("applies the correct default orientation class", () => {
|
|
13
|
+
const { container } = render(<CustomDivider />);
|
|
14
|
+
expect(container.firstChild).toHaveClass(DIVIDER_ORIENTATION.Horizontal);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("applies a custom orientation class", () => {
|
|
18
|
+
const { container } = render(
|
|
19
|
+
<CustomDivider orientation={DIVIDER_ORIENTATION.Vertical} />
|
|
20
|
+
);
|
|
21
|
+
expect(container.firstChild).toHaveClass(DIVIDER_ORIENTATION.Vertical);
|
|
22
|
+
});
|
|
14
23
|
|
|
15
|
-
|
|
24
|
+
it("applies the passed className to the outer div", () => {
|
|
25
|
+
const { container } = render(
|
|
26
|
+
<CustomDivider className="custom-class" />
|
|
27
|
+
);
|
|
28
|
+
expect(container.firstChild).toHaveClass("custom-class");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("applies the passed dividerClassName to the inner div", () => {
|
|
32
|
+
const { container } = render(
|
|
33
|
+
<CustomDivider dividerClassName="inner-class" />
|
|
34
|
+
);
|
|
35
|
+
expect(container.firstChild?.firstChild).toHaveClass("inner-class");
|
|
36
|
+
});
|
|
16
37
|
|
|
17
|
-
|
|
38
|
+
it("passes additional props to the outer div", () => {
|
|
39
|
+
const { container } = render(
|
|
40
|
+
<CustomDivider data-testid="custom-divider" />
|
|
41
|
+
);
|
|
42
|
+
expect(container.firstChild).toHaveAttribute("data-testid", "custom-divider");
|
|
18
43
|
});
|
|
19
44
|
});
|