@bytebrand/fe-ui-core 4.2.65 → 4.2.66
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/__tests__/components/_common/MaterialField/MaterialField.test.tsx +58 -0
- package/package.json +1 -1
- package/source/components/_common/MaterialField/MaterialField.styled.tsx +6 -6
- package/source/components/_common/MaterialField/MaterialField.tsx +1 -1
- package/source/framework/utils/CommonUtils.ts +12 -0
- package/utils.ts +3 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import MaterialField from '../../../../source/components/_common/MaterialField/MaterialField';
|
|
4
|
+
|
|
5
|
+
describe('MaterialField', () => {
|
|
6
|
+
const props = {
|
|
7
|
+
label: 'Test Label',
|
|
8
|
+
value: 'Test Value',
|
|
9
|
+
onChange: jest.fn(),
|
|
10
|
+
disabled: false,
|
|
11
|
+
type: 'text',
|
|
12
|
+
autoComplete: 'off',
|
|
13
|
+
name: 'testName',
|
|
14
|
+
required: true,
|
|
15
|
+
multiline: false,
|
|
16
|
+
rows: 1,
|
|
17
|
+
placeholder: 'Test Placeholder'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
it('renders the input element with the correct props', () => {
|
|
21
|
+
const { getByRole } = render(<MaterialField size='medium' {...props} />);
|
|
22
|
+
const inputElement = getByRole('textbox');
|
|
23
|
+
expect(inputElement).toBeInTheDocument();
|
|
24
|
+
expect(inputElement).toHaveAttribute('type', 'text');
|
|
25
|
+
expect(inputElement).toHaveAttribute('value', 'Test Value');
|
|
26
|
+
expect(inputElement).toHaveAttribute('name', 'testName');
|
|
27
|
+
expect(inputElement).toHaveAttribute('required');
|
|
28
|
+
expect(inputElement).toHaveAttribute('placeholder', 'Test Placeholder');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('calls the onChange prop when the input value changes', () => {
|
|
32
|
+
const { getByRole } = render(<MaterialField size='medium' {...props} />);
|
|
33
|
+
const inputElement = getByRole('textbox');
|
|
34
|
+
fireEvent.change(inputElement, { target: { value: 'New Value' } });
|
|
35
|
+
expect(props.onChange).toHaveBeenCalledTimes(1);
|
|
36
|
+
expect(props.onChange).toHaveBeenCalledWith('New Value', 'testName', expect.anything());
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('toggles password visibility when the icon button is clicked', () => {
|
|
40
|
+
const passwordProps = {
|
|
41
|
+
...props,
|
|
42
|
+
type: 'password'
|
|
43
|
+
}
|
|
44
|
+
const { getByRole, getByPlaceholderText } = render(<MaterialField size='medium' {...passwordProps} />);
|
|
45
|
+
const iconButton = getByRole('button');
|
|
46
|
+
const inputElement = getByPlaceholderText('Test Placeholder');
|
|
47
|
+
fireEvent.click(iconButton);
|
|
48
|
+
expect(inputElement).toHaveAttribute('type', 'text');
|
|
49
|
+
|
|
50
|
+
fireEvent.click(iconButton);
|
|
51
|
+
|
|
52
|
+
expect(inputElement).toHaveAttribute('type', 'password');
|
|
53
|
+
|
|
54
|
+
fireEvent.click(iconButton);
|
|
55
|
+
|
|
56
|
+
expect(inputElement).toHaveAttribute('type', 'text');
|
|
57
|
+
});
|
|
58
|
+
});
|
package/package.json
CHANGED
|
@@ -12,14 +12,14 @@ export const Theme = createTheme({
|
|
|
12
12
|
},
|
|
13
13
|
MuiInputLabel: {
|
|
14
14
|
styleOverrides: {
|
|
15
|
-
root: ({ ownerState }) => ({
|
|
16
|
-
...(
|
|
15
|
+
root: ({ ownerState: { size } }: { ownerState: { size?: 'smaller' | 'custom' | 'normal' | 'small' | 'medium' } }) => ({
|
|
16
|
+
...(size === 'smaller' && {
|
|
17
17
|
marginTop: '-13px',
|
|
18
18
|
['&.MuiInputLabel-shrink, &.Mui-focused']: {
|
|
19
19
|
marginTop: 0
|
|
20
20
|
}
|
|
21
21
|
}),
|
|
22
|
-
...(
|
|
22
|
+
...(size === 'custom' && {
|
|
23
23
|
marginTop: isMobileOnly ? '0px' :'-4px',
|
|
24
24
|
['&.MuiInputLabel-shrink, &.Mui-focused']: {
|
|
25
25
|
marginTop: 0
|
|
@@ -30,13 +30,13 @@ export const Theme = createTheme({
|
|
|
30
30
|
},
|
|
31
31
|
MuiOutlinedInput: {
|
|
32
32
|
styleOverrides: {
|
|
33
|
-
input: ({ ownerState }) => ({
|
|
34
|
-
...(
|
|
33
|
+
input: ({ ownerState: { size } }: { ownerState: { size?: 'smaller' | 'custom' | 'normal' | 'small' | 'medium' } }) => ({
|
|
34
|
+
...(size === 'smaller' && {
|
|
35
35
|
height: 28,
|
|
36
36
|
boxSizing: 'border-box',
|
|
37
37
|
padding: '0 14px'
|
|
38
38
|
}),
|
|
39
|
-
...(
|
|
39
|
+
...(size === 'custom' && {
|
|
40
40
|
height: isMobileOnly ? 56 : 48,
|
|
41
41
|
boxSizing: 'border-box'
|
|
42
42
|
})
|
|
@@ -64,7 +64,7 @@ const MaterialField: React.FC<IVehicleModalProps> = ({
|
|
|
64
64
|
setShowPassword(!showPassword);
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
const handleMouseDownPassword = (event) => {
|
|
67
|
+
const handleMouseDownPassword = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
|
68
68
|
event.preventDefault();
|
|
69
69
|
};
|
|
70
70
|
|
|
@@ -568,3 +568,15 @@ export const updateCookieList = () => {
|
|
|
568
568
|
// grant Hotjar cookies
|
|
569
569
|
if (isHotjarGranted && typeof window.grantHotjarCookieConsent === 'function') window.grantHotjarCookieConsent();
|
|
570
570
|
};
|
|
571
|
+
|
|
572
|
+
// function returns decimal part of number with 2 digits
|
|
573
|
+
export const getCents = (value: number, prefix?: string, postfix?: string): string => {
|
|
574
|
+
if (!Number.isFinite(value)) return '';
|
|
575
|
+
const roundedValue = Math.floor(value);
|
|
576
|
+
const result = value.toFixed(2).toString().replace(`${roundedValue}.`, '');
|
|
577
|
+
return `${prefix}${result}${postfix}`;
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
export const priceParse = (value: any) => {
|
|
581
|
+
return !!value ? Number.parseFloat(value) : null;
|
|
582
|
+
};
|