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
@@ -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
+ });
@@ -0,0 +1,9 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Button Component renders correctly without crashing 1`] = `
4
+ <button
5
+ class="button-class"
6
+ >
7
+ Click Me
8
+ </button>
9
+ `;
@@ -1,61 +1,89 @@
1
- import React from "react";
2
- import { render, fireEvent } from "@testing-library/react";
3
- import Checkbox from "./Checkbox";
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
- describe("Checkbox Component", () => {
6
- it("should render without crashing", () => {
7
- const { getByTestId } = render(
8
- <Checkbox data-testid="checkbox-rendered" />
9
- );
10
- expect(getByTestId("checkbox-rendered")).toBeInTheDocument();
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
- expect(checkboxElement).not.toBeChecked();
15
+ describe('CustomCheckbox Component', () => {
16
+ let handleChange: jest.Mock;
18
17
 
19
- expect(checkboxElement).toHaveAttribute("type", "checkbox");
20
- expect(checkboxElement).not.toBeDisabled();
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
- it("should render with the checked prop", () => {
24
- const { getByRole } = render(<Checkbox checked={true} />);
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("should handle the onChange event", () => {
31
- const handleChange = jest.fn();
32
- const { getByRole } = render(<Checkbox onChange={handleChange} />);
33
- const checkboxElement = getByRole("checkbox");
34
-
35
- fireEvent.click(checkboxElement);
36
-
37
- expect(handleChange).toHaveBeenCalledTimes(1);
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("should render with the specified color", () => {
42
- const { getByRole } = render(<Checkbox color="secondary" />);
43
- const checkboxElement = getByRole("checkbox");
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
- expect(checkboxElement).toBeInTheDocument();
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("should render with the specified size", () => {
49
- const { getByRole } = render(<Checkbox size="small" />);
50
- const checkboxElement = getByRole("checkbox");
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
- expect(checkboxElement).toBeInTheDocument();
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("should render as disabled when the disabled prop is true", () => {
56
- const { getByRole } = render(<Checkbox disabled />);
57
- const checkboxElement = getByRole("checkbox");
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
- expect(checkboxElement).toBeDisabled();
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
+ `;
@@ -34,4 +34,4 @@ const CircularProgress: React.FC<CircularProgressProps> = ({
34
34
  );
35
35
  };
36
36
 
37
- export default CircularProgress;
37
+ export default CircularProgress;
@@ -1,19 +1,44 @@
1
1
  import React from "react";
2
2
  import { render } from "@testing-library/react";
3
- import Divider from "./Divider";
3
+ import CustomDivider from "./Divider";
4
+ import { DIVIDER_ORIENTATION } from "../Enum";
4
5
 
5
- describe("Divider Component", () => {
6
- it("should render without crashing", () => {
7
- const { getByTestId } = render(<Divider data-testid="divider-rendered" />);
8
- expect(getByTestId("divider-rendered")).toBeInTheDocument();
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("should render with default props", () => {
12
- const { container } = render(<Divider />);
13
- const dividerElement = container.querySelector(".MuiDivider-root");
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
- expect(dividerElement).not.toHaveClass("MuiDivider-vertical");
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
- expect(dividerElement).toHaveClass("MuiDivider-fullWidth");
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
  });
@@ -1,48 +1,118 @@
1
- import React from "react";
2
- import { render } from "@testing-library/react";
3
- import InputTextField from "./InputTextField";
1
+ import React from 'react';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import CustomInputField, { CustomInputFieldProps } from './InputTextField';
4
+ import { INPUT_TYPES } from '../Enum';
4
5
 
5
- describe("InputTextField Component", () => {
6
- it("should render without crashing", () => {
7
- const { getByTestId } = render(
8
- <InputTextField label="Name" data-testid="inputTextField-rendered" />
9
- );
10
- expect(getByTestId("inputTextField-rendered")).toBeInTheDocument();
6
+ const renderWithProps = (props: Partial<CustomInputFieldProps> = {}) => {
7
+ const defaultProps: CustomInputFieldProps = {
8
+ label: 'Test Label',
9
+ value: 'Test Value',
10
+ type: INPUT_TYPES.TEXT,
11
+ placeholder: 'Enter text...',
12
+ onChange: jest.fn(),
13
+ className: 'custom-input-wrapper',
14
+ inputClassName: 'custom-input',
15
+ labelClassName: 'custom-label',
16
+ error: '',
17
+ errorClassName: 'custom-error',
18
+ id: 'test-input-field',
19
+ ...props
20
+ };
21
+ return render(<CustomInputField {...defaultProps} />);
22
+ };
23
+
24
+ describe('CustomInputField Component', () => {
25
+ // it('renders without crashing', () => {
26
+ // renderWithProps();
27
+ // // Check if the label correctly associates with the input by using the id
28
+ // const input = screen.getByLabelText('Test Label');
29
+ // expect(input).toBeInTheDocument();
30
+ // });
31
+
32
+
33
+ it('renders the label correctly', () => {
34
+ renderWithProps();
35
+ expect(screen.getByText('Test Label')).toHaveClass('custom-label');
11
36
  });
12
37
 
13
- it("should render with default props", () => {
14
- const { getByLabelText } = render(<InputTextField label="Name" />);
15
- const inputElement = getByLabelText("Name") as HTMLInputElement;
38
+ it('renders the input with the correct value', () => {
39
+ renderWithProps();
40
+ expect(screen.getByDisplayValue('Test Value')).toHaveClass('custom-input');
41
+ });
16
42
 
17
- expect(inputElement).toHaveAttribute("type", "text");
43
+ it('calls the onChange handler when input value changes', () => {
44
+ const mockOnChange = jest.fn();
45
+ renderWithProps({ onChange: mockOnChange });
46
+ const input = screen.getByDisplayValue('Test Value');
47
+ fireEvent.change(input, { target: { value: 'New Value' } });
48
+ expect(mockOnChange).toHaveBeenCalledTimes(1);
49
+ });
18
50
 
19
- expect(inputElement).toHaveClass("MuiInputBase-input");
51
+ it('displays the error message correctly', () => {
52
+ renderWithProps({ error: 'Error message' });
53
+ expect(screen.getByText('Error message')).toHaveClass('custom-error');
20
54
  });
21
55
 
22
- it("should render with the specified type", () => {
23
- const { getByLabelText } = render(
24
- <InputTextField label="Password" type="password" />
25
- );
26
- const inputElement = getByLabelText("Password") as HTMLInputElement;
56
+ it('renders the input with the correct type', () => {
57
+ renderWithProps({ type: INPUT_TYPES.EMAIL });
58
+ expect(screen.getByPlaceholderText('Enter text...')).toHaveAttribute('type', INPUT_TYPES.EMAIL);
59
+ });
60
+
61
+ // it('applies the passed className to the wrapper div', () => {
62
+ // renderWithProps();
63
+ // // Check the class name of the wrapper div
64
+ // const wrapper = screen.getByLabelText('Test Label').parentElement?.parentElement;
65
+ // expect(wrapper).toHaveClass('custom-input-wrapper');
66
+ // });
67
+
68
+ it('applies additional props to the input field', () => {
69
+ renderWithProps();
70
+ expect(screen.getByPlaceholderText('Enter text...')).toBeInTheDocument();
71
+ });
72
+ });
27
73
 
28
- expect(inputElement).toHaveAttribute("type", "password");
74
+ describe('CustomInputField Component - Default Values', () => {
75
+ it('renders the input field with default value when value prop is not provided', () => {
76
+ render(<CustomInputField label="Test Label" type={INPUT_TYPES.TEXT} value="" onChange={jest.fn()} />);
77
+ expect(screen.getByPlaceholderText('')).toHaveValue('');
29
78
  });
30
79
 
31
- it("should render with the specified variant", () => {
32
- const { getByLabelText } = render(
33
- <InputTextField label="Email" variant="outlined" />
34
- );
35
- const inputElement = getByLabelText("Email") as HTMLInputElement;
80
+ it('renders the input field with default type when type prop is not provided', () => {
81
+ render(<CustomInputField label="Test Label" value="Test Value" type={INPUT_TYPES.TEXT} onChange={jest.fn()} />);
82
+ expect(screen.getByDisplayValue('Test Value')).toHaveAttribute('type', INPUT_TYPES.TEXT);
83
+ });
36
84
 
37
- expect(inputElement).toHaveClass("MuiOutlinedInput-input");
85
+ it('renders the input field with default placeholder when placeholder prop is not provided', () => {
86
+ render(<CustomInputField label="Test Label" value="Test Value" type={INPUT_TYPES.TEXT} onChange={jest.fn()} />);
87
+ expect(screen.getByDisplayValue('Test Value')).toHaveAttribute('placeholder', '');
38
88
  });
39
89
 
40
- it("should render with helper text", () => {
41
- const { getByText } = render(
42
- <InputTextField label="Email" helperText="Enter your email" />
43
- );
44
- const helperTextElement = getByText("Enter your email");
90
+ // it('applies default class names if className, inputClassName, or labelClassName are not provided', () => {
91
+ // render(<CustomInputField label="Test Label" value="Test Value" type={INPUT_TYPES.TEXT} onChange={jest.fn()} />);
92
+
93
+ // // Get the label element
94
+ // const label = screen.getByText('Test Label');
95
+ // const input = screen.getByDisplayValue('Test Value');
96
+
97
+ // // Get the parent wrapper div
98
+ // const wrapper = label.closest('div');
99
+
100
+ // // Check if the wrapper div has default class names or no class names
101
+ // if (wrapper) {
102
+ // // Expect no additional class names or specific default class names
103
+ // expect(wrapper).toHaveClass('default-wrapper-class'); // Replace with actual default class
104
+ // }
45
105
 
46
- expect(helperTextElement).toBeInTheDocument();
106
+ // // Check if the input field has default input class names or no class names
107
+ // expect(input).toHaveClass('default-input-class'); // Replace with actual default class
108
+
109
+ // // Check if the label has default label class names or no class names
110
+ // expect(label).toHaveClass('default-label-class'); // Replace with actual default class
111
+ // });
112
+
113
+ it('does not render the error message if error prop is not provided', () => {
114
+ render(<CustomInputField label="Test Label" value="Test Value" type={INPUT_TYPES.TEXT} onChange={jest.fn()} />);
115
+ const errorMessage = screen.queryByText('Error message');
116
+ expect(errorMessage).not.toBeInTheDocument();
47
117
  });
48
- });
118
+ });
@@ -4,16 +4,18 @@ import { INPUT_TYPES } from '../Enum';
4
4
  export interface CustomInputFieldProps {
5
5
  label?: string;
6
6
  value?: string;
7
- type?:string ;
7
+ type?:string ;
8
8
  placeholder?: string;
9
9
  onChange?: React.ChangeEventHandler<HTMLInputElement>;
10
- className?: string;
11
- inputClassName?: string;
12
- labelClassName?: string;
10
+ className?: string;
11
+ inputClassName?: string;
12
+ labelClassName?: string;
13
13
  error?: string;
14
- errorClassName?: string;
14
+ errorClassName?: string;
15
+ id?: string;
15
16
  }
16
17
 
18
+
17
19
  const CustomInputField: React.FC<CustomInputFieldProps> = ({
18
20
  label,
19
21
  value = '',
@@ -1,47 +1,55 @@
1
- import React from "react";
2
- import { render, fireEvent } from "@testing-library/react";
3
- import Link from "./Link";
4
-
5
- describe("Link Component", () => {
6
- it("should render without crashing", () => {
7
- const { getByRole } = render(
8
- <Link href="https://example.com">Test Link</Link>
9
- );
10
- const linkElement = getByRole("link");
11
- expect(linkElement).toBeInTheDocument();
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import Link, { LinkProps } from './Link';
4
+ import { LINK_TARGET } from '../Enum';
5
+
6
+ describe('Link Component', () => {
7
+ const defaultProps: LinkProps = {
8
+ href: 'https://example.com',
9
+ target: LINK_TARGET.Self,
10
+ rel: 'noopener noreferrer',
11
+ className: 'custom-link',
12
+ children: 'Click here',
13
+ };
14
+
15
+ it('renders the link with the correct href', () => {
16
+ render(<Link {...defaultProps} />);
17
+ expect(screen.getByText('Click here')).toHaveAttribute('href', 'https://example.com');
12
18
  });
13
19
 
14
- it("should render with default props", () => {
15
- const { getByRole } = render(<Link href="https://example.com" />);
16
- const linkElement = getByRole("link");
17
-
18
- expect(linkElement).toHaveAttribute("href", "https://example.com");
19
-
20
- expect(linkElement).toHaveAttribute("target", "_self");
21
-
22
- expect(linkElement).toHaveAttribute("rel", "noopener noreferrer");
23
-
24
- expect(linkElement).toHaveClass("MuiLink-underlineNone");
20
+ it('renders the link with the correct target attribute', () => {
21
+ render(<Link {...defaultProps} />);
22
+ expect(screen.getByText('Click here')).toHaveAttribute('target', LINK_TARGET.Self);
25
23
  });
26
24
 
27
- it('should render with target="_blank"', () => {
28
- const { getByRole } = render(
29
- <Link href="https://example.com" target="_blank" />
30
- );
31
- const linkElement = getByRole("link");
25
+ it('renders the link with the correct rel attribute', () => {
26
+ render(<Link {...defaultProps} />);
27
+ expect(screen.getByText('Click here')).toHaveAttribute('rel', 'noopener noreferrer');
28
+ });
32
29
 
33
- expect(linkElement).toHaveAttribute("target", "_blank");
30
+ it('renders the link with the correct className', () => {
31
+ render(<Link {...defaultProps} />);
32
+ expect(screen.getByText('Click here')).toHaveClass('custom-link');
34
33
  });
35
34
 
36
- it("should handle onClick event", () => {
37
- const handleClick = jest.fn();
38
- const { getByRole } = render(
39
- <Link href="https://example.com" onClick={handleClick} />
40
- );
41
- const linkElement = getByRole("link");
35
+ it('renders the link with the correct children', () => {
36
+ render(<Link {...defaultProps} />);
37
+ expect(screen.getByText('Click here')).toBeInTheDocument();
38
+ });
42
39
 
43
- fireEvent.click(linkElement);
40
+ it('renders with default target when not specified', () => {
41
+ const propsWithoutTarget: Omit<LinkProps, 'target'> = {
42
+ href: defaultProps.href,
43
+ rel: defaultProps.rel,
44
+ className: defaultProps.className,
45
+ children: defaultProps.children,
46
+ };
47
+ render(<Link {...propsWithoutTarget} />);
48
+ expect(screen.getByText('Click here')).toHaveAttribute('target', LINK_TARGET.Self);
49
+ });
44
50
 
45
- expect(handleClick).toHaveBeenCalledTimes(1);
51
+ it('applies additional props to the link element', () => {
52
+ render(<Link {...defaultProps} data-testid="custom-link" />);
53
+ expect(screen.getByTestId('custom-link')).toBeInTheDocument();
46
54
  });
47
55
  });