@lumx/react 3.0.3 → 3.0.4-alpha.1
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/_internal/ClickAwayProvider.js +37 -232
- package/_internal/ClickAwayProvider.js.map +1 -1
- package/index.d.ts +10 -2
- package/index.js +4031 -4319
- package/index.js.map +1 -1
- package/package.json +28 -34
- package/src/components/alert-dialog/__snapshots__/AlertDialog.test.tsx.snap +23 -23
- package/src/components/autocomplete/Autocomplete.tsx +8 -0
- package/src/components/autocomplete/__snapshots__/Autocomplete.test.tsx.snap +4 -4
- package/src/components/autocomplete/__snapshots__/AutocompleteMultiple.test.tsx.snap +1 -1
- package/src/components/avatar/__snapshots__/Avatar.test.tsx.snap +6 -6
- package/src/components/button/__snapshots__/ButtonRoot.test.tsx.snap +1 -1
- package/src/components/button/index.ts +1 -0
- package/src/components/date-picker/__snapshots__/DatePicker.test.tsx.snap +2 -2
- package/src/components/date-picker/__snapshots__/DatePickerField.test.tsx.snap +2 -2
- package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +22 -22
- package/src/components/dropdown/Dropdown.tsx +2 -0
- package/src/components/dropdown/__snapshots__/Dropdown.test.tsx.snap +2 -2
- package/src/components/flag/__snapshots__/Flag.test.tsx.snap +1 -1
- package/src/components/flex-box/__snapshots__/FlexBox.test.tsx.snap +31 -31
- package/src/components/heading/Heading.test.tsx +32 -27
- package/src/components/icon/__snapshots__/Icon.test.tsx.snap +2 -2
- package/src/components/image-block/__snapshots__/ImageBlock.test.tsx.snap +1 -1
- package/src/components/index.ts +5 -0
- package/src/components/inline-list/InlineList.tsx +3 -1
- package/src/components/lightbox/__snapshots__/Lightbox.test.tsx.snap +7 -7
- package/src/components/list/__snapshots__/List.test.tsx.snap +13 -13
- package/src/components/notification/__snapshots__/Notification.test.tsx.snap +1 -1
- package/src/components/popover/__snapshots__/Popover.test.tsx.snap +52 -52
- package/src/components/post-block/__snapshots__/PostBlock.test.tsx.snap +4 -4
- package/src/components/progress-tracker/__snapshots__/ProgressTracker.test.tsx.snap +2 -2
- package/src/components/select/__snapshots__/Select.test.tsx.snap +2 -2
- package/src/components/select/__snapshots__/SelectMultiple.test.tsx.snap +6 -6
- package/src/components/skeleton/__snapshots__/SkeletonCircle.test.tsx.snap +1 -1
- package/src/components/skeleton/__snapshots__/SkeletonRectangle.test.tsx.snap +1 -1
- package/src/components/skeleton/__snapshots__/SkeletonTypography.test.tsx.snap +15 -15
- package/src/components/slider/__snapshots__/Slider.test.tsx.snap +4 -4
- package/src/components/slideshow/__snapshots__/Slideshow.test.tsx.snap +10 -10
- package/src/components/table/__snapshots__/Table.test.tsx.snap +1 -1
- package/src/components/text/Text.test.tsx +67 -35
- package/src/components/text/Text.tsx +8 -7
- package/src/components/text-field/TextField.test.tsx +75 -117
- package/src/components/text-field/__snapshots__/TextField.test.tsx.snap +12 -17
- package/src/components/thumbnail/__snapshots__/Thumbnail.test.tsx.snap +6 -6
- package/src/components/tooltip/__snapshots__/Tooltip.test.tsx.snap +6 -6
- package/src/components/user-block/__snapshots__/UserBlock.test.tsx.snap +11 -11
- package/src/stories/generated/Dropdown/Demos.stories.tsx +1 -0
- package/src/testing/utils/commonTestsSuiteRTL.ts +55 -0
- package/src/testing/utils/index.ts +1 -0
- package/src/testing/utils/queries.ts +19 -0
- package/src/utils/focus/getFocusableElements.test.ts +12 -12
- package/types.d.ts +0 -2847
|
@@ -1,76 +1,108 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import 'jest-enzyme';
|
|
5
|
-
|
|
6
|
-
import { commonTestsSuite } from '@lumx/react/testing/utils';
|
|
3
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
7
4
|
import { mdiEarth } from '@lumx/icons';
|
|
8
5
|
import { Icon } from '@lumx/react';
|
|
6
|
+
import { render } from '@testing-library/react';
|
|
7
|
+
import { getByClassName } from '@lumx/react/testing/utils/queries';
|
|
9
8
|
import { Text, TextProps } from '.';
|
|
10
9
|
|
|
11
10
|
const setup = (props: Partial<TextProps> = {}) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
const { container } = render(<Text as="span" {...props} />);
|
|
12
|
+
const element = getByClassName(container, Text.className as string);
|
|
13
|
+
return { props, container, element };
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
describe(`<${Text.displayName}>`, () => {
|
|
17
|
-
describe('
|
|
17
|
+
describe('Render', () => {
|
|
18
18
|
it('should render default', () => {
|
|
19
|
-
const {
|
|
20
|
-
expect(
|
|
21
|
-
expect(wrapper.prop('className')).toBe(Text.className);
|
|
19
|
+
const { element } = setup({ children: 'Some text' });
|
|
20
|
+
expect(element.tagName).toBe('SPAN');
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
it('should render with as', () => {
|
|
25
|
-
const {
|
|
26
|
-
expect(
|
|
27
|
-
expect(wrapper.prop('className')).toBe(Text.className);
|
|
24
|
+
const { element } = setup({ children: 'Some text', as: 'p' });
|
|
25
|
+
expect(element.tagName).toBe('P');
|
|
28
26
|
});
|
|
29
27
|
|
|
30
28
|
it('should render with typography', () => {
|
|
31
|
-
const {
|
|
32
|
-
expect(
|
|
33
|
-
expect(
|
|
29
|
+
const { element } = setup({ typography: 'body2', children: 'Some text' });
|
|
30
|
+
expect(element.tagName).toBe('SPAN');
|
|
31
|
+
expect(element).toHaveClass('lumx-typography-body2');
|
|
34
32
|
});
|
|
35
33
|
|
|
36
34
|
it('should render with color', () => {
|
|
37
|
-
const {
|
|
38
|
-
expect(
|
|
39
|
-
expect(
|
|
35
|
+
const { element } = setup({ color: 'blue', children: 'Some text' });
|
|
36
|
+
expect(element.tagName).toBe('SPAN');
|
|
37
|
+
expect(element).toHaveClass('lumx-color-font-blue-N');
|
|
40
38
|
});
|
|
41
39
|
|
|
42
40
|
it('should render with color and variant', () => {
|
|
43
|
-
const {
|
|
44
|
-
expect(
|
|
45
|
-
expect(
|
|
41
|
+
const { element } = setup({ color: 'blue', colorVariant: 'D2', children: 'Some text' });
|
|
42
|
+
expect(element.tagName).toBe('SPAN');
|
|
43
|
+
expect(element).toHaveClass('lumx-color-font-blue-D2');
|
|
46
44
|
});
|
|
47
45
|
|
|
48
46
|
it('should render truncated', () => {
|
|
49
|
-
const {
|
|
50
|
-
expect(
|
|
51
|
-
expect(
|
|
47
|
+
const { element } = setup({ truncate: true });
|
|
48
|
+
expect(element.tagName).toBe('SPAN');
|
|
49
|
+
expect(element).toHaveClass('lumx-text--is-truncated');
|
|
52
50
|
});
|
|
53
51
|
|
|
54
52
|
it('should render truncated multiline', () => {
|
|
55
|
-
const {
|
|
56
|
-
expect(
|
|
57
|
-
expect(
|
|
58
|
-
expect(wrapper).toHaveStyle({ '--lumx-text-truncate-lines': 2 });
|
|
53
|
+
const { element } = setup({ truncate: { lines: 2 } });
|
|
54
|
+
expect(element.tagName).toBe('SPAN');
|
|
55
|
+
expect(element).toHaveClass('lumx-text--is-truncated-multiline');
|
|
59
56
|
});
|
|
60
57
|
|
|
61
58
|
it('should render noWrap', () => {
|
|
62
|
-
const {
|
|
63
|
-
expect(
|
|
64
|
-
expect(
|
|
59
|
+
const { element } = setup({ noWrap: true });
|
|
60
|
+
expect(element.tagName).toBe('SPAN');
|
|
61
|
+
expect(element).toHaveClass('lumx-text--no-wrap');
|
|
65
62
|
});
|
|
66
63
|
|
|
67
64
|
it('should wrap icons with spaces', () => {
|
|
68
|
-
const {
|
|
65
|
+
const { element } = setup({ children: ['Some text', <Icon key="icon" icon={mdiEarth} />, 'with icon'] });
|
|
69
66
|
// Spaces have been inserted around the icon.
|
|
70
|
-
expect(
|
|
67
|
+
expect(element).toMatchInlineSnapshot(`
|
|
68
|
+
<span
|
|
69
|
+
class="lumx-text"
|
|
70
|
+
>
|
|
71
|
+
Some text
|
|
72
|
+
|
|
73
|
+
<i
|
|
74
|
+
class="lumx-icon lumx-icon--no-shape lumx-icon--path"
|
|
75
|
+
>
|
|
76
|
+
<svg
|
|
77
|
+
aria-hidden="true"
|
|
78
|
+
height="1em"
|
|
79
|
+
preserveAspectRatio="xMidYMid meet"
|
|
80
|
+
style="vertical-align: -0.125em;"
|
|
81
|
+
viewBox="0 0 24 24"
|
|
82
|
+
width="1em"
|
|
83
|
+
>
|
|
84
|
+
<path
|
|
85
|
+
d="M17.9,17.39C17.64,16.59 16.89,16 16,16H15V13A1,1 0 0,0 14,12H8V10H10A1,1 0 0,0 11,9V7H13A2,2 0 0,0 15,5V4.59C17.93,5.77 20,8.64 20,12C20,14.08 19.2,15.97 17.9,17.39M11,19.93C7.05,19.44 4,16.08 4,12C4,11.38 4.08,10.78 4.21,10.21L9,15V16A2,2 0 0,0 11,18M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"
|
|
86
|
+
fill="currentColor"
|
|
87
|
+
/>
|
|
88
|
+
</svg>
|
|
89
|
+
</i>
|
|
90
|
+
|
|
91
|
+
with icon
|
|
92
|
+
</span>
|
|
93
|
+
`);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should render dangerouslySetInnerHTML', () => {
|
|
97
|
+
const { element } = setup({ dangerouslySetInnerHTML: { __html: '<strong>HTML text</strong>' } });
|
|
98
|
+
expect(element).toHaveTextContent('HTML text');
|
|
71
99
|
});
|
|
72
100
|
});
|
|
73
101
|
|
|
74
102
|
// Common tests suite.
|
|
75
|
-
|
|
103
|
+
commonTestsSuiteRTL(setup, {
|
|
104
|
+
baseClassName: Text.className as string,
|
|
105
|
+
forwardClassName: 'element',
|
|
106
|
+
forwardAttributes: 'element',
|
|
107
|
+
});
|
|
76
108
|
});
|
|
@@ -105,13 +105,14 @@ export const Text: Comp<TextProps> = forwardRef((props, ref) => {
|
|
|
105
105
|
style={{ ...truncateLinesStyle, ...style }}
|
|
106
106
|
{...forwardedProps}
|
|
107
107
|
>
|
|
108
|
-
{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
{children &&
|
|
109
|
+
Children.toArray(children).map((child, index) => {
|
|
110
|
+
// Force wrap spaces around icons to make sure they are never stuck against text.
|
|
111
|
+
if (isComponent(Icon)(child)) {
|
|
112
|
+
return <Fragment key={child.key || index}> {child} </Fragment>;
|
|
113
|
+
}
|
|
114
|
+
return child;
|
|
115
|
+
})}
|
|
115
116
|
</Component>
|
|
116
117
|
);
|
|
117
118
|
});
|
|
@@ -1,144 +1,117 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import 'jest-enzyme';
|
|
5
|
-
import { build } from 'test-data-bot';
|
|
3
|
+
import camelCase from 'lodash/camelCase';
|
|
6
4
|
|
|
7
|
-
import {
|
|
5
|
+
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
8
6
|
import { getBasicClass } from '@lumx/react/utils/className';
|
|
9
7
|
|
|
10
|
-
import {
|
|
8
|
+
import { render } from '@testing-library/react';
|
|
9
|
+
import { getByClassName, getByTagName, queryAllByClassName, queryByTagName } from '@lumx/react/testing/utils/queries';
|
|
10
|
+
import partition from 'lodash/partition';
|
|
11
|
+
import userEvent from '@testing-library/user-event';
|
|
12
|
+
|
|
11
13
|
import { TextField, TextFieldProps } from './TextField';
|
|
12
14
|
|
|
13
15
|
const CLASSNAME = TextField.className as string;
|
|
14
16
|
|
|
15
|
-
type SetupProps = Partial<TextFieldProps>;
|
|
16
|
-
|
|
17
17
|
/**
|
|
18
18
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
19
19
|
*/
|
|
20
|
-
const setup = (propsOverride:
|
|
20
|
+
const setup = (propsOverride: Partial<TextFieldProps> = {}) => {
|
|
21
21
|
const props: any = { ...propsOverride };
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
30
|
-
const helper = wrapper.findWhere(
|
|
31
|
-
(n: ShallowWrapper | ReactWrapper) => n.name() === 'InputHelper' && n.prop('kind') === Kind.info,
|
|
32
|
-
);
|
|
22
|
+
const { container } = render(<TextField {...props} />);
|
|
23
|
+
|
|
24
|
+
const element = getByClassName(container, CLASSNAME);
|
|
25
|
+
const inputNative = (queryByTagName(container, 'textarea') || getByTagName(container, 'input')) as
|
|
26
|
+
| HTMLTextAreaElement
|
|
27
|
+
| HTMLInputElement;
|
|
28
|
+
const helpers = queryAllByClassName(container, 'lumx-text-field__helper');
|
|
29
|
+
const [[helper], [error]] = partition(helpers, (h) => !h.className.includes('lumx-input-helper--color-red'));
|
|
33
30
|
|
|
34
31
|
return {
|
|
32
|
+
props,
|
|
33
|
+
container,
|
|
34
|
+
element,
|
|
35
|
+
inputNative,
|
|
35
36
|
error,
|
|
36
37
|
helper,
|
|
37
|
-
inputNative: textarea.length ? textarea : input,
|
|
38
|
-
props,
|
|
39
|
-
wrapper,
|
|
40
38
|
};
|
|
41
39
|
};
|
|
42
40
|
|
|
43
41
|
describe(`<${TextField.displayName}>`, () => {
|
|
44
|
-
|
|
45
|
-
describe('Snapshots and structure', () => {
|
|
42
|
+
describe('Render', () => {
|
|
46
43
|
it('should render defaults', () => {
|
|
47
|
-
const {
|
|
48
|
-
expect(
|
|
49
|
-
|
|
50
|
-
expect(
|
|
51
|
-
|
|
52
|
-
expect(
|
|
53
|
-
expect(
|
|
54
|
-
expect(
|
|
55
|
-
expect(
|
|
56
|
-
expect(
|
|
57
|
-
|
|
58
|
-
expect(
|
|
59
|
-
expect(
|
|
60
|
-
|
|
61
|
-
expect(wrapper).toHaveClassName(`${CLASSNAME}--theme-light`);
|
|
62
|
-
|
|
63
|
-
expect(inputNative).toExist();
|
|
64
|
-
expect(inputNative.type()).toEqual('input');
|
|
44
|
+
const { element, inputNative } = setup({ id: 'fixedId' });
|
|
45
|
+
expect(element).toBeInTheDocument();
|
|
46
|
+
expect(element).toMatchSnapshot();
|
|
47
|
+
expect(element).not.toHaveClass(`${CLASSNAME}--is-valid`);
|
|
48
|
+
expect(element).not.toHaveClass(`${CLASSNAME}--has-error`);
|
|
49
|
+
expect(element).not.toHaveClass(`${CLASSNAME}--has-label`);
|
|
50
|
+
expect(element).not.toHaveClass(`${CLASSNAME}--is-disabled`);
|
|
51
|
+
expect(element).not.toHaveClass(`${CLASSNAME}--has-placeholder`);
|
|
52
|
+
expect(element).not.toHaveClass(`${CLASSNAME}--is-focus`);
|
|
53
|
+
expect(element).not.toHaveClass(`${CLASSNAME}--has-icon`);
|
|
54
|
+
|
|
55
|
+
expect(element).toHaveClass(`${CLASSNAME}--theme-light`);
|
|
56
|
+
expect(inputNative.tagName).toBe('INPUT');
|
|
65
57
|
});
|
|
66
58
|
|
|
67
59
|
it('should render textarea', () => {
|
|
68
|
-
const {
|
|
69
|
-
expect(
|
|
70
|
-
|
|
71
|
-
expect(
|
|
72
|
-
|
|
73
|
-
expect(inputNative).toExist();
|
|
74
|
-
expect(inputNative.type()).toEqual('textarea');
|
|
60
|
+
const { element, inputNative } = setup({ id: 'fixedId', multiline: true });
|
|
61
|
+
expect(element).toBeInTheDocument();
|
|
62
|
+
expect(element).toMatchSnapshot();
|
|
63
|
+
expect(inputNative.tagName).toBe('TEXTAREA');
|
|
75
64
|
});
|
|
76
65
|
});
|
|
77
66
|
|
|
78
67
|
// 2. Test defaultProps value and important props custom values.
|
|
79
68
|
describe('Props', () => {
|
|
80
69
|
it('should add all class names (except has-error)', () => {
|
|
81
|
-
const
|
|
70
|
+
const modifiedProps = {
|
|
82
71
|
icon: 'icon',
|
|
83
72
|
isDisabled: true,
|
|
84
73
|
isValid: true,
|
|
85
74
|
label: 'test',
|
|
86
75
|
placeholder: 'test',
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
? `has${prop.charAt(0).toUpperCase() + prop.slice(1)}`
|
|
97
|
-
: prop;
|
|
98
|
-
const propValue =
|
|
99
|
-
prop === 'icon' || prop === 'label' || prop === 'placeholder' ? true : modifiedProps[prop];
|
|
100
|
-
expect(wrapper).toHaveClassName(getBasicClass({ prefix: CLASSNAME, type: propType, value: propValue }));
|
|
101
|
-
});
|
|
76
|
+
};
|
|
77
|
+
const hasProps = ['icon', 'label', 'placeholder'];
|
|
78
|
+
const { element } = setup(modifiedProps);
|
|
79
|
+
|
|
80
|
+
for (const [prop, value] of Object.entries(modifiedProps)) {
|
|
81
|
+
const propType = hasProps.includes(prop) ? camelCase(`has-${prop}`) : prop;
|
|
82
|
+
const propValue = hasProps.includes(prop) ? true : value;
|
|
83
|
+
expect(element).toHaveClass(getBasicClass({ prefix: CLASSNAME, type: propType, value: propValue }));
|
|
84
|
+
}
|
|
102
85
|
});
|
|
103
86
|
|
|
104
87
|
it('should add "has-error" class name', () => {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
});
|
|
88
|
+
const modifiedProps = { hasError: true };
|
|
89
|
+
const { element } = setup(modifiedProps);
|
|
108
90
|
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Object.keys(modifiedProps).forEach((prop) => {
|
|
114
|
-
expect(wrapper).toHaveClassName(
|
|
115
|
-
getBasicClass({ prefix: CLASSNAME, type: prop, value: modifiedProps[prop] }),
|
|
116
|
-
);
|
|
117
|
-
});
|
|
91
|
+
for (const [prop, value] of Object.entries(modifiedProps)) {
|
|
92
|
+
expect(element).toHaveClass(getBasicClass({ prefix: CLASSNAME, type: prop, value }));
|
|
93
|
+
}
|
|
118
94
|
});
|
|
119
95
|
|
|
120
96
|
it('should have text as value', () => {
|
|
121
97
|
const value = 'test';
|
|
122
98
|
const { inputNative } = setup({ value });
|
|
123
|
-
|
|
124
|
-
expect(inputNative).toHaveValue(value);
|
|
99
|
+
expect(inputNative.value).toEqual(value);
|
|
125
100
|
});
|
|
126
101
|
|
|
127
102
|
it('should have no value', () => {
|
|
128
103
|
const value = undefined;
|
|
129
104
|
const { inputNative } = setup({ value });
|
|
130
|
-
|
|
131
|
-
expect(inputNative).toHaveValue(value);
|
|
105
|
+
expect(inputNative.value).toEqual('');
|
|
132
106
|
});
|
|
133
107
|
|
|
134
108
|
it('should have helper text', () => {
|
|
135
109
|
const { helper } = setup({
|
|
136
|
-
helper: '
|
|
110
|
+
helper: 'helper',
|
|
137
111
|
label: 'test',
|
|
138
112
|
placeholder: 'test',
|
|
139
113
|
});
|
|
140
|
-
|
|
141
|
-
expect(helper).toHaveLength(1);
|
|
114
|
+
expect(helper).toHaveTextContent('helper');
|
|
142
115
|
});
|
|
143
116
|
|
|
144
117
|
it('should have error text', () => {
|
|
@@ -148,8 +121,7 @@ describe(`<${TextField.displayName}>`, () => {
|
|
|
148
121
|
label: 'test',
|
|
149
122
|
placeholder: 'test',
|
|
150
123
|
});
|
|
151
|
-
|
|
152
|
-
expect(error).toHaveLength(1);
|
|
124
|
+
expect(error).toHaveTextContent('error');
|
|
153
125
|
});
|
|
154
126
|
|
|
155
127
|
it('should not have error text', () => {
|
|
@@ -159,8 +131,7 @@ describe(`<${TextField.displayName}>`, () => {
|
|
|
159
131
|
label: 'test',
|
|
160
132
|
placeholder: 'test',
|
|
161
133
|
});
|
|
162
|
-
|
|
163
|
-
expect(error).toHaveLength(0);
|
|
134
|
+
expect(error).not.toBeDefined();
|
|
164
135
|
});
|
|
165
136
|
|
|
166
137
|
it('should have error and helper text', () => {
|
|
@@ -171,43 +142,30 @@ describe(`<${TextField.displayName}>`, () => {
|
|
|
171
142
|
label: 'test',
|
|
172
143
|
placeholder: 'test',
|
|
173
144
|
});
|
|
174
|
-
|
|
175
|
-
expect(
|
|
176
|
-
expect(helper).toHaveLength(1);
|
|
145
|
+
expect(error).toHaveTextContent('error');
|
|
146
|
+
expect(helper).toHaveTextContent('helper');
|
|
177
147
|
});
|
|
178
148
|
});
|
|
179
149
|
|
|
180
150
|
// 3. Test events.
|
|
181
151
|
describe('Events', () => {
|
|
182
|
-
|
|
152
|
+
it('should trigger `onChange` when text field is changed', async () => {
|
|
153
|
+
const onChange = jest.fn();
|
|
154
|
+
const { inputNative } = setup({ value: '', name: 'name', onChange });
|
|
183
155
|
|
|
184
|
-
|
|
156
|
+
await userEvent.tab();
|
|
157
|
+
expect(inputNative).toHaveFocus();
|
|
185
158
|
|
|
186
|
-
|
|
187
|
-
const onChangeMock = jest.fn();
|
|
188
|
-
const event = {
|
|
189
|
-
target: { value: 'my value' },
|
|
190
|
-
};
|
|
191
|
-
const component = shallow(<TextField value="" name="my name" onChange={onChangeMock} />);
|
|
192
|
-
component.find('input').simulate('change', event);
|
|
193
|
-
expect(onChangeMock).toBeCalledWith('my value', 'my name', {
|
|
194
|
-
target: {
|
|
195
|
-
value: 'my value',
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
159
|
+
await userEvent.keyboard('a');
|
|
200
160
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
// Nothing to do here.
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// 5. Test state.
|
|
207
|
-
describe('State', () => {
|
|
208
|
-
// Nothing to do here.
|
|
161
|
+
expect(onChange).toHaveBeenCalledWith('a', 'name', expect.objectContaining({}));
|
|
162
|
+
});
|
|
209
163
|
});
|
|
210
164
|
|
|
211
165
|
// Common tests suite.
|
|
212
|
-
|
|
166
|
+
commonTestsSuiteRTL(setup, {
|
|
167
|
+
baseClassName: CLASSNAME,
|
|
168
|
+
forwardClassName: 'element',
|
|
169
|
+
forwardAttributes: 'inputNative',
|
|
170
|
+
});
|
|
213
171
|
});
|
|
@@ -1,45 +1,40 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`<TextField>
|
|
3
|
+
exports[`<TextField> Render should render defaults 1`] = `
|
|
4
4
|
<div
|
|
5
|
-
|
|
5
|
+
class="lumx-text-field lumx-text-field--has-input lumx-text-field--theme-light"
|
|
6
6
|
>
|
|
7
7
|
<div
|
|
8
|
-
|
|
8
|
+
class="lumx-text-field__wrapper"
|
|
9
9
|
>
|
|
10
10
|
<div
|
|
11
|
-
|
|
11
|
+
class="lumx-text-field__input-wrapper"
|
|
12
12
|
>
|
|
13
13
|
<input
|
|
14
|
-
|
|
14
|
+
class="lumx-text-field__input-native lumx-text-field__input-native--text"
|
|
15
15
|
id="fixedId"
|
|
16
|
-
onBlur={[Function]}
|
|
17
|
-
onChange={[Function]}
|
|
18
|
-
onFocus={[Function]}
|
|
19
16
|
type="text"
|
|
17
|
+
value=""
|
|
20
18
|
/>
|
|
21
19
|
</div>
|
|
22
20
|
</div>
|
|
23
21
|
</div>
|
|
24
22
|
`;
|
|
25
23
|
|
|
26
|
-
exports[`<TextField>
|
|
24
|
+
exports[`<TextField> Render should render textarea 1`] = `
|
|
27
25
|
<div
|
|
28
|
-
|
|
26
|
+
class="lumx-text-field lumx-text-field--has-textarea lumx-text-field--theme-light"
|
|
29
27
|
>
|
|
30
28
|
<div
|
|
31
|
-
|
|
29
|
+
class="lumx-text-field__wrapper"
|
|
32
30
|
>
|
|
33
31
|
<div
|
|
34
|
-
|
|
32
|
+
class="lumx-text-field__input-wrapper"
|
|
35
33
|
>
|
|
36
34
|
<textarea
|
|
37
|
-
|
|
35
|
+
class="lumx-text-field__input-native lumx-text-field__input-native--textarea"
|
|
38
36
|
id="fixedId"
|
|
39
|
-
|
|
40
|
-
onChange={[Function]}
|
|
41
|
-
onFocus={[Function]}
|
|
42
|
-
rows={2}
|
|
37
|
+
rows="2"
|
|
43
38
|
/>
|
|
44
39
|
</div>
|
|
45
40
|
</div>
|
|
@@ -15,7 +15,7 @@ exports[`<Thumbnail> Snapshots and structure should render story 'Clickable' 1`]
|
|
|
15
15
|
className="lumx-thumbnail__image lumx-thumbnail__image--is-loading"
|
|
16
16
|
loading="lazy"
|
|
17
17
|
src="/demo-assets/landscape1.jpg"
|
|
18
|
-
style={
|
|
18
|
+
style={{}}
|
|
19
19
|
/>
|
|
20
20
|
</div>
|
|
21
21
|
</button>
|
|
@@ -34,7 +34,7 @@ exports[`<Thumbnail> Snapshots and structure should render story 'ClickableCusto
|
|
|
34
34
|
className="lumx-thumbnail__image lumx-thumbnail__image--is-loading"
|
|
35
35
|
loading="lazy"
|
|
36
36
|
src="/demo-assets/landscape1.jpg"
|
|
37
|
-
style={
|
|
37
|
+
style={{}}
|
|
38
38
|
/>
|
|
39
39
|
</div>
|
|
40
40
|
</CustomLink>
|
|
@@ -53,7 +53,7 @@ exports[`<Thumbnail> Snapshots and structure should render story 'ClickableLink'
|
|
|
53
53
|
className="lumx-thumbnail__image lumx-thumbnail__image--is-loading"
|
|
54
54
|
loading="lazy"
|
|
55
55
|
src="/demo-assets/landscape1.jpg"
|
|
56
|
-
style={
|
|
56
|
+
style={{}}
|
|
57
57
|
/>
|
|
58
58
|
</div>
|
|
59
59
|
</a>
|
|
@@ -71,7 +71,7 @@ exports[`<Thumbnail> Snapshots and structure should render story 'Default' 1`] =
|
|
|
71
71
|
className="lumx-thumbnail__image lumx-thumbnail__image--is-loading"
|
|
72
72
|
loading="lazy"
|
|
73
73
|
src="/demo-assets/landscape1.jpg"
|
|
74
|
-
style={
|
|
74
|
+
style={{}}
|
|
75
75
|
/>
|
|
76
76
|
</div>
|
|
77
77
|
</div>
|
|
@@ -89,7 +89,7 @@ exports[`<Thumbnail> Snapshots and structure should render story 'WithBadge' 1`]
|
|
|
89
89
|
className="lumx-thumbnail__image lumx-thumbnail__image--is-loading"
|
|
90
90
|
loading="lazy"
|
|
91
91
|
src="/demo-assets/landscape1.jpg"
|
|
92
|
-
style={
|
|
92
|
+
style={{}}
|
|
93
93
|
/>
|
|
94
94
|
</div>
|
|
95
95
|
<Badge
|
|
@@ -115,7 +115,7 @@ exports[`<Thumbnail> Snapshots and structure should render story 'WithCustomImag
|
|
|
115
115
|
className="lumx-thumbnail__image lumx-thumbnail__image--is-loading custom-image-class-name"
|
|
116
116
|
loading="lazy"
|
|
117
117
|
src="/demo-assets/landscape1.jpg"
|
|
118
|
-
style={
|
|
118
|
+
style={{}}
|
|
119
119
|
/>
|
|
120
120
|
</div>
|
|
121
121
|
<Badge
|
|
@@ -19,7 +19,7 @@ exports[`<Tooltip> Snapshots and structure should not wrap Button 1`] = `
|
|
|
19
19
|
id="tooltip-uid"
|
|
20
20
|
role="tooltip"
|
|
21
21
|
style={
|
|
22
|
-
|
|
22
|
+
{
|
|
23
23
|
"left": "0",
|
|
24
24
|
"position": "absolute",
|
|
25
25
|
"top": "0",
|
|
@@ -54,7 +54,7 @@ exports[`<Tooltip> Snapshots and structure should not wrap Icon 1`] = `
|
|
|
54
54
|
id="tooltip-uid"
|
|
55
55
|
role="tooltip"
|
|
56
56
|
style={
|
|
57
|
-
|
|
57
|
+
{
|
|
58
58
|
"left": "0",
|
|
59
59
|
"position": "absolute",
|
|
60
60
|
"top": "0",
|
|
@@ -91,7 +91,7 @@ exports[`<Tooltip> Snapshots and structure should render correctly 1`] = `
|
|
|
91
91
|
id="tooltip-uid"
|
|
92
92
|
role="tooltip"
|
|
93
93
|
style={
|
|
94
|
-
|
|
94
|
+
{
|
|
95
95
|
"left": "0",
|
|
96
96
|
"position": "absolute",
|
|
97
97
|
"top": "0",
|
|
@@ -143,7 +143,7 @@ exports[`<Tooltip> Snapshots and structure should work on disabled elements 1`]
|
|
|
143
143
|
id="tooltip-uid"
|
|
144
144
|
role="tooltip"
|
|
145
145
|
style={
|
|
146
|
-
|
|
146
|
+
{
|
|
147
147
|
"left": "0",
|
|
148
148
|
"position": "absolute",
|
|
149
149
|
"top": "0",
|
|
@@ -180,7 +180,7 @@ exports[`<Tooltip> Snapshots and structure should wrap children 1`] = `
|
|
|
180
180
|
id="tooltip-uid"
|
|
181
181
|
role="tooltip"
|
|
182
182
|
style={
|
|
183
|
-
|
|
183
|
+
{
|
|
184
184
|
"left": "0",
|
|
185
185
|
"position": "absolute",
|
|
186
186
|
"top": "0",
|
|
@@ -212,7 +212,7 @@ exports[`<Tooltip> Snapshots and structure should wrap children 2`] = `
|
|
|
212
212
|
id="tooltip-uid"
|
|
213
213
|
role="tooltip"
|
|
214
214
|
style={
|
|
215
|
-
|
|
215
|
+
{
|
|
216
216
|
"left": "0",
|
|
217
217
|
"position": "absolute",
|
|
218
218
|
"top": "0",
|