dhre-component-lib 0.1.5 → 0.1.7
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/components/Avatar/Avatar.d.ts +9 -0
- package/dist/components/Avatar/Avatar.js +6 -0
- package/dist/components/Avatar/Avatar.test.d.ts +1 -0
- package/dist/components/Avatar/Avatar.test.js +39 -0
- package/dist/components/Avatar/index.d.ts +1 -0
- package/dist/components/Avatar/index.js +1 -0
- package/dist/components/Badge/Badge.d.ts +8 -0
- package/dist/components/Badge/Badge.js +6 -0
- package/dist/components/Badge/Badge.test.d.ts +1 -0
- package/dist/components/Badge/Badge.test.js +44 -0
- package/dist/components/Badge/index.d.ts +2 -0
- package/dist/components/Badge/index.js +2 -0
- package/dist/components/BreadCrumb/BreadCrumb.d.ts +14 -0
- package/dist/components/BreadCrumb/BreadCrumb.js +8 -0
- package/dist/components/BreadCrumb/BreadCrumb.test.d.ts +1 -0
- package/dist/components/BreadCrumb/BreadCrumb.test.js +55 -0
- package/dist/components/BreadCrumb/index.d.ts +2 -0
- package/dist/components/BreadCrumb/index.js +2 -0
- package/dist/components/Button/Button.d.ts +10 -0
- package/dist/components/Button/Button.js +6 -0
- package/dist/components/Button/Button.test.d.ts +1 -0
- package/dist/components/Button/Button.test.js +36 -0
- package/dist/components/Button/index.d.ts +2 -0
- package/dist/components/Button/index.js +2 -0
- package/dist/components/Checkbox/Checkbox.d.ts +11 -0
- package/dist/components/Checkbox/Checkbox.js +7 -0
- package/dist/components/Checkbox/Checkbox.test.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.test.js +59 -0
- package/dist/components/Checkbox/index.d.ts +1 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/CircularProgress/CircularProgress.d.ts +10 -0
- package/dist/components/CircularProgress/CircularProgress.js +15 -0
- package/dist/components/CircularProgress/CircularProgress.test.d.ts +1 -0
- package/dist/components/CircularProgress/CircularProgress.test.js +31 -0
- package/dist/components/CircularProgress/index.d.ts +2 -0
- package/dist/components/CircularProgress/index.js +2 -0
- package/dist/components/Divider/Divider.d.ts +8 -0
- package/dist/components/Divider/Divider.js +7 -0
- package/dist/components/Divider/Divider.test.d.ts +1 -0
- package/dist/components/Divider/Divider.test.js +30 -0
- package/dist/components/Divider/index.d.ts +1 -0
- package/dist/components/Divider/index.js +1 -0
- package/dist/components/Enum.d.ts +17 -0
- package/dist/components/Enum.js +17 -0
- package/dist/components/InputTextField/InputTextField.d.ts +16 -0
- package/dist/components/InputTextField/InputTextField.js +9 -0
- package/dist/components/InputTextField/InputTextField.test.d.ts +1 -0
- package/dist/components/InputTextField/InputTextField.test.js +98 -0
- package/dist/components/InputTextField/index.d.ts +1 -0
- package/dist/components/InputTextField/index.js +1 -0
- package/dist/components/Link/Link.d.ts +10 -0
- package/dist/components/Link/Link.js +6 -0
- package/dist/components/Link/Link.test.d.ts +1 -0
- package/dist/components/Link/Link.test.js +47 -0
- package/dist/components/Link/index.d.ts +1 -0
- package/dist/components/Link/index.js +1 -0
- package/dist/components/Map/Directions.d.ts +13 -0
- package/dist/components/Map/Directions.js +9 -0
- package/dist/components/Map/GoogleMap.d.ts +12 -0
- package/dist/components/Map/GoogleMap.js +104 -0
- package/dist/components/Map/GoogleMapsLoader.d.ts +4 -0
- package/dist/components/Map/GoogleMapsLoader.js +10 -0
- package/dist/components/Map/index.d.ts +3 -0
- package/dist/components/Map/index.js +3 -0
- package/dist/components/Modal/Modal.d.ts +10 -0
- package/dist/components/Modal/Modal.js +14 -0
- package/dist/components/Modal/Modal.test.d.ts +1 -0
- package/dist/components/Modal/Modal.test.js +52 -0
- package/dist/components/Modal/index.d.ts +2 -0
- package/dist/components/Modal/index.js +2 -0
- package/dist/components/Notification/Notification.d.ts +10 -0
- package/dist/components/Notification/Notification.js +21 -0
- package/dist/components/Notification/Notification.test.d.ts +1 -0
- package/dist/components/Notification/Notification.test.js +40 -0
- package/dist/components/Notification/index.d.ts +2 -0
- package/dist/components/Notification/index.js +2 -0
- package/dist/components/OtpInput/OtpInput.d.ts +14 -0
- package/dist/components/OtpInput/OtpInput.js +68 -0
- package/dist/components/OtpInput/OtpInput.test.d.ts +1 -0
- package/dist/components/OtpInput/OtpInput.test.js +36 -0
- package/dist/components/OtpInput/index.d.ts +2 -0
- package/dist/components/OtpInput/index.js +2 -0
- package/dist/components/PdfView/PdfView.d.ts +18 -0
- package/dist/components/PdfView/PdfView.js +59 -0
- package/dist/components/PdfView/PdfView.test.d.ts +1 -0
- package/dist/components/PdfView/PdfView.test.js +41 -0
- package/dist/components/PdfView/index.d.ts +2 -0
- package/dist/components/PdfView/index.js +2 -0
- package/dist/components/Progress/Progress.d.ts +12 -0
- package/dist/components/Progress/Progress.js +9 -0
- package/dist/components/Progress/Progress.test.d.ts +1 -0
- package/dist/components/Progress/Progress.test.js +34 -0
- package/dist/components/Progress/index.d.ts +1 -0
- package/dist/components/Progress/index.js +1 -0
- package/dist/components/RadioButton/RadioButton.d.ts +14 -0
- package/dist/components/RadioButton/RadioButton.js +7 -0
- package/dist/components/RadioButton/RadioButton.test.d.ts +1 -0
- package/dist/components/RadioButton/RadioButton.test.js +29 -0
- package/dist/components/RadioButton/index.d.ts +1 -0
- package/dist/components/RadioButton/index.js +1 -0
- package/dist/components/Switch/Switch.d.ts +13 -0
- package/dist/components/Switch/Switch.js +10 -0
- package/dist/components/Switch/Switch.test.d.ts +1 -0
- package/dist/components/Switch/Switch.test.js +45 -0
- package/dist/components/Switch/index.d.ts +1 -0
- package/dist/components/Switch/index.js +1 -0
- package/dist/components/Tag/Tag.d.ts +9 -0
- package/dist/components/Tag/Tag.js +6 -0
- package/dist/components/Tag/Tag.test.d.ts +1 -0
- package/dist/components/Tag/Tag.test.js +43 -0
- package/dist/components/Tag/index.d.ts +1 -0
- package/dist/components/Tag/index.js +1 -0
- package/dist/components/Tooltip/Tooltip.d.ts +9 -0
- package/dist/components/Tooltip/Tooltip.js +11 -0
- package/dist/components/Tooltip/Tooltip.test.d.ts +1 -0
- package/dist/components/Tooltip/Tooltip.test.js +48 -0
- package/dist/components/Tooltip/index.d.ts +2 -0
- package/dist/components/Tooltip/index.js +2 -0
- package/dist/components/index.d.ts +15 -0
- package/dist/components/index.js +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/theme/colors.d.ts +1 -0
- package/dist/theme/colors.js +2 -0
- package/package.json +21 -8
- package/src/components/Badge/index.ts +2 -1
- package/src/components/BreadCrumb/index.ts +2 -1
- package/src/components/Button/index.ts +2 -1
- package/src/components/CircularProgress/index.ts +2 -1
- package/src/components/Map/index.ts +1 -0
- package/src/components/Modal/index.ts +2 -1
- package/src/components/Notification/index.ts +2 -1
- package/src/components/OtpInput/index.ts +2 -1
- package/src/components/PdfView/index.ts +2 -1
- package/src/components/Tooltip/index.ts +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import Avatar from './Avatar';
|
|
5
|
+
describe('Avatar Component', () => {
|
|
6
|
+
const defaultProps = {
|
|
7
|
+
src: 'test-image.jpg',
|
|
8
|
+
alt: 'Test Avatar',
|
|
9
|
+
imgClassName: 'avatar-class',
|
|
10
|
+
};
|
|
11
|
+
it('renders the image with the provided src and alt attributes', () => {
|
|
12
|
+
render(React.createElement(Avatar, { ...defaultProps }));
|
|
13
|
+
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
14
|
+
expect(imgElement).toHaveAttribute('src', defaultProps.src);
|
|
15
|
+
expect(imgElement).toHaveAttribute('alt', defaultProps.alt);
|
|
16
|
+
});
|
|
17
|
+
it('applies the correct className to the image', () => {
|
|
18
|
+
render(React.createElement(Avatar, { ...defaultProps }));
|
|
19
|
+
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
20
|
+
expect(imgElement).toHaveClass(defaultProps.imgClassName);
|
|
21
|
+
});
|
|
22
|
+
it('handles the onClick event correctly', () => {
|
|
23
|
+
const handleClick = jest.fn();
|
|
24
|
+
render(React.createElement(Avatar, { ...defaultProps, handleClick: handleClick }));
|
|
25
|
+
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
26
|
+
fireEvent.click(imgElement);
|
|
27
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
28
|
+
});
|
|
29
|
+
it('does not crash without handleClick prop', () => {
|
|
30
|
+
render(React.createElement(Avatar, { ...defaultProps }));
|
|
31
|
+
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
32
|
+
expect(() => fireEvent.click(imgElement)).not.toThrow();
|
|
33
|
+
});
|
|
34
|
+
it('renders correctly without crashing', () => {
|
|
35
|
+
render(React.createElement(Avatar, { ...defaultProps }));
|
|
36
|
+
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
37
|
+
expect(imgElement).toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Avatar";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Avatar";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import styles from './Badge.module.scss';
|
|
3
|
+
const Badge = ({ content, badgeClassName, handleClick, }) => {
|
|
4
|
+
return (React.createElement("button", { onClick: handleClick, className: `${styles.badge} ${badgeClassName}` }, content));
|
|
5
|
+
};
|
|
6
|
+
export default Badge;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import Badge from './Badge';
|
|
5
|
+
describe('Badge Component', () => {
|
|
6
|
+
const defaultProps = {
|
|
7
|
+
content: 'Test Badge',
|
|
8
|
+
badgeClassName: 'badge-class',
|
|
9
|
+
};
|
|
10
|
+
it('renders the badge with the provided content', () => {
|
|
11
|
+
render(React.createElement(Badge, { ...defaultProps }));
|
|
12
|
+
const badgeElement = screen.getByText(defaultProps.content);
|
|
13
|
+
expect(badgeElement).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
it('handles the onClick event correctly', () => {
|
|
16
|
+
const handleClick = jest.fn();
|
|
17
|
+
render(React.createElement(Badge, { ...defaultProps, handleClick: handleClick }));
|
|
18
|
+
const badgeElement = screen.getByText(defaultProps.content);
|
|
19
|
+
fireEvent.click(badgeElement);
|
|
20
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
21
|
+
});
|
|
22
|
+
it('does not crash without handleClick prop', () => {
|
|
23
|
+
render(React.createElement(Badge, { ...defaultProps }));
|
|
24
|
+
const badgeElement = screen.getByText(defaultProps.content);
|
|
25
|
+
expect(() => fireEvent.click(badgeElement)).not.toThrow();
|
|
26
|
+
});
|
|
27
|
+
it('renders correctly with numeric content', () => {
|
|
28
|
+
const numericProps = {
|
|
29
|
+
...defaultProps,
|
|
30
|
+
content: 99,
|
|
31
|
+
};
|
|
32
|
+
render(React.createElement(Badge, { ...numericProps }));
|
|
33
|
+
const badgeElement = screen.getByText(numericProps.content.toString());
|
|
34
|
+
expect(badgeElement).toBeInTheDocument();
|
|
35
|
+
expect(badgeElement).toHaveTextContent('99');
|
|
36
|
+
});
|
|
37
|
+
it('renders correctly with different content', () => {
|
|
38
|
+
const newContent = 'Updated Badge';
|
|
39
|
+
render(React.createElement(Badge, { ...defaultProps, content: newContent }));
|
|
40
|
+
const badgeElement = screen.getByText(newContent);
|
|
41
|
+
expect(badgeElement).toBeInTheDocument();
|
|
42
|
+
expect(badgeElement).toHaveTextContent(newContent);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface BreadcrumbItem {
|
|
3
|
+
label: string;
|
|
4
|
+
handleClick?: () => void;
|
|
5
|
+
}
|
|
6
|
+
export interface BreadcrumbProps {
|
|
7
|
+
items: BreadcrumbItem[];
|
|
8
|
+
breadcrumbClassName: string;
|
|
9
|
+
itemClassName?: string;
|
|
10
|
+
separator?: string;
|
|
11
|
+
separatorClassName?: string;
|
|
12
|
+
}
|
|
13
|
+
declare const Breadcrumb: React.FC<BreadcrumbProps>;
|
|
14
|
+
export default Breadcrumb;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import styles from './Breadcrumb.module.scss';
|
|
3
|
+
const Breadcrumb = ({ items, breadcrumbClassName, itemClassName, separator = "/", separatorClassName, }) => {
|
|
4
|
+
return (React.createElement("nav", { className: `${styles.breadcrumb} ${breadcrumbClassName}` }, items.map((item, index) => (React.createElement(React.Fragment, { key: index },
|
|
5
|
+
React.createElement("button", { className: `${styles.breadcrumbItem} ${itemClassName}`, onClick: item.handleClick }, item.label),
|
|
6
|
+
index < items.length - 1 && (React.createElement("span", { className: `${styles.separator} ${separatorClassName}` }, separator)))))));
|
|
7
|
+
};
|
|
8
|
+
export default Breadcrumb;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
describe('Breadcrumb', () => {
|
|
6
|
+
it('should render with given props', () => {
|
|
7
|
+
const items = [
|
|
8
|
+
{ label: 'Home', handleClick: () => { } },
|
|
9
|
+
{ label: 'Library' },
|
|
10
|
+
{ label: 'Data' },
|
|
11
|
+
];
|
|
12
|
+
render(React.createElement(Breadcrumb, { items: items, breadcrumbClassName: "breadcrumb-class", itemClassName: "item-class", separator: ">", separatorClassName: "separator-class" }));
|
|
13
|
+
// Check if breadcrumb container is rendered
|
|
14
|
+
const breadcrumb = screen.getByRole('navigation');
|
|
15
|
+
expect(breadcrumb).toBeInTheDocument();
|
|
16
|
+
expect(breadcrumb).toHaveClass('breadcrumb-class');
|
|
17
|
+
// Check if breadcrumb items are rendered
|
|
18
|
+
items.forEach((item) => {
|
|
19
|
+
const itemElement = screen.getByText(item.label);
|
|
20
|
+
expect(itemElement).toBeInTheDocument();
|
|
21
|
+
expect(itemElement).toHaveClass('item-class');
|
|
22
|
+
});
|
|
23
|
+
// Check if separators are rendered
|
|
24
|
+
const separators = screen.getAllByText('>');
|
|
25
|
+
expect(separators.length).toBe(items.length - 1);
|
|
26
|
+
separators.forEach(separator => expect(separator).toHaveClass('separator-class'));
|
|
27
|
+
});
|
|
28
|
+
it('should call handleClick when a breadcrumb item is clicked', () => {
|
|
29
|
+
const handleClick = jest.fn();
|
|
30
|
+
const items = [
|
|
31
|
+
{ label: 'Home', handleClick },
|
|
32
|
+
{ label: 'Library' },
|
|
33
|
+
];
|
|
34
|
+
render(React.createElement(Breadcrumb, { items: items, breadcrumbClassName: "breadcrumb-class", itemClassName: "item-class", separator: ">", separatorClassName: "separator-class" }));
|
|
35
|
+
const homeItem = screen.getByText('Home');
|
|
36
|
+
fireEvent.click(homeItem);
|
|
37
|
+
expect(handleClick).toHaveBeenCalled();
|
|
38
|
+
});
|
|
39
|
+
it('should render without separators if none are provided', () => {
|
|
40
|
+
const items = [
|
|
41
|
+
{ label: 'Home' },
|
|
42
|
+
{ label: 'Library' },
|
|
43
|
+
];
|
|
44
|
+
render(React.createElement(Breadcrumb, { items: items, breadcrumbClassName: "breadcrumb-class", itemClassName: "item-class", separator: "" // Pass an empty string for separator
|
|
45
|
+
}));
|
|
46
|
+
// Check if breadcrumb items are rendered
|
|
47
|
+
items.forEach((item) => {
|
|
48
|
+
const itemElement = screen.getByText(item.label);
|
|
49
|
+
expect(itemElement).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
// Check that no separators are present by querying with the separator class name
|
|
52
|
+
const separators = screen.queryAllByRole('presentation');
|
|
53
|
+
expect(separators.length).toBe(0);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface ButtonProps {
|
|
3
|
+
label: string;
|
|
4
|
+
variant: 'text' | 'outlined' | 'contained';
|
|
5
|
+
color: 'primary' | 'secondary' | 'success' | 'error' | 'warning' | 'info';
|
|
6
|
+
size: 'small' | 'medium' | 'large';
|
|
7
|
+
handleClick: () => void;
|
|
8
|
+
}
|
|
9
|
+
declare const Button: React.FC<ButtonProps>;
|
|
10
|
+
export default Button;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import styles from './Button.module.scss';
|
|
3
|
+
const Button = ({ label, variant, color, size, handleClick, }) => {
|
|
4
|
+
return (React.createElement("button", { onClick: handleClick, className: `${styles.button} ${styles[variant]} ${styles[color]} ${styles[size]}` }, label));
|
|
5
|
+
};
|
|
6
|
+
export default Button;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import Button from './Button';
|
|
5
|
+
describe('Button Component', () => {
|
|
6
|
+
let handleClick;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
handleClick = jest.fn(); // Initialize the mock function before each test
|
|
9
|
+
});
|
|
10
|
+
const renderButton = (props = {}) => {
|
|
11
|
+
const defaultProps = {
|
|
12
|
+
label: 'Click Me',
|
|
13
|
+
variant: 'contained',
|
|
14
|
+
color: 'primary',
|
|
15
|
+
size: 'small',
|
|
16
|
+
handleClick: handleClick
|
|
17
|
+
};
|
|
18
|
+
return render(React.createElement(Button, { ...defaultProps }));
|
|
19
|
+
};
|
|
20
|
+
it('renders the button with the correct label', () => {
|
|
21
|
+
renderButton();
|
|
22
|
+
const buttonElement = screen.getByText('Click Me');
|
|
23
|
+
expect(buttonElement).toBeInTheDocument();
|
|
24
|
+
expect(buttonElement.tagName).toBe('BUTTON');
|
|
25
|
+
});
|
|
26
|
+
it('calls the handleClick function when the button is clicked', () => {
|
|
27
|
+
renderButton();
|
|
28
|
+
const buttonElement = screen.getByText('Click Me');
|
|
29
|
+
fireEvent.click(buttonElement);
|
|
30
|
+
expect(handleClick).toHaveBeenCalledTimes(1); // Ensure the mock function is called once
|
|
31
|
+
});
|
|
32
|
+
it('does not call handleClick when the button is not clicked', () => {
|
|
33
|
+
renderButton();
|
|
34
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface CustomCheckboxProps {
|
|
3
|
+
label?: string;
|
|
4
|
+
checked?: boolean;
|
|
5
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
6
|
+
className?: string;
|
|
7
|
+
checkboxClassName?: string;
|
|
8
|
+
labelClassName?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const CustomCheckbox: React.FC<CustomCheckboxProps>;
|
|
11
|
+
export default CustomCheckbox;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
const CustomCheckbox = ({ label, checked = false, onChange, className = '', checkboxClassName = '', labelClassName = '', ...rest }) => {
|
|
3
|
+
return (React.createElement("div", { className: className },
|
|
4
|
+
React.createElement("input", { type: "checkbox", checked: checked, onChange: onChange, className: checkboxClassName, ...rest }),
|
|
5
|
+
label && React.createElement("label", { className: labelClassName }, label)));
|
|
6
|
+
};
|
|
7
|
+
export default CustomCheckbox;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,59 @@
|
|
|
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';
|
|
5
|
+
describe('CustomCheckbox Component', () => {
|
|
6
|
+
let handleChange;
|
|
7
|
+
// Function to generate default props for each test
|
|
8
|
+
const getDefaultProps = () => ({
|
|
9
|
+
label: 'Accept Terms',
|
|
10
|
+
checked: false,
|
|
11
|
+
onChange: handleChange,
|
|
12
|
+
className: 'custom-container',
|
|
13
|
+
checkboxClassName: 'custom-checkbox',
|
|
14
|
+
labelClassName: 'custom-label',
|
|
15
|
+
});
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
handleChange = jest.fn(); // Reset the mock function before each test
|
|
18
|
+
});
|
|
19
|
+
it('renders the checkbox with a label', () => {
|
|
20
|
+
render(React.createElement(CustomCheckbox, { ...getDefaultProps() }));
|
|
21
|
+
const checkboxElement = screen.getByRole('checkbox');
|
|
22
|
+
const labelElement = screen.getByText('Accept Terms');
|
|
23
|
+
expect(checkboxElement).toBeInTheDocument();
|
|
24
|
+
expect(labelElement).toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
it('applies the correct className to the checkbox container', () => {
|
|
27
|
+
render(React.createElement(CustomCheckbox, { ...getDefaultProps() }));
|
|
28
|
+
const container = screen.getByRole('checkbox').parentElement;
|
|
29
|
+
expect(container).toHaveClass('custom-container');
|
|
30
|
+
});
|
|
31
|
+
it('applies the correct className to the checkbox', () => {
|
|
32
|
+
render(React.createElement(CustomCheckbox, { ...getDefaultProps() }));
|
|
33
|
+
const checkboxElement = screen.getByRole('checkbox');
|
|
34
|
+
expect(checkboxElement).toHaveClass('custom-checkbox');
|
|
35
|
+
});
|
|
36
|
+
it('applies the correct className to the label', () => {
|
|
37
|
+
render(React.createElement(CustomCheckbox, { ...getDefaultProps() }));
|
|
38
|
+
const labelElement = screen.getByText('Accept Terms');
|
|
39
|
+
expect(labelElement).toHaveClass('custom-label');
|
|
40
|
+
});
|
|
41
|
+
it('checks the checkbox based on the checked prop', () => {
|
|
42
|
+
render(React.createElement(CustomCheckbox, { ...getDefaultProps(), checked: true }));
|
|
43
|
+
const checkboxElement = screen.getByRole('checkbox');
|
|
44
|
+
expect(checkboxElement).toBeChecked();
|
|
45
|
+
});
|
|
46
|
+
it('calls the onChange function when the checkbox state changes', () => {
|
|
47
|
+
render(React.createElement(CustomCheckbox, { ...getDefaultProps(), checked: false }));
|
|
48
|
+
const checkboxElement = screen.getByRole('checkbox');
|
|
49
|
+
fireEvent.click(checkboxElement); // Toggle the checkbox
|
|
50
|
+
expect(handleChange).toHaveBeenCalledTimes(1);
|
|
51
|
+
});
|
|
52
|
+
it('renders correctly with different label', () => {
|
|
53
|
+
const newLabel = 'Agree to Privacy Policy';
|
|
54
|
+
render(React.createElement(CustomCheckbox, { ...getDefaultProps(), label: newLabel }));
|
|
55
|
+
const labelElement = screen.getByText(newLabel);
|
|
56
|
+
expect(labelElement).toBeInTheDocument();
|
|
57
|
+
expect(labelElement).toHaveTextContent(newLabel);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Checkbox";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Checkbox";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface CircularProgressProps {
|
|
3
|
+
value?: number;
|
|
4
|
+
variant?: 'determinate' | 'indeterminate';
|
|
5
|
+
color?: 'primary' | 'secondary' | 'error' | 'success' | 'info' | 'warning';
|
|
6
|
+
thickness?: number;
|
|
7
|
+
size?: number | string;
|
|
8
|
+
}
|
|
9
|
+
declare const CircularProgress: React.FC<CircularProgressProps>;
|
|
10
|
+
export default CircularProgress;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styles from './CircularProgress.module.scss';
|
|
3
|
+
const CircularProgress = ({ value = 0, variant = 'indeterminate', color = 'primary', thickness = 4, size = 100, }) => {
|
|
4
|
+
const isDeterminate = variant === 'determinate';
|
|
5
|
+
const rotationStyle = isDeterminate
|
|
6
|
+
? { transform: `rotate(${(value / 100) * 360}deg)` }
|
|
7
|
+
: {};
|
|
8
|
+
return (React.createElement("div", { className: `${styles.spinner} ${styles[color]}`, style: {
|
|
9
|
+
width: typeof size === 'number' ? `${size}px` : size,
|
|
10
|
+
height: typeof size === 'number' ? `${size}px` : size,
|
|
11
|
+
borderWidth: `${thickness}px`,
|
|
12
|
+
...rotationStyle,
|
|
13
|
+
} }));
|
|
14
|
+
};
|
|
15
|
+
export default CircularProgress;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import CircularProgress from "./CircularProgress";
|
|
4
|
+
describe("Loading Component", () => {
|
|
5
|
+
const renderComponent = (props) => render(React.createElement(CircularProgress, { ...props }));
|
|
6
|
+
it("applies the correct size and thickness", () => {
|
|
7
|
+
const { container } = renderComponent({ size: 60, thickness: 5 });
|
|
8
|
+
const spinner = container.firstChild;
|
|
9
|
+
expect(spinner).not.toBeNull();
|
|
10
|
+
expect(spinner.style.width).toBe("60px");
|
|
11
|
+
expect(spinner.style.height).toBe("60px");
|
|
12
|
+
expect(spinner.style.borderWidth).toBe("5px");
|
|
13
|
+
});
|
|
14
|
+
it("renders the determinate spinner with the correct rotation", () => {
|
|
15
|
+
const { container } = renderComponent({
|
|
16
|
+
variant: "determinate",
|
|
17
|
+
value: 75,
|
|
18
|
+
});
|
|
19
|
+
const spinner = container.firstChild;
|
|
20
|
+
const expectedRotation = `rotate(${(75 / 100) * 360}deg)`;
|
|
21
|
+
expect(spinner).not.toBeNull();
|
|
22
|
+
expect(spinner.style.transform).toBe(expectedRotation);
|
|
23
|
+
});
|
|
24
|
+
it("handles string size correctly", () => {
|
|
25
|
+
const { container } = renderComponent({ size: "50%" });
|
|
26
|
+
const spinner = container.firstChild;
|
|
27
|
+
expect(spinner).not.toBeNull();
|
|
28
|
+
expect(spinner.style.width).toBe("50%");
|
|
29
|
+
expect(spinner.style.height).toBe("50%");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DIVIDER_ORIENTATION } from "../Enum";
|
|
3
|
+
const CustomDivider = ({ orientation = DIVIDER_ORIENTATION.Horizontal, className = "", dividerClassName = "", ...rest }) => {
|
|
4
|
+
return (React.createElement("div", { className: `${className} ${orientation}`, ...rest },
|
|
5
|
+
React.createElement("div", { className: dividerClassName })));
|
|
6
|
+
};
|
|
7
|
+
export default CustomDivider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import CustomDivider from "./Divider";
|
|
4
|
+
import { DIVIDER_ORIENTATION } from "../Enum";
|
|
5
|
+
describe("CustomDivider Component", () => {
|
|
6
|
+
it("renders without crashing", () => {
|
|
7
|
+
const { container } = render(React.createElement(CustomDivider, null));
|
|
8
|
+
expect(container.firstChild).toBeTruthy();
|
|
9
|
+
});
|
|
10
|
+
it("applies the correct default orientation class", () => {
|
|
11
|
+
const { container } = render(React.createElement(CustomDivider, null));
|
|
12
|
+
expect(container.firstChild).toHaveClass(DIVIDER_ORIENTATION.Horizontal);
|
|
13
|
+
});
|
|
14
|
+
it("applies a custom orientation class", () => {
|
|
15
|
+
const { container } = render(React.createElement(CustomDivider, { orientation: DIVIDER_ORIENTATION.Vertical }));
|
|
16
|
+
expect(container.firstChild).toHaveClass(DIVIDER_ORIENTATION.Vertical);
|
|
17
|
+
});
|
|
18
|
+
it("applies the passed className to the outer div", () => {
|
|
19
|
+
const { container } = render(React.createElement(CustomDivider, { className: "custom-class" }));
|
|
20
|
+
expect(container.firstChild).toHaveClass("custom-class");
|
|
21
|
+
});
|
|
22
|
+
it("applies the passed dividerClassName to the inner div", () => {
|
|
23
|
+
const { container } = render(React.createElement(CustomDivider, { dividerClassName: "inner-class" }));
|
|
24
|
+
expect(container.firstChild?.firstChild).toHaveClass("inner-class");
|
|
25
|
+
});
|
|
26
|
+
it("passes additional props to the outer div", () => {
|
|
27
|
+
const { container } = render(React.createElement(CustomDivider, { "data-testid": "custom-divider" }));
|
|
28
|
+
expect(container.firstChild).toHaveAttribute("data-testid", "custom-divider");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Divider";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Divider";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const INPUT_TYPES: {
|
|
2
|
+
PASSWORD: string;
|
|
3
|
+
TEXT: string;
|
|
4
|
+
EMAIL: string;
|
|
5
|
+
NUMBER: string;
|
|
6
|
+
DATE: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const DIVIDER_ORIENTATION: {
|
|
9
|
+
Horizontal: string;
|
|
10
|
+
Vertical: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const LINK_TARGET: {
|
|
13
|
+
Self: string;
|
|
14
|
+
Blank: string;
|
|
15
|
+
Parent: string;
|
|
16
|
+
Top: string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const INPUT_TYPES = {
|
|
2
|
+
PASSWORD: 'password',
|
|
3
|
+
TEXT: 'text',
|
|
4
|
+
EMAIL: 'email',
|
|
5
|
+
NUMBER: 'number',
|
|
6
|
+
DATE: 'date',
|
|
7
|
+
};
|
|
8
|
+
export const DIVIDER_ORIENTATION = {
|
|
9
|
+
Horizontal: "horizontal",
|
|
10
|
+
Vertical: "vertical",
|
|
11
|
+
};
|
|
12
|
+
export const LINK_TARGET = {
|
|
13
|
+
Self: '_self',
|
|
14
|
+
Blank: '_blank',
|
|
15
|
+
Parent: '_parent',
|
|
16
|
+
Top: '_top',
|
|
17
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface CustomInputFieldProps {
|
|
3
|
+
label?: string;
|
|
4
|
+
value?: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
8
|
+
className?: string;
|
|
9
|
+
inputClassName?: string;
|
|
10
|
+
labelClassName?: string;
|
|
11
|
+
error?: string;
|
|
12
|
+
errorClassName?: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
}
|
|
15
|
+
declare const CustomInputField: React.FC<CustomInputFieldProps>;
|
|
16
|
+
export default CustomInputField;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { INPUT_TYPES } from '../Enum';
|
|
3
|
+
const CustomInputField = ({ label, value = '', type = INPUT_TYPES.TEXT, placeholder = '', onChange, className = '', inputClassName = '', labelClassName = '', error = '', errorClassName = '', ...rest }) => {
|
|
4
|
+
return (React.createElement("div", { className: className },
|
|
5
|
+
label && React.createElement("label", { className: labelClassName }, label),
|
|
6
|
+
React.createElement("input", { type: type, value: value, placeholder: placeholder, onChange: onChange, className: inputClassName, ...rest }),
|
|
7
|
+
error && React.createElement("div", { className: errorClassName }, error)));
|
|
8
|
+
};
|
|
9
|
+
export default CustomInputField;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|