dhre-component-lib 0.1.4 → 0.1.6
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 +3 -7
- package/src/components/Badge/Badge.tsx +2 -2
- package/dist/components/Avatar/Avatar.d.ts +0 -9
- package/dist/components/Avatar/Avatar.js +0 -6
- package/dist/components/Avatar/Avatar.test.d.ts +0 -1
- package/dist/components/Avatar/Avatar.test.js +0 -50
- package/dist/components/Avatar/index.d.ts +0 -1
- package/dist/components/Avatar/index.js +0 -1
- package/dist/components/Badge/Badge.d.ts +0 -9
- package/dist/components/Badge/Badge.js +0 -7
- package/dist/components/Badge/Badge.test.d.ts +0 -1
- package/dist/components/Badge/Badge.test.js +0 -52
- package/dist/components/Badge/index.d.ts +0 -1
- package/dist/components/Badge/index.js +0 -1
- package/dist/components/BreadCrumb/BreadCrumb.d.ts +0 -14
- package/dist/components/BreadCrumb/BreadCrumb.js +0 -8
- package/dist/components/BreadCrumb/BreadCrumb.test.d.ts +0 -1
- package/dist/components/BreadCrumb/BreadCrumb.test.js +0 -55
- package/dist/components/BreadCrumb/index.d.ts +0 -1
- package/dist/components/BreadCrumb/index.js +0 -1
- package/dist/components/Button/Button.d.ts +0 -10
- package/dist/components/Button/Button.js +0 -7
- package/dist/components/Button/Button.test.d.ts +0 -1
- package/dist/components/Button/Button.test.js +0 -48
- package/dist/components/Button/index.d.ts +0 -1
- package/dist/components/Button/index.js +0 -1
- package/dist/components/Checkbox/Checkbox.d.ts +0 -11
- package/dist/components/Checkbox/Checkbox.js +0 -28
- package/dist/components/Checkbox/Checkbox.test.d.ts +0 -1
- package/dist/components/Checkbox/Checkbox.test.js +0 -70
- package/dist/components/Checkbox/index.d.ts +0 -1
- package/dist/components/Checkbox/index.js +0 -1
- package/dist/components/CircularProgress/CircularProgress.d.ts +0 -10
- package/dist/components/CircularProgress/CircularProgress.js +0 -22
- package/dist/components/CircularProgress/CircularProgress.test.d.ts +0 -1
- package/dist/components/CircularProgress/CircularProgress.test.js +0 -44
- package/dist/components/CircularProgress/index.d.ts +0 -1
- package/dist/components/CircularProgress/index.js +0 -1
- package/dist/components/Divider/Divider.d.ts +0 -8
- package/dist/components/Divider/Divider.js +0 -29
- package/dist/components/Divider/Divider.test.d.ts +0 -1
- package/dist/components/Divider/Divider.test.js +0 -31
- package/dist/components/Divider/index.d.ts +0 -1
- package/dist/components/Divider/index.js +0 -1
- package/dist/components/Enum.d.ts +0 -17
- package/dist/components/Enum.js +0 -17
- package/dist/components/InputTextField/InputTextField.d.ts +0 -16
- package/dist/components/InputTextField/InputTextField.js +0 -29
- package/dist/components/InputTextField/InputTextField.test.d.ts +0 -1
- package/dist/components/InputTextField/InputTextField.test.js +0 -97
- package/dist/components/InputTextField/index.d.ts +0 -1
- package/dist/components/InputTextField/index.js +0 -1
- package/dist/components/Link/Link.d.ts +0 -10
- package/dist/components/Link/Link.js +0 -29
- package/dist/components/Link/Link.test.d.ts +0 -1
- package/dist/components/Link/Link.test.js +0 -58
- package/dist/components/Link/index.d.ts +0 -1
- package/dist/components/Link/index.js +0 -1
- package/dist/components/Map/Directions.d.ts +0 -13
- package/dist/components/Map/Directions.js +0 -6
- package/dist/components/Map/GoogleMap.d.ts +0 -12
- package/dist/components/Map/GoogleMap.js +0 -100
- package/dist/components/Map/GoogleMapsLoader.d.ts +0 -4
- package/dist/components/Map/GoogleMapsLoader.js +0 -10
- package/dist/components/Map/index.d.ts +0 -2
- package/dist/components/Map/index.js +0 -2
- package/dist/components/Modal/Modal.d.ts +0 -10
- package/dist/components/Modal/Modal.js +0 -14
- package/dist/components/Modal/Modal.test.d.ts +0 -1
- package/dist/components/Modal/Modal.test.js +0 -51
- package/dist/components/Modal/index.d.ts +0 -1
- package/dist/components/Modal/index.js +0 -1
- package/dist/components/Notification/Notification.d.ts +0 -10
- package/dist/components/Notification/Notification.js +0 -21
- package/dist/components/Notification/Notification.test.d.ts +0 -1
- package/dist/components/Notification/Notification.test.js +0 -97
- package/dist/components/Notification/index.d.ts +0 -1
- package/dist/components/Notification/index.js +0 -1
- package/dist/components/OtpInput/OtpInput.d.ts +0 -14
- package/dist/components/OtpInput/OtpInput.js +0 -74
- package/dist/components/OtpInput/OtpInput.test.d.ts +0 -1
- package/dist/components/OtpInput/OtpInput.test.js +0 -76
- package/dist/components/OtpInput/index.d.ts +0 -1
- package/dist/components/OtpInput/index.js +0 -1
- package/dist/components/PdfView/PdfView.d.ts +0 -18
- package/dist/components/PdfView/PdfView.js +0 -92
- package/dist/components/PdfView/PdfView.test.d.ts +0 -1
- package/dist/components/PdfView/PdfView.test.js +0 -41
- package/dist/components/PdfView/index.d.ts +0 -1
- package/dist/components/PdfView/index.js +0 -1
- package/dist/components/Progress/Progress.d.ts +0 -12
- package/dist/components/Progress/Progress.js +0 -29
- package/dist/components/Progress/Progress.test.d.ts +0 -1
- package/dist/components/Progress/Progress.test.js +0 -34
- package/dist/components/Progress/index.d.ts +0 -1
- package/dist/components/Progress/index.js +0 -1
- package/dist/components/RadioButton/RadioButton.d.ts +0 -14
- package/dist/components/RadioButton/RadioButton.js +0 -28
- package/dist/components/RadioButton/RadioButton.test.d.ts +0 -1
- package/dist/components/RadioButton/RadioButton.test.js +0 -29
- package/dist/components/RadioButton/index.d.ts +0 -1
- package/dist/components/RadioButton/index.js +0 -1
- package/dist/components/Switch/Switch.d.ts +0 -13
- package/dist/components/Switch/Switch.js +0 -7
- package/dist/components/Switch/Switch.test.d.ts +0 -1
- package/dist/components/Switch/Switch.test.js +0 -46
- package/dist/components/Switch/index.d.ts +0 -1
- package/dist/components/Switch/index.js +0 -1
- package/dist/components/Tag/Tag.d.ts +0 -9
- package/dist/components/Tag/Tag.js +0 -7
- package/dist/components/Tag/Tag.test.d.ts +0 -1
- package/dist/components/Tag/Tag.test.js +0 -54
- package/dist/components/Tag/index.d.ts +0 -1
- package/dist/components/Tag/index.js +0 -1
- package/dist/components/Tooltip/Tooltip.d.ts +0 -9
- package/dist/components/Tooltip/Tooltip.js +0 -11
- package/dist/components/Tooltip/Tooltip.test.d.ts +0 -1
- package/dist/components/Tooltip/Tooltip.test.js +0 -59
- package/dist/components/Tooltip/index.d.ts +0 -1
- package/dist/components/Tooltip/index.js +0 -1
- package/dist/components/index.d.ts +0 -15
- package/dist/components/index.js +0 -15
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/theme/colors.d.ts +0 -1
- package/dist/theme/colors.js +0 -2
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import './Notification.module.scss';
|
|
4
|
-
var Notification = function (_a) {
|
|
5
|
-
var message = _a.message, _b = _a.severity, severity = _b === void 0 ? 'info' : _b, _c = _a.autoHideDuration, autoHideDuration = _c === void 0 ? 6000 : _c, onClose = _a.onClose;
|
|
6
|
-
useEffect(function () {
|
|
7
|
-
if (autoHideDuration && onClose) {
|
|
8
|
-
var timer_1 = setTimeout(function () {
|
|
9
|
-
onClose(new Event('timeout'), 'timeout');
|
|
10
|
-
}, autoHideDuration);
|
|
11
|
-
return function () { return clearTimeout(timer_1); };
|
|
12
|
-
}
|
|
13
|
-
}, [autoHideDuration, onClose]);
|
|
14
|
-
var handleClose = function (event, reason) {
|
|
15
|
-
if (onClose) {
|
|
16
|
-
onClose(event, reason);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
return (_jsxs("div", { className: "notification ".concat(severity), onClick: function (e) { return handleClose(e); }, role: "alert", children: [_jsx("div", { className: "notification-message", children: message }), _jsx("button", { className: "close-button", onClick: function (e) { return handleClose(e, 'close'); }, "aria-label": "Close notification", children: "\u00D7" })] }));
|
|
20
|
-
};
|
|
21
|
-
export default Notification;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
49
|
-
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
50
|
-
import Notification from './Notification';
|
|
51
|
-
describe('Notification Component', function () {
|
|
52
|
-
var defaultProps = {
|
|
53
|
-
message: 'Test Message',
|
|
54
|
-
severity: 'info',
|
|
55
|
-
autoHideDuration: 6000,
|
|
56
|
-
onClose: jest.fn(),
|
|
57
|
-
};
|
|
58
|
-
var renderNotification = function (props) {
|
|
59
|
-
if (props === void 0) { props = {}; }
|
|
60
|
-
return render(_jsx(Notification, __assign({}, defaultProps, props)));
|
|
61
|
-
};
|
|
62
|
-
test('renders notification with the correct message', function () {
|
|
63
|
-
render(_jsx(Notification, { message: "Test Message", severity: "info" }));
|
|
64
|
-
// Check if the element exists by querying it
|
|
65
|
-
var notificationElement = screen.getByText('Test Message');
|
|
66
|
-
expect(notificationElement).not.toBeNull(); // Equivalent to `toBeInTheDocument`
|
|
67
|
-
// Alternatively, check for the presence of the role or className
|
|
68
|
-
var alertElement = screen.getByRole('alert');
|
|
69
|
-
expect(alertElement.className).toContain('info'); // Check if className includes "info"
|
|
70
|
-
});
|
|
71
|
-
test('calls onClose when the notification is clicked', function () {
|
|
72
|
-
var onClose = jest.fn();
|
|
73
|
-
renderNotification({ onClose: onClose });
|
|
74
|
-
fireEvent.click(screen.getByRole('alert'));
|
|
75
|
-
expect(onClose).toHaveBeenCalled();
|
|
76
|
-
});
|
|
77
|
-
test('calls onClose when the close button is clicked', function () {
|
|
78
|
-
var onClose = jest.fn();
|
|
79
|
-
renderNotification({ onClose: onClose });
|
|
80
|
-
fireEvent.click(screen.getByLabelText('Close notification'));
|
|
81
|
-
expect(onClose).toHaveBeenCalledWith(expect.anything(), 'close');
|
|
82
|
-
});
|
|
83
|
-
test('calls onClose after autoHideDuration expires', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
84
|
-
var onClose;
|
|
85
|
-
return __generator(this, function (_a) {
|
|
86
|
-
switch (_a.label) {
|
|
87
|
-
case 0:
|
|
88
|
-
onClose = jest.fn();
|
|
89
|
-
renderNotification({ onClose: onClose, autoHideDuration: 1000 });
|
|
90
|
-
return [4 /*yield*/, waitFor(function () { return expect(onClose).toHaveBeenCalledWith(expect.anything(), 'timeout'); }, { timeout: 1500 })];
|
|
91
|
-
case 1:
|
|
92
|
-
_a.sent();
|
|
93
|
-
return [2 /*return*/];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}); });
|
|
97
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Notification";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Notification";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import "./OtpInput.module.scss";
|
|
3
|
-
interface OTPInputProps {
|
|
4
|
-
length?: number;
|
|
5
|
-
onChange: (otp: string) => void;
|
|
6
|
-
autoFocus?: boolean;
|
|
7
|
-
onResend: () => void;
|
|
8
|
-
resendDelay?: number;
|
|
9
|
-
error?: boolean;
|
|
10
|
-
errorText?: string;
|
|
11
|
-
resendText: string;
|
|
12
|
-
}
|
|
13
|
-
declare const OTPInput: React.FC<OTPInputProps>;
|
|
14
|
-
export default OTPInput;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
-
if (ar || !(i in from)) {
|
|
4
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
-
ar[i] = from[i];
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
-
};
|
|
10
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { useEffect, useState } from "react";
|
|
12
|
-
import "./OtpInput.module.scss";
|
|
13
|
-
var OTPInput = function (_a) {
|
|
14
|
-
var _b = _a.length, length = _b === void 0 ? 4 : _b, onChange = _a.onChange, _c = _a.autoFocus, autoFocus = _c === void 0 ? false : _c, onResend = _a.onResend, _d = _a.resendDelay, resendDelay = _d === void 0 ? 60 : _d, _e = _a.error, error = _e === void 0 ? false : _e, errorText = _a.errorText, resendText = _a.resendText;
|
|
15
|
-
var _f = useState(Array(length).fill("")), otp = _f[0], setOtp = _f[1];
|
|
16
|
-
var _g = useState(resendDelay), timer = _g[0], setTimer = _g[1];
|
|
17
|
-
var _h = useState(false), isComplete = _h[0], setIsComplete = _h[1];
|
|
18
|
-
useEffect(function () {
|
|
19
|
-
var countdown = setInterval(function () {
|
|
20
|
-
setTimer(function (prevTimer) { return (prevTimer > 0 ? prevTimer - 1 : 0); });
|
|
21
|
-
}, 1000);
|
|
22
|
-
return function () { return clearInterval(countdown); };
|
|
23
|
-
}, []);
|
|
24
|
-
var handleChange = function (value, index) {
|
|
25
|
-
if (isNaN(Number(value)))
|
|
26
|
-
return;
|
|
27
|
-
var newOtp = __spreadArray([], otp, true);
|
|
28
|
-
newOtp[index] = value;
|
|
29
|
-
setOtp(newOtp);
|
|
30
|
-
onChange(newOtp.join(""));
|
|
31
|
-
if (value && index < length - 1) {
|
|
32
|
-
var nextInput = document.getElementById("otp-input-".concat(index + 1));
|
|
33
|
-
if (nextInput) {
|
|
34
|
-
nextInput.focus();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var handleKeyDown = function (e, index) {
|
|
39
|
-
if (e.key === "Backspace" && !otp[index] && index > 0) {
|
|
40
|
-
var prevInput = document.getElementById("otp-input-".concat(index - 1));
|
|
41
|
-
if (prevInput) {
|
|
42
|
-
prevInput.focus();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var handleResendClick = function () {
|
|
47
|
-
onResend();
|
|
48
|
-
setOtp(Array(length).fill(""));
|
|
49
|
-
setTimer(resendDelay);
|
|
50
|
-
setIsComplete(false);
|
|
51
|
-
};
|
|
52
|
-
useEffect(function () {
|
|
53
|
-
setIsComplete(otp.every(function (digit) { return digit !== ""; }));
|
|
54
|
-
}, [otp]);
|
|
55
|
-
useEffect(function () {
|
|
56
|
-
if (error) {
|
|
57
|
-
setTimer(0);
|
|
58
|
-
}
|
|
59
|
-
}, [error]);
|
|
60
|
-
function getReadableStatus() {
|
|
61
|
-
if (error) {
|
|
62
|
-
return "#EB0542";
|
|
63
|
-
}
|
|
64
|
-
return isComplete ? "#00B578" : "#A7A7A7";
|
|
65
|
-
}
|
|
66
|
-
return (_jsxs("div", { className: "otpMainContainer", children: [_jsx("div", { className: "otpInputDiv", children: Array(length)
|
|
67
|
-
.fill("")
|
|
68
|
-
.map(function (_, index) { return (_jsx("input", { type: "text", id: "otp-input-".concat(index), value: otp[index], "data-testid": "otp-input-".concat(index), role: "textbox", onChange: function (e) { return handleChange(e.target.value, index); }, onKeyDown: function (e) { return handleKeyDown(e, index); }, maxLength: 1, style: { border: "1px solid ".concat(getReadableStatus()) }, className: "otpInput", autoFocus: autoFocus && index === 0 }, index)); }) }), _jsxs("div", { className: "resendContainer", children: [error ? (_jsx("div", { className: "errorText", children: errorText })) : (_jsx("div", { className: "timerText", children: timer > 0 ? "00:".concat(timer, " secs") : "" })), _jsx("button", { onClick: handleResendClick, disabled: timer > 0, style: {
|
|
69
|
-
border: "none",
|
|
70
|
-
background: "none",
|
|
71
|
-
cursor: timer > 0 ? "not-allowed" : "pointer",
|
|
72
|
-
}, children: _jsx("div", { className: "resendText", children: resendText }) })] })] }));
|
|
73
|
-
};
|
|
74
|
-
export default OTPInput;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
38
|
-
import { render, fireEvent, screen } from '@testing-library/react';
|
|
39
|
-
import OTPInput from './OtpInput';
|
|
40
|
-
import '@testing-library/jest-dom';
|
|
41
|
-
describe('OTPInput Component', function () {
|
|
42
|
-
it('renders the correct number of input fields based on the length prop', function () {
|
|
43
|
-
render(_jsx(OTPInput, { length: 4, onChange: function () { }, onResend: function () { }, resendText: "Resend OTP" }));
|
|
44
|
-
var inputs = screen.getAllByRole('textbox');
|
|
45
|
-
expect(inputs).toHaveLength(4);
|
|
46
|
-
});
|
|
47
|
-
it('calls onChange prop when input changes', function () {
|
|
48
|
-
var handleChange = jest.fn();
|
|
49
|
-
render(_jsx(OTPInput, { length: 4, onChange: handleChange, onResend: function () { }, resendText: "Resend OTP" }));
|
|
50
|
-
var inputs = screen.getAllByRole('textbox');
|
|
51
|
-
fireEvent.change(inputs[0], { target: { value: '1' } });
|
|
52
|
-
expect(handleChange).toHaveBeenCalledWith('1');
|
|
53
|
-
});
|
|
54
|
-
it('calls onResend prop when the resend button is clicked', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
55
|
-
var handleResend, resendButton;
|
|
56
|
-
return __generator(this, function (_a) {
|
|
57
|
-
handleResend = jest.fn();
|
|
58
|
-
render(_jsx(OTPInput, { length: 4, onChange: function () { }, onResend: handleResend, resendText: "Resend OTP", resendDelay: 0 }));
|
|
59
|
-
resendButton = screen.getByRole('button', { name: /resend otp/i });
|
|
60
|
-
fireEvent.click(resendButton);
|
|
61
|
-
expect(handleResend).toHaveBeenCalled();
|
|
62
|
-
return [2 /*return*/];
|
|
63
|
-
});
|
|
64
|
-
}); });
|
|
65
|
-
it('displays error text when the error prop is true', function () {
|
|
66
|
-
var errorMessage = 'Invalid OTP';
|
|
67
|
-
render(_jsx(OTPInput, { length: 4, onChange: function () { }, onResend: function () { }, resendText: "Resend OTP", error: true, errorText: errorMessage }));
|
|
68
|
-
var errorElement = screen.getByText(errorMessage);
|
|
69
|
-
expect(errorElement).toBeInTheDocument();
|
|
70
|
-
});
|
|
71
|
-
it('changes border color to red when the error prop is true', function () {
|
|
72
|
-
render(_jsx(OTPInput, { length: 4, onChange: function () { }, onResend: function () { }, resendText: "Resend OTP", error: true }));
|
|
73
|
-
var firstInput = screen.getByTestId('otp-input-0');
|
|
74
|
-
expect(firstInput).toHaveStyle('border: 1px solid #EB0542');
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./OtpInput";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./OtpInput";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
export interface PdfViewerProps {
|
|
3
|
-
content: string;
|
|
4
|
-
contentType?: string;
|
|
5
|
-
buttonText?: string;
|
|
6
|
-
loadingText?: string;
|
|
7
|
-
errorText?: string;
|
|
8
|
-
cleanUpDelay?: number;
|
|
9
|
-
buttonVariant?: "text" | "outlined" | "contained";
|
|
10
|
-
buttonColor?: "inherit" | "primary" | "secondary" | "error" | "info" | "success" | "warning";
|
|
11
|
-
buttonSize?: "small" | "medium" | "large";
|
|
12
|
-
showLoadingSpinner?: boolean;
|
|
13
|
-
spinnerSize?: number;
|
|
14
|
-
spinnerColor?: "inherit" | "primary" | "secondary";
|
|
15
|
-
className?: string;
|
|
16
|
-
}
|
|
17
|
-
declare const PdfView: React.FC<PdfViewerProps>;
|
|
18
|
-
export default PdfView;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
38
|
-
import React, { useEffect } from "react";
|
|
39
|
-
import styles from './PdfView.module.scss';
|
|
40
|
-
var PdfView = function (_a) {
|
|
41
|
-
var content = _a.content, _b = _a.contentType, contentType = _b === void 0 ? "application/pdf" : _b, _c = _a.buttonText, buttonText = _c === void 0 ? "View PDF" : _c, _d = _a.loadingText, loadingText = _d === void 0 ? "Loading..." : _d, _e = _a.errorText, errorText = _e === void 0 ? "Failed to load PDF" : _e, _f = _a.cleanUpDelay, cleanUpDelay = _f === void 0 ? 1000 : _f, _g = _a.buttonVariant, buttonVariant = _g === void 0 ? "contained" : _g, _h = _a.buttonColor, buttonColor = _h === void 0 ? "primary" : _h, _j = _a.buttonSize, buttonSize = _j === void 0 ? "medium" : _j, _k = _a.showLoadingSpinner, showLoadingSpinner = _k === void 0 ? false : _k, _l = _a.spinnerSize, spinnerSize = _l === void 0 ? 24 : _l, _m = _a.spinnerColor, spinnerColor = _m === void 0 ? "primary" : _m, _o = _a.className, className = _o === void 0 ? "" : _o;
|
|
42
|
-
var _p = React.useState(false), isLoading = _p[0], setIsLoading = _p[1];
|
|
43
|
-
var _q = React.useState(false), isError = _q[0], setIsError = _q[1];
|
|
44
|
-
var _r = React.useState(errorText), errorMsg = _r[0], setErrorMsg = _r[1];
|
|
45
|
-
useEffect(function () {
|
|
46
|
-
if (btoa(atob(content)) !== content) {
|
|
47
|
-
setIsError(true);
|
|
48
|
-
}
|
|
49
|
-
}, [content]);
|
|
50
|
-
var base64ToBlob = function (content, contentType) {
|
|
51
|
-
if (contentType === void 0) { contentType = "application/pdf"; }
|
|
52
|
-
try {
|
|
53
|
-
var byteCharacters = atob(content);
|
|
54
|
-
var byteArray = new Uint8Array(byteCharacters.length);
|
|
55
|
-
for (var i = 0; i < byteCharacters.length; i++) {
|
|
56
|
-
byteArray[i] = byteCharacters.charCodeAt(i);
|
|
57
|
-
}
|
|
58
|
-
return new Blob([byteArray], { type: contentType });
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
setIsError(true);
|
|
62
|
-
setErrorMsg("Invalid base64 string:");
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
var handleViewPdf = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
-
var blob, url_1;
|
|
68
|
-
return __generator(this, function (_a) {
|
|
69
|
-
setIsLoading(true);
|
|
70
|
-
setIsError(false);
|
|
71
|
-
blob = base64ToBlob(content, contentType);
|
|
72
|
-
if (blob) {
|
|
73
|
-
url_1 = URL.createObjectURL(blob);
|
|
74
|
-
window.open(url_1, "_blank");
|
|
75
|
-
setTimeout(function () {
|
|
76
|
-
URL.revokeObjectURL(url_1);
|
|
77
|
-
}, cleanUpDelay);
|
|
78
|
-
setIsLoading(false);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
setIsLoading(false);
|
|
82
|
-
setIsError(true);
|
|
83
|
-
setErrorMsg("Failed to create Blob from base64 string.");
|
|
84
|
-
}
|
|
85
|
-
return [2 /*return*/];
|
|
86
|
-
});
|
|
87
|
-
}); };
|
|
88
|
-
var buttonClass = "\n ".concat(styles.button, " \n ").concat(styles["button".concat(buttonVariant.charAt(0).toUpperCase() + buttonVariant.slice(1))], " \n ").concat(styles["button".concat(buttonColor.charAt(0).toUpperCase() + buttonColor.slice(1))], " \n ").concat(styles["button".concat(buttonSize.charAt(0).toUpperCase() + buttonSize.slice(1))], "\n ");
|
|
89
|
-
var spinnerClass = "".concat(styles.spinner, " ").concat(styles.spinnerInner);
|
|
90
|
-
return (_jsxs("div", { className: "".concat(styles.container, " ").concat(className), children: [isLoading && showLoadingSpinner && (_jsx("div", { "data-testid": "spinnertest", className: spinnerClass, style: { width: spinnerSize, height: spinnerSize, borderColor: spinnerColor }, children: _jsx("div", { className: styles.spinnerInner }) })), isError && _jsx("p", { className: styles.errorText, children: errorMsg }), !isLoading && !isError && (_jsx("button", { onClick: handleViewPdf, className: buttonClass, children: buttonText })), isLoading && !showLoadingSpinner && _jsx("p", { children: loadingText })] }));
|
|
91
|
-
};
|
|
92
|
-
export default PdfView;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import '@testing-library/jest-dom';
|
|
4
|
-
import PdfView from './PdfView';
|
|
5
|
-
// Dummy base64 content for testing
|
|
6
|
-
var validBase64Content = 'JVBERi0xLjQKJeLjz9MNCjEgMCBvYmoKPDwvTGluay9QYWdlcyAyIDAgUj4+CnN0YXJ0eHJlZgoyNCAwIFIKZW5kb2JqCjEgMCBvYmoKPDwvTGluay9QYWdlcyAyIDAgUj4+CnN0YXJ0eHJlZgo2IDAgUgo+';
|
|
7
|
-
var invalidBase64Content = 'invalid base64 content';
|
|
8
|
-
var errorText = 'Failed to load PDF';
|
|
9
|
-
var buttonText = 'View PDF';
|
|
10
|
-
var loadingText = 'Loading...';
|
|
11
|
-
// Save the original implementation of createObjectURL
|
|
12
|
-
var originalCreateObjectURL = global.URL.createObjectURL;
|
|
13
|
-
describe('PdfView Component', function () {
|
|
14
|
-
beforeAll(function () {
|
|
15
|
-
// Mock URL.createObjectURL directly
|
|
16
|
-
global.URL.createObjectURL = jest.fn(function () { return 'mock-url'; });
|
|
17
|
-
});
|
|
18
|
-
afterAll(function () {
|
|
19
|
-
// Restore the original implementation
|
|
20
|
-
global.URL.createObjectURL = originalCreateObjectURL;
|
|
21
|
-
});
|
|
22
|
-
it('renders correctly with default props', function () {
|
|
23
|
-
render(_jsx(PdfView, { content: validBase64Content }));
|
|
24
|
-
expect(screen.getByText(buttonText)).toBeInTheDocument();
|
|
25
|
-
});
|
|
26
|
-
it('shows error message if content is invalid', function () {
|
|
27
|
-
render(_jsx(PdfView, { content: invalidBase64Content }));
|
|
28
|
-
expect(screen.getByText(errorText)).toBeInTheDocument();
|
|
29
|
-
});
|
|
30
|
-
it('applies the provided class names', function () {
|
|
31
|
-
var className = 'custom-class';
|
|
32
|
-
render(_jsx(PdfView, { content: validBase64Content, className: className }));
|
|
33
|
-
expect(screen.getByText(buttonText).parentElement).toHaveClass(className);
|
|
34
|
-
});
|
|
35
|
-
it('does not show spinner or loading text if isLoading is false', function () {
|
|
36
|
-
render(_jsx(PdfView, { content: validBase64Content }));
|
|
37
|
-
// The component should not be in a loading state initially
|
|
38
|
-
expect(screen.queryByTestId('spinnertest')).not.toBeInTheDocument();
|
|
39
|
-
expect(screen.queryByText(loadingText)).not.toBeInTheDocument();
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./PdfView";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./PdfView";
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export interface ProgressProps {
|
|
3
|
-
value: number;
|
|
4
|
-
max: number;
|
|
5
|
-
className?: string;
|
|
6
|
-
barContainerClassName?: string;
|
|
7
|
-
barClassName?: string;
|
|
8
|
-
labelClassName?: string;
|
|
9
|
-
label?: string;
|
|
10
|
-
}
|
|
11
|
-
declare const Progress: React.FC<ProgressProps>;
|
|
12
|
-
export default Progress;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
-
var Progress = function (_a) {
|
|
25
|
-
var value = _a.value, max = _a.max, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.barContainerClassName, barContainerClassName = _c === void 0 ? '' : _c, _d = _a.barClassName, barClassName = _d === void 0 ? '' : _d, _e = _a.labelClassName, labelClassName = _e === void 0 ? '' : _e, label = _a.label, rest = __rest(_a, ["value", "max", "className", "barContainerClassName", "barClassName", "labelClassName", "label"]);
|
|
26
|
-
var percentage = (value / max) * 100;
|
|
27
|
-
return (_jsxs("div", __assign({ className: className }, rest, { children: [label && _jsx("div", { className: labelClassName, children: label }), _jsx("div", { className: barContainerClassName, children: _jsx("div", { "data-testid": "progress-bar", className: barClassName, style: { width: "".concat(percentage, "%") } }) })] })));
|
|
28
|
-
};
|
|
29
|
-
export default Progress;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import '@testing-library/jest-dom';
|
|
4
|
-
import Progress from './Progress';
|
|
5
|
-
describe('Progress Component', function () {
|
|
6
|
-
it('renders the progress bar with correct percentage width', function () {
|
|
7
|
-
render(_jsx(Progress, { value: 50, max: 100, barClassName: "progress-bar" }));
|
|
8
|
-
var progressBar = screen.getByTestId('progress-bar');
|
|
9
|
-
expect(progressBar).toHaveStyle('width: 50%');
|
|
10
|
-
});
|
|
11
|
-
it('renders the label when provided', function () {
|
|
12
|
-
render(_jsx(Progress, { value: 30, max: 100, label: "Loading", labelClassName: "label-class" }));
|
|
13
|
-
expect(screen.getByText('Loading')).toHaveClass('label-class');
|
|
14
|
-
});
|
|
15
|
-
it('does not render the label when not provided', function () {
|
|
16
|
-
render(_jsx(Progress, { value: 30, max: 100 }));
|
|
17
|
-
expect(screen.queryByText('Loading')).not.toBeInTheDocument();
|
|
18
|
-
});
|
|
19
|
-
it('handles zero values correctly', function () {
|
|
20
|
-
render(_jsx(Progress, { value: 0, max: 100, barClassName: "progress-bar" }));
|
|
21
|
-
var progressBar = screen.getByTestId('progress-bar');
|
|
22
|
-
expect(progressBar).toHaveStyle('width: 0%');
|
|
23
|
-
});
|
|
24
|
-
it('handles max values correctly', function () {
|
|
25
|
-
render(_jsx(Progress, { value: 100, max: 100, barClassName: "progress-bar" }));
|
|
26
|
-
var progressBar = screen.getByTestId('progress-bar');
|
|
27
|
-
expect(progressBar).toHaveStyle('width: 100%');
|
|
28
|
-
});
|
|
29
|
-
it('handles values greater than max', function () {
|
|
30
|
-
render(_jsx(Progress, { value: 150, max: 100, barClassName: "progress-bar" }));
|
|
31
|
-
var progressBar = screen.getByTestId('progress-bar');
|
|
32
|
-
expect(progressBar).toHaveStyle('width: 150%'); // Matches the component's behavior
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Progress";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./Progress";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
interface RadioButtonProps {
|
|
3
|
-
name: string;
|
|
4
|
-
value: string;
|
|
5
|
-
checked?: boolean;
|
|
6
|
-
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
7
|
-
className?: string;
|
|
8
|
-
inputClassName?: string;
|
|
9
|
-
labelClassName?: string;
|
|
10
|
-
id?: string;
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
}
|
|
13
|
-
declare const CustomRadioButton: React.FC<RadioButtonProps>;
|
|
14
|
-
export default CustomRadioButton;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
-
var CustomRadioButton = function (_a) {
|
|
25
|
-
var name = _a.name, value = _a.value, _b = _a.checked, checked = _b === void 0 ? false : _b, onChange = _a.onChange, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.inputClassName, inputClassName = _d === void 0 ? '' : _d, _e = _a.labelClassName, labelClassName = _e === void 0 ? '' : _e, id = _a.id, rest = __rest(_a, ["name", "value", "checked", "onChange", "className", "inputClassName", "labelClassName", "id"]);
|
|
26
|
-
return (_jsxs("div", { className: className, children: [_jsx("input", __assign({ type: "radio", name: name, value: value, checked: checked, onChange: onChange, id: id, className: inputClassName }, rest)), _jsx("label", { htmlFor: id, className: labelClassName, children: value })] }));
|
|
27
|
-
};
|
|
28
|
-
export default CustomRadioButton;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
-
import '@testing-library/jest-dom';
|
|
4
|
-
import CustomRadioButton from './RadioButton';
|
|
5
|
-
describe('CustomRadioButton', function () {
|
|
6
|
-
it('should render with given props', function () {
|
|
7
|
-
render(_jsx(CustomRadioButton, { name: "testName", value: "testValue", checked: true, onChange: function () { }, className: "custom-class", inputClassName: "input-class", labelClassName: "label-class", id: "radio1" }));
|
|
8
|
-
var radioInput = screen.getByRole('radio');
|
|
9
|
-
var label = screen.getByText('testValue'); // Use text to find the label
|
|
10
|
-
// Assert that the radio input is rendered correctly
|
|
11
|
-
expect(radioInput).toBeInTheDocument();
|
|
12
|
-
expect(radioInput).toHaveAttribute('name', 'testName');
|
|
13
|
-
expect(radioInput).toHaveAttribute('value', 'testValue');
|
|
14
|
-
expect(radioInput).toBeChecked();
|
|
15
|
-
expect(radioInput).toHaveClass('input-class');
|
|
16
|
-
// Assert that the label is rendered correctly
|
|
17
|
-
expect(label).toBeInTheDocument();
|
|
18
|
-
// Ensure the label has the correct class by finding the label element directly
|
|
19
|
-
var labelElement = document.querySelector("label[for=\"radio1\"]");
|
|
20
|
-
expect(labelElement).toHaveClass('label-class');
|
|
21
|
-
});
|
|
22
|
-
it('should call onChange handler when clicked', function () {
|
|
23
|
-
var handleChange = jest.fn();
|
|
24
|
-
render(_jsx(CustomRadioButton, { name: "testName", value: "testValue", onChange: handleChange, id: "radio1" }));
|
|
25
|
-
var radioInput = screen.getByRole('radio');
|
|
26
|
-
fireEvent.click(radioInput);
|
|
27
|
-
expect(handleChange).toHaveBeenCalled();
|
|
28
|
-
});
|
|
29
|
-
});
|