dhre-component-lib 0.0.1 → 0.0.2

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.
Files changed (90) hide show
  1. package/coverage/clover.xml +260 -0
  2. package/coverage/coverage-final.json +19 -0
  3. package/coverage/lcov-report/base.css +224 -0
  4. package/coverage/lcov-report/block-navigation.js +87 -0
  5. package/coverage/lcov-report/components/Avatar/Avatar.tsx.html +163 -0
  6. package/coverage/lcov-report/components/Avatar/index.html +116 -0
  7. package/coverage/lcov-report/components/Badge/Badge.tsx.html +160 -0
  8. package/coverage/lcov-report/components/Badge/index.html +116 -0
  9. package/coverage/lcov-report/components/BreadCrumb/BreadCrumb.tsx.html +193 -0
  10. package/coverage/lcov-report/components/BreadCrumb/index.html +116 -0
  11. package/coverage/lcov-report/components/Button/Button.tsx.html +151 -0
  12. package/coverage/lcov-report/components/Button/index.html +116 -0
  13. package/coverage/lcov-report/components/Checkbox/Checkbox.tsx.html +190 -0
  14. package/coverage/lcov-report/components/Checkbox/index.html +116 -0
  15. package/coverage/lcov-report/components/CircularProgress/CircularProgress.tsx.html +196 -0
  16. package/coverage/lcov-report/components/CircularProgress/index.html +116 -0
  17. package/coverage/lcov-report/components/Divider/Divider.tsx.html +157 -0
  18. package/coverage/lcov-report/components/Divider/index.html +116 -0
  19. package/coverage/lcov-report/components/Enum.ts.html +142 -0
  20. package/coverage/lcov-report/components/InputTextField/InputTextField.tsx.html +229 -0
  21. package/coverage/lcov-report/components/InputTextField/index.html +116 -0
  22. package/coverage/lcov-report/components/Link/Link.tsx.html +184 -0
  23. package/coverage/lcov-report/components/Link/index.html +116 -0
  24. package/coverage/lcov-report/components/Modal/Modal.tsx.html +169 -0
  25. package/coverage/lcov-report/components/Modal/index.html +116 -0
  26. package/coverage/lcov-report/components/Notification/Notification.tsx.html +208 -0
  27. package/coverage/lcov-report/components/Notification/index.html +116 -0
  28. package/coverage/lcov-report/components/PdfView/PdfView.tsx.html +400 -0
  29. package/coverage/lcov-report/components/PdfView/index.html +116 -0
  30. package/coverage/lcov-report/components/Progress/Progress.tsx.html +190 -0
  31. package/coverage/lcov-report/components/Progress/index.html +116 -0
  32. package/coverage/lcov-report/components/RadioButton/RadioButton.tsx.html +214 -0
  33. package/coverage/lcov-report/components/RadioButton/index.html +116 -0
  34. package/coverage/lcov-report/components/Switch/Switch.tsx.html +199 -0
  35. package/coverage/lcov-report/components/Switch/index.html +116 -0
  36. package/coverage/lcov-report/components/Tag/Tag.tsx.html +160 -0
  37. package/coverage/lcov-report/components/Tag/index.html +116 -0
  38. package/coverage/lcov-report/components/Tooltip/Tooltip.tsx.html +187 -0
  39. package/coverage/lcov-report/components/Tooltip/index.html +116 -0
  40. package/coverage/lcov-report/components/index.html +116 -0
  41. package/coverage/lcov-report/favicon.png +0 -0
  42. package/coverage/lcov-report/index.html +371 -0
  43. package/coverage/lcov-report/prettify.css +1 -0
  44. package/coverage/lcov-report/prettify.js +2 -0
  45. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  46. package/coverage/lcov-report/sorter.js +196 -0
  47. package/coverage/lcov.info +457 -0
  48. package/jest.config.ts +1 -1
  49. package/package.json +9 -6
  50. package/src/components/Avatar/Avatar.test.tsx +52 -0
  51. package/src/components/Avatar/__snapshots__/Avatar.test.tsx.snap +9 -0
  52. package/src/components/Badge/Badge.test.tsx +63 -0
  53. package/src/components/Badge/__snapshots__/Badge.test.tsx.snap +9 -0
  54. package/src/components/BreadCrumb/BreadCrumb.test.tsx +90 -0
  55. package/src/components/BreadCrumb/index.ts +1 -0
  56. package/src/components/Button/Button.test.tsx +62 -0
  57. package/src/components/Button/__snapshots__/Button.test.tsx.snap +9 -0
  58. package/src/components/Checkbox/Checkbox.test.tsx +71 -43
  59. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +17 -0
  60. package/src/components/{Circular_Progress → CircularProgress}/CircularProgress.tsx +1 -1
  61. package/src/components/Divider/Divider.test.tsx +35 -10
  62. package/src/components/InputTextField/InputTextField.test.tsx +103 -33
  63. package/src/components/InputTextField/InputTextField.tsx +7 -5
  64. package/src/components/Link/Link.test.tsx +44 -36
  65. package/src/components/Link/Link.tsx +1 -1
  66. package/src/components/Map/Directions.tsx +36 -0
  67. package/src/components/Map/GoogleMap.module.scss +5 -0
  68. package/src/components/Map/GoogleMap.tsx +186 -0
  69. package/src/components/Map/GoogleMapsLoader.tsx +12 -0
  70. package/src/components/Map/index.ts +2 -0
  71. package/src/components/Modal/Modal.css +26 -0
  72. package/src/components/Modal/Modal.test.tsx +53 -34
  73. package/src/components/Modal/Modal.tsx +15 -6
  74. package/src/components/PdfView/PdfView.css +70 -0
  75. package/src/components/PdfView/PdfView.test.tsx +27 -63
  76. package/src/components/PdfView/PdfView.tsx +53 -41
  77. package/src/components/Progress/Progress.test.tsx +34 -26
  78. package/src/components/Progress/Progress.tsx +2 -2
  79. package/src/components/RadioButton/RadioButton.test.tsx +59 -30
  80. package/src/components/Switch/Switch.test.tsx +83 -0
  81. package/src/components/Tag/Tag.test.tsx +57 -0
  82. package/src/components/Tag/__snapshots__/Tag.test.tsx.snap +9 -0
  83. package/src/components/Tooltip/Tooltip.test.tsx +73 -0
  84. package/src/components/Tooltip/__snapshots__/Tooltip.test.tsx.snap +22 -0
  85. package/src/components/index.ts +5 -2
  86. package/src/typings.d.ts +1 -0
  87. package/tsconfig.json +17 -18
  88. /package/src/components/{Circular_Progress → CircularProgress}/CircularProgress.css +0 -0
  89. /package/src/components/{Circular_Progress → CircularProgress}/CircularProgress.test.tsx +0 -0
  90. /package/src/components/{Circular_Progress → CircularProgress}/index.ts +0 -0
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { Button, Box, CircularProgress, Typography } from '@mui/material';
1
+ import React, { useEffect } from "react";
2
+ import './PdfView.css';
3
3
 
4
4
  export interface PdfViewerProps {
5
5
  content: string;
@@ -7,14 +7,14 @@ export interface PdfViewerProps {
7
7
  buttonText?: string;
8
8
  loadingText?: string;
9
9
  errorText?: string;
10
- onError?: (error: Error) => void;
10
+ // onError?: (error: Error) => void;
11
11
  cleanUpDelay?: number;
12
- buttonVariant?: 'text' | 'outlined' | 'contained';
13
- buttonColor?: 'inherit' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning'; // Removed "default"
14
- buttonSize?: 'small' | 'medium' | 'large';
12
+ buttonVariant?: "text" | "outlined" | "contained";
13
+ buttonColor?: "inherit" | "primary" | "secondary" | "error" | "info" | "success" | "warning";
14
+ buttonSize?: "small" | "medium" | "large";
15
15
  showLoadingSpinner?: boolean;
16
16
  spinnerSize?: number;
17
- spinnerColor?: 'inherit' | 'primary' | 'secondary';
17
+ spinnerColor?: "inherit" | "primary" | "secondary";
18
18
  className?: string;
19
19
  }
20
20
 
@@ -24,10 +24,10 @@ const PdfView: React.FC<PdfViewerProps> = ({
24
24
  buttonText = "View PDF",
25
25
  loadingText = "Loading...",
26
26
  errorText = "Failed to load PDF",
27
- onError,
27
+
28
28
  cleanUpDelay = 1000,
29
29
  buttonVariant = "contained",
30
- buttonColor = "primary", // Changed to a valid default
30
+ buttonColor = "primary",
31
31
  buttonSize = "medium",
32
32
  showLoadingSpinner = false,
33
33
  spinnerSize = 24,
@@ -36,58 +36,70 @@ const PdfView: React.FC<PdfViewerProps> = ({
36
36
  }) => {
37
37
  const [isLoading, setIsLoading] = React.useState(false);
38
38
  const [isError, setIsError] = React.useState(false);
39
+ const [errorMsg, setErrorMsg] = React.useState(errorText);
40
+
41
+ useEffect(() => {
42
+ if (btoa(atob(content)) !== content) {
43
+ setIsError(true);
44
+ }
45
+ }, [content]);
46
+
47
+ const base64ToBlob = (content: string, contentType: string = "application/pdf"): Blob | null => {
48
+ try {
49
+ const byteCharacters = atob(content);
50
+ const byteArray = new Uint8Array(byteCharacters.length);
51
+
52
+ for (let i = 0; i < byteCharacters.length; i++) {
53
+ byteArray[i] = byteCharacters.charCodeAt(i);
54
+ }
55
+
56
+ return new Blob([byteArray], { type: contentType });
57
+ } catch (error) {
58
+ setIsError(true);
59
+ setErrorMsg("Invalid base64 string:");
60
+ return null;
61
+ }
62
+ };
39
63
 
40
64
  const handleViewPdf = async () => {
41
65
  setIsLoading(true);
42
66
  setIsError(false);
43
- try {
44
- const blob = base64ToBlob(content, contentType);
67
+ const blob = base64ToBlob(content, contentType);
68
+ if (blob) {
45
69
  const url = URL.createObjectURL(blob);
46
70
 
47
- window.open(url, '_blank');
48
-
71
+ window.open(url, "_blank");
72
+
49
73
  setTimeout(() => {
50
74
  URL.revokeObjectURL(url);
51
75
  }, cleanUpDelay);
52
- } catch (error) {
53
- setIsError(true);
54
- if (onError) {
55
- onError(error as Error);
56
- } else {
57
- console.error("Error generating PDF URL:", error);
58
- }
59
- } finally {
60
76
  setIsLoading(false);
77
+ } else {
78
+ setIsLoading(false);
79
+ setIsError(true);
80
+ setErrorMsg("Failed to create Blob from base64 string.");
61
81
  }
62
82
  };
63
83
 
64
84
  return (
65
- <Box className={className} display="flex" flexDirection="column" alignItems="center" justifyContent="center">
66
- {isLoading && showLoadingSpinner && <CircularProgress size={spinnerSize} color={spinnerColor} />}
67
- {isError && <Typography color="error">{errorText}</Typography>}
85
+ <div className={`${className} container`}>
86
+ {isLoading && showLoadingSpinner && (
87
+ <div data-testid="spinnertest" className="spinner" style={{ width: spinnerSize, height: spinnerSize, borderColor: spinnerColor }}>
88
+ <div className="spinner-inner"></div>
89
+ </div>
90
+ )}
91
+ {isError && <p className="error-text">{errorMsg}</p>}
68
92
  {!isLoading && !isError && (
69
- <Button
93
+ <button
70
94
  onClick={handleViewPdf}
71
- variant={buttonVariant}
72
- color={buttonColor} // Ensure only valid options are passed
73
- size={buttonSize}
95
+ className={`button button-${buttonVariant} button-${buttonColor} button-${buttonSize}`}
74
96
  >
75
97
  {buttonText}
76
- </Button>
98
+ </button>
77
99
  )}
78
- {isLoading && <Typography>{loadingText}</Typography>}
79
- </Box>
100
+ {isLoading && !showLoadingSpinner && <p>{loadingText}</p>}
101
+ </div>
80
102
  );
81
103
  };
82
104
 
83
- const base64ToBlob = (content: string, contentType: string = 'application/pdf'): Blob => {
84
- const byteCharacters = atob(content);
85
- const byteNumbers = new Array(byteCharacters.length);
86
- for (let i = 0; i < byteCharacters.length; i++) {
87
- byteNumbers[i] = byteCharacters.charCodeAt(i);
88
- }
89
- const byteArray = new Uint8Array(byteNumbers);
90
- return new Blob([byteArray], { type: contentType });
91
- };
92
-
93
105
  export default PdfView;
@@ -1,35 +1,43 @@
1
- import React from "react";
2
- import { render, screen } from "@testing-library/react";
3
- import Progress from "./Progress";
4
-
5
- describe("Progress Component", () => {
6
- it("should render without crashing", () => {
7
- render(<Progress value={50} />);
8
- const progressElement = screen.getByRole("progressbar");
9
- expect(progressElement).toBeInTheDocument();
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import '@testing-library/jest-dom';
4
+ import Progress from './Progress';
5
+
6
+ describe('Progress Component', () => {
7
+ it('renders the progress bar with correct percentage width', () => {
8
+ render(<Progress value={50} max={100} barClassName="progress-bar" />);
9
+ const progressBar = screen.getByTestId('progress-bar');
10
+ expect(progressBar).toHaveStyle('width: 50%');
10
11
  });
11
12
 
12
- it("should render with default props", () => {
13
- render(<Progress value={50} />);
14
- const progressElement = screen.getByRole("progressbar");
15
- expect(progressElement).toHaveClass("MuiLinearProgress-colorPrimary");
13
+ it('renders the label when provided', () => {
14
+ render(<Progress value={30} max={100} label="Loading" labelClassName="label-class" />);
15
+ expect(screen.getByText('Loading')).toHaveClass('label-class');
16
16
  });
17
17
 
18
- it("should render with custom variant", () => {
19
- render(<Progress value={50} variant="determinate" />);
20
- const progressElement = screen.getByRole("progressbar");
21
- expect(progressElement).toHaveClass("MuiLinearProgress-determinate");
18
+ it('does not render the label when not provided', () => {
19
+ render(<Progress value={30} max={100} />);
20
+ expect(screen.queryByText('Loading')).not.toBeInTheDocument();
22
21
  });
23
22
 
24
- it("should render with custom color", () => {
25
- render(<Progress value={50} color="secondary" />);
26
- const progressElement = screen.getByRole("progressbar");
27
- expect(progressElement).toHaveClass("MuiLinearProgress-colorSecondary");
23
+
24
+
25
+ it('handles zero values correctly', () => {
26
+ render(<Progress value={0} max={100} barClassName="progress-bar" />);
27
+ const progressBar = screen.getByTestId('progress-bar');
28
+ expect(progressBar).toHaveStyle('width: 0%');
28
29
  });
29
30
 
30
- it("should apply custom size", () => {
31
- render(<Progress value={50} size={150} />);
32
- const progressElement = screen.getByRole("progressbar");
33
- expect(progressElement).toHaveStyle({ width: "150px", height: "150px" });
31
+ it('handles max values correctly', () => {
32
+ render(<Progress value={100} max={100} barClassName="progress-bar" />);
33
+ const progressBar = screen.getByTestId('progress-bar');
34
+ expect(progressBar).toHaveStyle('width: 100%');
34
35
  });
35
- });
36
+
37
+ it('handles values greater than max', () => {
38
+ render(<Progress value={150} max={100} barClassName="progress-bar" />);
39
+ const progressBar = screen.getByTestId('progress-bar');
40
+ expect(progressBar).toHaveStyle('width: 150%'); // Matches the component's behavior
41
+ });
42
+
43
+ })
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- interface ProgressProps {
3
+ export interface ProgressProps {
4
4
  value: number;
5
5
  max: number;
6
6
  className?: string;
@@ -26,7 +26,7 @@ const Progress: React.FC<ProgressProps> = ({
26
26
  <div className={className} {...rest}>
27
27
  {label && <div className={labelClassName}>{label}</div>}
28
28
  <div className={barContainerClassName}>
29
- <div className={barClassName} style={{ width: `${percentage}%` }} />
29
+ <div data-testid="progress-bar" className={barClassName} style={{ width: `${percentage}%` }} />
30
30
  </div>
31
31
  </div>
32
32
  );
@@ -1,38 +1,67 @@
1
- import React from "react";
2
- import { render, screen, fireEvent } from "@testing-library/react";
3
- import RadioButton from "./RadioButton";
4
-
5
- describe("RadioButton Component", () => {
6
- it("should render without crashing", () => {
7
- render(<RadioButton value="option1" />);
8
- const radioElement = screen.getByRole("radio");
9
- expect(radioElement).toBeInTheDocument();
10
- });
1
+ import React from 'react';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import '@testing-library/jest-dom';
4
+ import CustomRadioButton from './RadioButton';
11
5
 
12
- it("should render with default props", () => {
13
- render(<RadioButton value="option1" />);
14
- const radioElement = screen.getByRole("radio");
15
- expect(radioElement).not.toBeChecked();
16
- expect(radioElement).toHaveAttribute("value", "option1");
17
- });
6
+ describe('CustomRadioButton', () => {
7
+ it('should render with given props', () => {
8
+ render(
9
+ <CustomRadioButton
10
+ name="testName"
11
+ value="testValue"
12
+ checked={true}
13
+ onChange={() => {}}
14
+ className="custom-class"
15
+ inputClassName="input-class"
16
+ labelClassName="label-class"
17
+ id="radio1"
18
+ />
19
+ );
18
20
 
19
- it("should handle the checked prop", () => {
20
- render(<RadioButton value="option1" checked />);
21
- const radioElement = screen.getByRole("radio");
22
- expect(radioElement).toBeChecked();
23
- });
21
+ const radioInput = screen.getByRole('radio');
22
+ const label = screen.getByText('testValue'); // Use text to find the label
24
23
 
25
- it("should be disabled when disabled prop is true", () => {
26
- render(<RadioButton value="option1" disabled />);
27
- const radioElement = screen.getByRole("radio");
28
- expect(radioElement).toBeDisabled();
24
+ // Assert that the radio input is rendered correctly
25
+ expect(radioInput).toBeInTheDocument();
26
+ expect(radioInput).toHaveAttribute('name', 'testName');
27
+ expect(radioInput).toHaveAttribute('value', 'testValue');
28
+ expect(radioInput).toBeChecked();
29
+ expect(radioInput).toHaveClass('input-class');
30
+
31
+ // Assert that the label is rendered correctly
32
+ expect(label).toBeInTheDocument();
33
+
34
+ // Ensure the label has the correct class by finding the label element directly
35
+ const labelElement = document.querySelector(`label[for="radio1"]`);
36
+ expect(labelElement).toHaveClass('label-class');
29
37
  });
30
38
 
31
- it("should call the onChange handler when clicked", () => {
39
+ it('should call onChange handler when clicked', () => {
32
40
  const handleChange = jest.fn();
33
- render(<RadioButton value="option1" onChange={handleChange} />);
34
- const radioElement = screen.getByRole("radio");
35
- fireEvent.click(radioElement);
36
- expect(handleChange).toHaveBeenCalledTimes(1);
41
+
42
+ render(
43
+ <CustomRadioButton
44
+ name="testName"
45
+ value="testValue"
46
+ onChange={handleChange}
47
+ id="radio1"
48
+ />
49
+ );
50
+
51
+ const radioInput = screen.getByRole('radio');
52
+ fireEvent.click(radioInput);
53
+
54
+ expect(handleChange).toHaveBeenCalled();
55
+ });
56
+
57
+ it('should render without crashing if no props are provided', () => {
58
+ render(<CustomRadioButton name="testName" value="testValue" />);
59
+
60
+ const radioInput = screen.getByRole('radio');
61
+ // Ensure that the label is associated with the radio input
62
+ const label = screen.getByText('testValue');
63
+
64
+ expect(radioInput).toBeInTheDocument();
65
+ expect(label).toBeInTheDocument();
37
66
  });
38
67
  });
@@ -0,0 +1,83 @@
1
+ import React, { useState } from 'react';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import '@testing-library/jest-dom';
4
+ import Switch from './Switch';
5
+
6
+ describe('Switch Component', () => {
7
+ it('renders with basic props', () => {
8
+ const { container } = render(<Switch checked={true} handleChange={() => {}} switchClassName="switch-class" />);
9
+
10
+ const switchInput = screen.getByRole('checkbox');
11
+ const switchToggle = container.querySelector('.switch-class');
12
+
13
+ expect(switchInput).toBeInTheDocument();
14
+ expect(switchInput).toBeChecked();
15
+ expect(switchToggle).toBeInTheDocument();
16
+ });
17
+
18
+ it('renders with a label', () => {
19
+ render(
20
+ <Switch
21
+ checked={true}
22
+ handleChange={() => {}}
23
+ switchClassName="switch-class"
24
+ label="Toggle Switch"
25
+ labelClassName="label-class"
26
+ />
27
+ );
28
+
29
+ const label = screen.getByText('Toggle Switch');
30
+ const switchInput = screen.getByRole('checkbox');
31
+
32
+ expect(label).toBeInTheDocument();
33
+ expect(label).toHaveClass('label-class');
34
+ expect(switchInput).toBeChecked();
35
+ });
36
+
37
+ it('calls handleChange handler when clicked', () => {
38
+ // Simulate a component that manages its own state
39
+ const TestComponent = () => {
40
+ const [checked, setChecked] = useState(false);
41
+ return (
42
+ <Switch
43
+ checked={checked}
44
+ handleChange={() => setChecked(!checked)}
45
+ switchClassName="switch-class"
46
+ />
47
+ );
48
+ };
49
+
50
+ render(<TestComponent />);
51
+
52
+ const switchInput = screen.getByRole('checkbox');
53
+ expect(switchInput).not.toBeChecked();
54
+
55
+ // Simulate the click event
56
+ fireEvent.click(switchInput);
57
+
58
+ // Check if the switchInput is now checked
59
+ expect(switchInput).toBeChecked();
60
+ });
61
+
62
+ it('applies custom classes', () => {
63
+ const { container } = render(
64
+ <Switch
65
+ checked={true}
66
+ handleChange={() => {}}
67
+ switchClassName="switch-class"
68
+ containerClassName="container-class"
69
+ toggleClassName="toggle-class"
70
+ label="Toggle Switch"
71
+ labelClassName="label-class"
72
+ />
73
+ );
74
+
75
+ const containerDiv = container.querySelector('.container-class');
76
+ const switchToggle = container.querySelector('.switch-class');
77
+ const label = screen.getByText('Toggle Switch');
78
+
79
+ expect(containerDiv).toHaveClass('container-class');
80
+ expect(switchToggle).toHaveClass('switch-class');
81
+ expect(label).toHaveClass('label-class');
82
+ });
83
+ });
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import '@testing-library/jest-dom';
4
+ import Tag, { TagProps } from './Tag';
5
+
6
+ describe('Tag Component', () => {
7
+ let handleClick: jest.Mock;
8
+
9
+ beforeEach(() => {
10
+ handleClick = jest.fn(); // Reset the mock function before each test
11
+ });
12
+
13
+ // Function to generate default props for each test
14
+ const getDefaultProps = (): TagProps => ({
15
+ content: 'Sample Tag',
16
+ tagClassName: 'tag-class',
17
+ handleClick,
18
+ });
19
+
20
+ it('renders the tag with the correct content', () => {
21
+ render(<Tag {...getDefaultProps()} />);
22
+
23
+ const tagElement = screen.getByText('Sample Tag');
24
+
25
+ expect(tagElement).toBeInTheDocument();
26
+ });
27
+
28
+ it('applies the correct className to the tag', () => {
29
+ render(<Tag {...getDefaultProps()} />);
30
+
31
+ const tagElement = screen.getByText('Sample Tag');
32
+
33
+ expect(tagElement).toHaveClass('tag-class');
34
+ });
35
+
36
+ it('calls the handleClick function when the tag is clicked', () => {
37
+ render(<Tag {...getDefaultProps()} />);
38
+
39
+ const tagElement = screen.getByText('Sample Tag');
40
+
41
+ fireEvent.click(tagElement);
42
+
43
+ expect(handleClick).toHaveBeenCalledTimes(1);
44
+ });
45
+
46
+ it('does not call handleClick when the tag is not clicked', () => {
47
+ render(<Tag {...getDefaultProps()} />);
48
+
49
+ expect(handleClick).not.toHaveBeenCalled();
50
+ });
51
+
52
+ it('renders correctly without crashing', () => {
53
+ const { container } = render(<Tag {...getDefaultProps()} />);
54
+
55
+ expect(container.firstChild).toMatchSnapshot();
56
+ });
57
+ });
@@ -0,0 +1,9 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Tag Component renders correctly without crashing 1`] = `
4
+ <span
5
+ class="tag-class"
6
+ >
7
+ Sample Tag
8
+ </span>
9
+ `;
@@ -0,0 +1,73 @@
1
+ import React from 'react';
2
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
3
+ import '@testing-library/jest-dom';
4
+ import Tooltip, { TooltipProps } from './Tooltip';
5
+
6
+ describe('Tooltip Component', () => {
7
+ const defaultProps: TooltipProps = {
8
+ content: 'Tooltip content',
9
+ tooltipClassName: 'tooltip-class',
10
+ children: <button>Hover me</button>,
11
+ };
12
+
13
+ it('renders the children correctly', () => {
14
+ render(<Tooltip {...defaultProps} />);
15
+
16
+ const childElement = screen.getByText('Hover me');
17
+
18
+ expect(childElement).toBeInTheDocument();
19
+ });
20
+
21
+ it('does not show tooltip content by default', () => {
22
+ render(<Tooltip {...defaultProps} />);
23
+
24
+ const tooltipElement = screen.queryByText(defaultProps.content);
25
+
26
+ expect(tooltipElement).not.toBeInTheDocument();
27
+ });
28
+
29
+ it('shows tooltip content on mouse enter and hides it on mouse leave', () => {
30
+ render(<Tooltip {...defaultProps} />);
31
+
32
+ const childElement = screen.getByText('Hover me');
33
+
34
+ // Trigger mouse enter
35
+ fireEvent.mouseEnter(childElement);
36
+ let tooltipElement = screen.getByText(defaultProps.content);
37
+ expect(tooltipElement).toBeInTheDocument();
38
+ expect(tooltipElement).toHaveClass(defaultProps.tooltipClassName);
39
+
40
+ // Trigger mouse leave
41
+ fireEvent.mouseLeave(childElement);
42
+ tooltipElement = screen.queryByText(defaultProps.content);
43
+
44
+ // Ensure tooltipElement is not null before checking its properties
45
+ expect(tooltipElement).toBeNull();
46
+ });
47
+
48
+ it('applies the correct container className', () => {
49
+ const customClassName = 'custom-container-class';
50
+ render(<Tooltip {...defaultProps} containerClassName={customClassName} />);
51
+
52
+ const containerElement = screen.getByText('Hover me').parentElement;
53
+
54
+ expect(containerElement).toHaveClass(customClassName);
55
+ });
56
+
57
+ it('matches snapshot when tooltip is visible', () => {
58
+ const { container } = render(<Tooltip {...defaultProps} />);
59
+
60
+ const childElement = screen.getByText('Hover me');
61
+
62
+ // Trigger mouse enter to show tooltip
63
+ fireEvent.mouseEnter(childElement);
64
+
65
+ expect(container.firstChild).toMatchSnapshot();
66
+ });
67
+
68
+ it('matches snapshot when tooltip is hidden', () => {
69
+ const { container } = render(<Tooltip {...defaultProps} />);
70
+
71
+ expect(container.firstChild).toMatchSnapshot();
72
+ });
73
+ });
@@ -0,0 +1,22 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Tooltip Component matches snapshot when tooltip is hidden 1`] = `
4
+ <div>
5
+ <button>
6
+ Hover me
7
+ </button>
8
+ </div>
9
+ `;
10
+
11
+ exports[`Tooltip Component matches snapshot when tooltip is visible 1`] = `
12
+ <div>
13
+ <button>
14
+ Hover me
15
+ </button>
16
+ <div
17
+ class="tooltip-class"
18
+ >
19
+ Tooltip content
20
+ </div>
21
+ </div>
22
+ `;
@@ -3,9 +3,12 @@ export { default as Avatar } from "./Avatar";
3
3
  export { default as Badge } from "./Badge";
4
4
  export { default as BreadCrumb } from "./BreadCrumb";
5
5
  export { default as Checkbox } from "./Checkbox";
6
- export { default as CircularProgress } from "./Circular_Progress";
6
+ export { default as CircularProgress } from "./CircularProgress";
7
7
  export { default as Divider } from "./Divider";
8
8
  export { default as Link } from "./Link";
9
9
  export { default as Progress } from "./Progress";
10
10
  export { default as RadioButton } from "./RadioButton";
11
- export { default as InputTextField } from "./InputTextField";
11
+ export { default as InputTextField } from "./InputTextField";
12
+ export { default } from "./PdfView";
13
+ export { default as Directions } from "./Map/Directions";
14
+ export { default as GoogleMap } from "./Map/GoogleMap";
@@ -0,0 +1 @@
1
+ declare module '*.scss';