@onewelcome/react-lib-components 0.1.5-alpha → 0.1.6-alpha
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/dist/react-lib-components.cjs.development.js +4 -3
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +4 -3
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/Form/Toggle/Toggle.test.tsx +45 -19
- package/src/Form/Toggle/Toggle.tsx +2 -2
package/package.json
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { Toggle } from './Toggle';
|
|
1
|
+
import React, { useRef, useEffect } from 'react';
|
|
2
|
+
import { Toggle, Props } from './Toggle';
|
|
3
3
|
import { render } from '@testing-library/react';
|
|
4
4
|
|
|
5
|
+
const defaultParams: Props = {
|
|
6
|
+
children: 'label',
|
|
7
|
+
name: 'example toggle',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const createToggle = (params?: (defaultParams: Props) => Props) => {
|
|
11
|
+
let parameters: Props = defaultParams;
|
|
12
|
+
if (params) {
|
|
13
|
+
parameters = params(defaultParams);
|
|
14
|
+
}
|
|
15
|
+
const queries = render(
|
|
16
|
+
<Toggle {...parameters} data-testid="toggle">
|
|
17
|
+
toggle content
|
|
18
|
+
</Toggle>
|
|
19
|
+
);
|
|
20
|
+
const toggle = queries.getByTestId('toggle');
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
...queries,
|
|
24
|
+
toggle,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
5
28
|
describe('Toggle should render', () => {
|
|
6
29
|
it('renders without crashing', () => {
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
30
|
+
const { toggle } = createToggle();
|
|
31
|
+
|
|
32
|
+
expect(toggle).toBeDefined();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('Toggle attributes', () => {
|
|
37
|
+
it('should be checked', () => {
|
|
38
|
+
const { toggle } = createToggle((defaultParams) => ({ ...defaultParams, checked: true }));
|
|
39
|
+
|
|
40
|
+
expect(toggle).toHaveAttribute('aria-checked', 'true');
|
|
14
41
|
});
|
|
15
42
|
});
|
|
16
43
|
|
|
@@ -29,7 +56,7 @@ describe('ref should work', () => {
|
|
|
29
56
|
}
|
|
30
57
|
}, [ref]);
|
|
31
58
|
|
|
32
|
-
return <Toggle
|
|
59
|
+
return <Toggle {...defaultParams} data-ref="testing" ref={ref} />;
|
|
33
60
|
};
|
|
34
61
|
|
|
35
62
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
@@ -40,16 +67,15 @@ describe('ref should work', () => {
|
|
|
40
67
|
});
|
|
41
68
|
});
|
|
42
69
|
|
|
43
|
-
describe('
|
|
44
|
-
it('
|
|
45
|
-
const { getByTestId } =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
70
|
+
describe('helperProps should be properly propagated down', () => {
|
|
71
|
+
it('renders an anchor tag as helper', () => {
|
|
72
|
+
const { getByTestId } = createToggle((defaultParams) => ({
|
|
73
|
+
...defaultParams,
|
|
74
|
+
helperProps: { children: <a data-testid="helpertextanchor">test</a> },
|
|
75
|
+
}));
|
|
50
76
|
|
|
51
|
-
const
|
|
77
|
+
const helperTextAnchor = getByTestId('helpertextanchor');
|
|
52
78
|
|
|
53
|
-
expect(
|
|
79
|
+
expect(helperTextAnchor).toBeTruthy();
|
|
54
80
|
});
|
|
55
81
|
});
|
|
@@ -9,14 +9,14 @@ export interface Props
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const Toggle = React.forwardRef<HTMLInputElement, Props>(
|
|
12
|
-
({ children, checked, disabled, ...rest }: Props, ref) => (
|
|
12
|
+
({ children, checked, disabled, helperProps, ...rest }: Props, ref) => (
|
|
13
13
|
<div className={classes['toggle-wrapper']}>
|
|
14
14
|
<Checkbox
|
|
15
15
|
{...rest}
|
|
16
16
|
ref={ref}
|
|
17
17
|
checked={checked}
|
|
18
18
|
className={classes['checkbox']}
|
|
19
|
-
helperProps={{ className: classes['toggle-helper'] }}
|
|
19
|
+
helperProps={{ className: classes['toggle-helper'], ...helperProps }}
|
|
20
20
|
disabled={disabled}
|
|
21
21
|
label={children}
|
|
22
22
|
>
|