dhre-component-lib 0.0.8 → 0.0.9
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/package.json +6 -3
- package/jest.config.ts +0 -10
- package/rollup.config.mjs +0 -37
- package/setupTests.ts +0 -1
- package/src/__mocks__/styleMock.js +0 -1
- package/src/components/Avatar/Avatar.test.tsx +0 -53
- package/src/components/Avatar/Avatar.tsx +0 -28
- package/src/components/Avatar/index.ts +0 -1
- package/src/components/Badge/Badge.module.scss +0 -14
- package/src/components/Badge/Badge.test.tsx +0 -59
- package/src/components/Badge/Badge.tsx +0 -25
- package/src/components/Badge/index.ts +0 -1
- package/src/components/BreadCrumb/BreadCrumb.test.tsx +0 -90
- package/src/components/BreadCrumb/BreadCrumb.tsx +0 -45
- package/src/components/BreadCrumb/Breadcrumb.module.scss +0 -20
- package/src/components/BreadCrumb/index.ts +0 -1
- package/src/components/Button/Button.module.scss +0 -66
- package/src/components/Button/Button.test.tsx +0 -49
- package/src/components/Button/Button.tsx +0 -29
- package/src/components/Button/index.ts +0 -1
- package/src/components/Checkbox/Checkbox.test.tsx +0 -93
- package/src/components/Checkbox/Checkbox.tsx +0 -35
- package/src/components/Checkbox/index.ts +0 -1
- package/src/components/CircularProgress/CircularProgress.module.scss +0 -19
- package/src/components/CircularProgress/CircularProgress.test.tsx +0 -39
- package/src/components/CircularProgress/CircularProgress.tsx +0 -37
- package/src/components/CircularProgress/index.ts +0 -1
- package/src/components/Divider/Divider.test.tsx +0 -44
- package/src/components/Divider/Divider.tsx +0 -24
- package/src/components/Divider/index.ts +0 -1
- package/src/components/Enum.ts +0 -19
- package/src/components/InputTextField/InputTextField.test.tsx +0 -118
- package/src/components/InputTextField/InputTextField.tsx +0 -48
- package/src/components/InputTextField/index.ts +0 -1
- package/src/components/Link/Link.test.tsx +0 -55
- package/src/components/Link/Link.tsx +0 -33
- package/src/components/Link/index.ts +0 -1
- package/src/components/Map/Directions.tsx +0 -36
- package/src/components/Map/GoogleMap.module.scss +0 -5
- package/src/components/Map/GoogleMap.tsx +0 -186
- package/src/components/Map/GoogleMapsLoader.tsx +0 -12
- package/src/components/Map/index.ts +0 -2
- package/src/components/Modal/Modal.module.scss +0 -26
- package/src/components/Modal/Modal.test.tsx +0 -74
- package/src/components/Modal/Modal.tsx +0 -39
- package/src/components/Modal/index.ts +0 -1
- package/src/components/Notification/Notification.module.scss +0 -20
- package/src/components/Notification/Notification.test.tsx +0 -53
- package/src/components/Notification/Notification.tsx +0 -42
- package/src/components/Notification/index.ts +0 -1
- package/src/components/OtpInput/OtpInput.module.scss +0 -49
- package/src/components/OtpInput/OtpInput.test.tsx +0 -53
- package/src/components/OtpInput/OtpInput.tsx +0 -137
- package/src/components/OtpInput/index.ts +0 -1
- package/src/components/PdfView/PdfView.module.scss +0 -69
- package/src/components/PdfView/PdfView.test.tsx +0 -52
- package/src/components/PdfView/PdfView.tsx +0 -116
- package/src/components/PdfView/index.ts +0 -1
- package/src/components/Progress/Progress.test.tsx +0 -43
- package/src/components/Progress/Progress.tsx +0 -35
- package/src/components/Progress/index.ts +0 -1
- package/src/components/RadioButton/RadioButton.test.tsx +0 -56
- package/src/components/RadioButton/RadioButton.tsx +0 -43
- package/src/components/RadioButton/index.ts +0 -1
- package/src/components/Switch/Switch.test.tsx +0 -83
- package/src/components/Switch/Switch.tsx +0 -38
- package/src/components/Switch/index.ts +0 -1
- package/src/components/Tag/Tag.css +0 -14
- package/src/components/Tag/Tag.test.tsx +0 -61
- package/src/components/Tag/Tag.tsx +0 -19
- package/src/components/Tag/index.ts +0 -1
- package/src/components/Tooltip/Tooltip.module.scss +0 -37
- package/src/components/Tooltip/Tooltip.test.tsx +0 -68
- package/src/components/Tooltip/Tooltip.tsx +0 -38
- package/src/components/Tooltip/index.ts +0 -1
- package/src/components/index.ts +0 -15
- package/src/index.ts +0 -1
- package/src/theme/Typography/typography.scss +0 -117
- package/src/theme/colors/colors.scss +0 -22
- package/src/theme/colors.ts +0 -3
- package/src/typings.d.ts +0 -1
- package/tsconfig.json +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dhre-component-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -49,7 +49,10 @@
|
|
|
49
49
|
"react": "^18.3.1",
|
|
50
50
|
"react-dom": "^18.3.1"
|
|
51
51
|
},
|
|
52
|
-
"main": "dist/
|
|
52
|
+
"main": "dist/index.js",
|
|
53
53
|
"module": "dist/esm/index.js",
|
|
54
|
-
"types": "dist/index.d.ts"
|
|
54
|
+
"types": "dist/index.d.ts",
|
|
55
|
+
"files": [
|
|
56
|
+
"dist"
|
|
57
|
+
]
|
|
55
58
|
}
|
package/jest.config.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
require('ts-node').register();
|
|
2
|
-
module.exports = {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'jsdom',
|
|
5
|
-
setupFilesAfterEnv: ['./setupTests.ts'],
|
|
6
|
-
moduleNameMapper: {
|
|
7
|
-
'\\.(css|less|sass|scss)$': '<rootDir>/src/__mocks__/styleMock.js', // Mock CSS files
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
|
package/rollup.config.mjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import resolve from "@rollup/plugin-node-resolve";
|
|
2
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
3
|
-
import typescript from "@rollup/plugin-typescript";
|
|
4
|
-
import dts from "rollup-plugin-dts";
|
|
5
|
-
import PeerDepsExternalPlugin from 'rollup-plugin-peer-deps-external';
|
|
6
|
-
|
|
7
|
-
import packageJson from "./package.json" assert { type: "json" };
|
|
8
|
-
|
|
9
|
-
export default [
|
|
10
|
-
{
|
|
11
|
-
input: "src/index.ts",
|
|
12
|
-
output: [
|
|
13
|
-
{
|
|
14
|
-
file: packageJson.main,
|
|
15
|
-
format: "cjs",
|
|
16
|
-
sourcemap: true,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
file: packageJson.module,
|
|
20
|
-
format: "esm",
|
|
21
|
-
sourcemap: true,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
plugins: [
|
|
25
|
-
resolve(),
|
|
26
|
-
commonjs(),
|
|
27
|
-
typescript({ tsconfig: "./tsconfig.json" }),
|
|
28
|
-
PeerDepsExternalPlugin(),
|
|
29
|
-
],
|
|
30
|
-
//external: ['react', 'react-dom', '@mui/material', '@emotion/react', '@emotion/styled'],
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
input: "dist/esm/types/index.d.ts",
|
|
34
|
-
output: [{ file: "dist/index.d.ts", format: "esm" }],
|
|
35
|
-
plugins: [dts()],
|
|
36
|
-
},
|
|
37
|
-
];
|
package/setupTests.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen, fireEvent } 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('renders correctly without crashing', () => {
|
|
48
|
-
render(<Avatar {...defaultProps} />);
|
|
49
|
-
|
|
50
|
-
const imgElement = screen.getByAltText(defaultProps.alt);
|
|
51
|
-
expect(imgElement).toBeInTheDocument();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
export interface AvatarProps {
|
|
4
|
-
src: string;
|
|
5
|
-
alt: string;
|
|
6
|
-
imgClassName: string;
|
|
7
|
-
handleClick?: () => void;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const Avatar: React.FC<AvatarProps> = ({
|
|
11
|
-
src,
|
|
12
|
-
alt,
|
|
13
|
-
imgClassName,
|
|
14
|
-
handleClick,
|
|
15
|
-
}) => {
|
|
16
|
-
return (
|
|
17
|
-
<button onClick={handleClick}>
|
|
18
|
-
<img
|
|
19
|
-
src={src}
|
|
20
|
-
alt={alt}
|
|
21
|
-
|
|
22
|
-
className={imgClassName}
|
|
23
|
-
/>
|
|
24
|
-
</button>
|
|
25
|
-
);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default Avatar;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Avatar";
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen, fireEvent } 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('handles the onClick event correctly', () => {
|
|
21
|
-
const handleClick = jest.fn();
|
|
22
|
-
render(<Badge {...defaultProps} handleClick={handleClick} />);
|
|
23
|
-
|
|
24
|
-
const badgeElement = screen.getByText(defaultProps.content as string);
|
|
25
|
-
fireEvent.click(badgeElement);
|
|
26
|
-
|
|
27
|
-
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('does not crash without handleClick prop', () => {
|
|
31
|
-
render(<Badge {...defaultProps} />);
|
|
32
|
-
|
|
33
|
-
const badgeElement = screen.getByText(defaultProps.content as string);
|
|
34
|
-
expect(() => fireEvent.click(badgeElement)).not.toThrow();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('renders correctly with numeric content', () => {
|
|
38
|
-
const numericProps: BadgeProps = {
|
|
39
|
-
...defaultProps,
|
|
40
|
-
content: 99,
|
|
41
|
-
};
|
|
42
|
-
render(<Badge {...numericProps} />);
|
|
43
|
-
|
|
44
|
-
const badgeElement = screen.getByText(numericProps.content.toString());
|
|
45
|
-
|
|
46
|
-
expect(badgeElement).toBeInTheDocument();
|
|
47
|
-
expect(badgeElement).toHaveTextContent('99');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('renders correctly with different content', () => {
|
|
51
|
-
const newContent = 'Updated Badge';
|
|
52
|
-
render(<Badge {...defaultProps} content={newContent} />);
|
|
53
|
-
|
|
54
|
-
const badgeElement = screen.getByText(newContent);
|
|
55
|
-
|
|
56
|
-
expect(badgeElement).toBeInTheDocument();
|
|
57
|
-
expect(badgeElement).toHaveTextContent(newContent);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import styles from './Badge.module.scss';
|
|
3
|
-
|
|
4
|
-
export interface BadgeProps {
|
|
5
|
-
content: string | number;
|
|
6
|
-
badgeClassName?: string;
|
|
7
|
-
handleClick?: () => void;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const Badge: React.FC<BadgeProps> = ({
|
|
11
|
-
content,
|
|
12
|
-
badgeClassName,
|
|
13
|
-
handleClick,
|
|
14
|
-
}) => {
|
|
15
|
-
return (
|
|
16
|
-
<button
|
|
17
|
-
onClick={handleClick}
|
|
18
|
-
className={`${styles.badge} ${badgeClassName}`}
|
|
19
|
-
>
|
|
20
|
-
{content}
|
|
21
|
-
</button>
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default Badge;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Badge";
|
|
@@ -1,90 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import styles from './Breadcrumb.module.scss';
|
|
3
|
-
|
|
4
|
-
export interface BreadcrumbItem {
|
|
5
|
-
label: string;
|
|
6
|
-
handleClick?: () => void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface BreadcrumbProps {
|
|
10
|
-
items: BreadcrumbItem[];
|
|
11
|
-
breadcrumbClassName: string;
|
|
12
|
-
itemClassName?: string;
|
|
13
|
-
separator?: string;
|
|
14
|
-
separatorClassName?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const Breadcrumb: React.FC<BreadcrumbProps> = ({
|
|
18
|
-
items,
|
|
19
|
-
breadcrumbClassName,
|
|
20
|
-
itemClassName,
|
|
21
|
-
separator = "/",
|
|
22
|
-
separatorClassName,
|
|
23
|
-
}) => {
|
|
24
|
-
return (
|
|
25
|
-
<nav className={`${styles.breadcrumb} ${breadcrumbClassName}`}>
|
|
26
|
-
{items.map((item, index) => (
|
|
27
|
-
<React.Fragment key={index}>
|
|
28
|
-
<button
|
|
29
|
-
className={`${styles.breadcrumbItem} ${itemClassName}`}
|
|
30
|
-
onClick={item.handleClick}
|
|
31
|
-
>
|
|
32
|
-
{item.label}
|
|
33
|
-
</button>
|
|
34
|
-
{index < items.length - 1 && (
|
|
35
|
-
<span className={`${styles.separator} ${separatorClassName}`}>
|
|
36
|
-
{separator}
|
|
37
|
-
</span>
|
|
38
|
-
)}
|
|
39
|
-
</React.Fragment>
|
|
40
|
-
))}
|
|
41
|
-
</nav>
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default Breadcrumb;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
.breadcrumb {
|
|
2
|
-
display: flex;
|
|
3
|
-
align-items: center;
|
|
4
|
-
font-size: 16px;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.breadcrumbItem {
|
|
8
|
-
color: blue;
|
|
9
|
-
cursor: pointer;
|
|
10
|
-
margin-right: 8px;
|
|
11
|
-
|
|
12
|
-
&:hover {
|
|
13
|
-
text-decoration: underline;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.separator {
|
|
18
|
-
margin: 0 8px;
|
|
19
|
-
color: grey;
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./BreadCrumb";
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/* Base button styling */
|
|
2
|
-
.button {
|
|
3
|
-
padding: 8px 16px;
|
|
4
|
-
font-size: 14px;
|
|
5
|
-
border-radius: 4px;
|
|
6
|
-
border: none;
|
|
7
|
-
cursor: pointer;
|
|
8
|
-
transition: background-color 0.3s ease;
|
|
9
|
-
|
|
10
|
-
&.text {
|
|
11
|
-
background-color: transparent;
|
|
12
|
-
color: inherit;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
&.outlined {
|
|
16
|
-
background-color: transparent;
|
|
17
|
-
border: 2px solid currentColor;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
&.contained {
|
|
21
|
-
background-color: currentColor;
|
|
22
|
-
color: #fff;
|
|
23
|
-
|
|
24
|
-
&.primary:hover {
|
|
25
|
-
background-color: #1565c0;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
&.secondary:hover {
|
|
29
|
-
background-color: #7b1fa2;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
&.success:hover {
|
|
33
|
-
background-color: #388e3c;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
&.error:hover {
|
|
37
|
-
background-color: #d32f2f;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
&.warning:hover {
|
|
41
|
-
background-color: #f57c00;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
&.info:hover {
|
|
45
|
-
background-color: #1976d2;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
&.primary {
|
|
50
|
-
color: #1976d2;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
&.secondary {
|
|
54
|
-
color: #9c27b0;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
&.success {
|
|
58
|
-
color: #4caf50;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
&.error {
|
|
62
|
-
color: #f44336;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
&.warning {
|
|
66
|
-
color:
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
variant: 'contained',
|
|
17
|
-
color: 'primary',
|
|
18
|
-
size: 'small',
|
|
19
|
-
handleClick: handleClick
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return render(<Button {...defaultProps} />);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
it('renders the button with the correct label', () => {
|
|
26
|
-
renderButton();
|
|
27
|
-
|
|
28
|
-
const buttonElement = screen.getByText('Click Me');
|
|
29
|
-
|
|
30
|
-
expect(buttonElement).toBeInTheDocument();
|
|
31
|
-
expect(buttonElement.tagName).toBe('BUTTON');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('calls the handleClick function when the button is clicked', () => {
|
|
35
|
-
renderButton();
|
|
36
|
-
|
|
37
|
-
const buttonElement = screen.getByText('Click Me');
|
|
38
|
-
|
|
39
|
-
fireEvent.click(buttonElement);
|
|
40
|
-
|
|
41
|
-
expect(handleClick).toHaveBeenCalledTimes(1); // Ensure the mock function is called once
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('does not call handleClick when the button is not clicked', () => {
|
|
45
|
-
renderButton();
|
|
46
|
-
|
|
47
|
-
expect(handleClick).not.toHaveBeenCalled();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import styles from './Button.module.scss';
|
|
3
|
-
|
|
4
|
-
export interface ButtonProps {
|
|
5
|
-
label: string;
|
|
6
|
-
variant: 'text' | 'outlined' | 'contained';
|
|
7
|
-
color: 'primary' | 'secondary' | 'success' | 'error' | 'warning' | 'info';
|
|
8
|
-
size: 'small' | 'medium' | 'large';
|
|
9
|
-
handleClick: () => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const Button: React.FC<ButtonProps> = ({
|
|
13
|
-
label,
|
|
14
|
-
variant,
|
|
15
|
-
color,
|
|
16
|
-
size,
|
|
17
|
-
handleClick,
|
|
18
|
-
}) => {
|
|
19
|
-
return (
|
|
20
|
-
<button
|
|
21
|
-
onClick={handleClick}
|
|
22
|
-
className={`${styles.button} ${styles[variant]} ${styles[color]} ${styles[size]}`}
|
|
23
|
-
>
|
|
24
|
-
{label}
|
|
25
|
-
</button>
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default Button;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Button";
|
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
|
|
6
|
-
interface CustomCheckboxProps {
|
|
7
|
-
label?: string;
|
|
8
|
-
checked?: boolean;
|
|
9
|
-
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
10
|
-
className?: string;
|
|
11
|
-
checkboxClassName?: string;
|
|
12
|
-
labelClassName?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('CustomCheckbox Component', () => {
|
|
16
|
-
let handleChange: jest.Mock;
|
|
17
|
-
|
|
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',
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
handleChange = jest.fn(); // Reset the mock function before each test
|
|
30
|
-
});
|
|
31
|
-
|
|
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();
|
|
40
|
-
});
|
|
41
|
-
|
|
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
|
-
});
|
|
49
|
-
|
|
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');
|
|
56
|
-
});
|
|
57
|
-
|
|
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
|
-
});
|
|
65
|
-
|
|
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();
|
|
72
|
-
});
|
|
73
|
-
|
|
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
|
-
});
|
|
83
|
-
|
|
84
|
-
it('renders correctly with different label', () => {
|
|
85
|
-
const newLabel = 'Agree to Privacy Policy';
|
|
86
|
-
render(<CustomCheckbox {...getDefaultProps()} label={newLabel} />);
|
|
87
|
-
|
|
88
|
-
const labelElement = screen.getByText(newLabel);
|
|
89
|
-
|
|
90
|
-
expect(labelElement).toBeInTheDocument();
|
|
91
|
-
expect(labelElement).toHaveTextContent(newLabel);
|
|
92
|
-
});
|
|
93
|
-
});
|