@patternfly/react-core 4.236.3 → 4.236.4
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/CHANGELOG.md +8 -0
- package/dist/esm/components/AboutModal/AboutModal.js +2 -2
- package/dist/esm/components/AboutModal/AboutModal.js.map +1 -1
- package/dist/esm/components/ContextSelector/ContextSelector.js +2 -2
- package/dist/esm/components/ContextSelector/ContextSelector.js.map +1 -1
- package/dist/esm/components/ContextSelector/ContextSelectorToggle.d.ts.map +1 -1
- package/dist/esm/components/ContextSelector/ContextSelectorToggle.js +5 -7
- package/dist/esm/components/ContextSelector/ContextSelectorToggle.js.map +1 -1
- package/dist/esm/components/Dropdown/Toggle.d.ts.map +1 -1
- package/dist/esm/components/Dropdown/Toggle.js +2 -3
- package/dist/esm/components/Dropdown/Toggle.js.map +1 -1
- package/dist/esm/components/Modal/Modal.d.ts.map +1 -1
- package/dist/esm/components/Modal/Modal.js +2 -2
- package/dist/esm/components/Modal/Modal.js.map +1 -1
- package/dist/esm/components/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/esm/components/NumberInput/NumberInput.js +3 -3
- package/dist/esm/components/NumberInput/NumberInput.js.map +1 -1
- package/dist/esm/components/OptionsMenu/OptionsMenuToggleWithText.d.ts.map +1 -1
- package/dist/esm/components/OptionsMenu/OptionsMenuToggleWithText.js +2 -3
- package/dist/esm/components/OptionsMenu/OptionsMenuToggleWithText.js.map +1 -1
- package/dist/esm/components/Pagination/Navigation.js +2 -2
- package/dist/esm/components/Pagination/Navigation.js.map +1 -1
- package/dist/esm/components/SearchInput/AdvancedSearchMenu.d.ts.map +1 -1
- package/dist/esm/components/SearchInput/AdvancedSearchMenu.js +2 -3
- package/dist/esm/components/SearchInput/AdvancedSearchMenu.js.map +1 -1
- package/dist/esm/components/Tooltip/Tooltip.js +3 -3
- package/dist/esm/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/esm/components/Wizard/Wizard.js +2 -2
- package/dist/esm/components/Wizard/Wizard.js.map +1 -1
- package/dist/js/components/AboutModal/AboutModal.js +1 -1
- package/dist/js/components/AboutModal/AboutModal.js.map +1 -1
- package/dist/js/components/ContextSelector/ContextSelector.js +1 -1
- package/dist/js/components/ContextSelector/ContextSelector.js.map +1 -1
- package/dist/js/components/ContextSelector/ContextSelectorToggle.d.ts.map +1 -1
- package/dist/js/components/ContextSelector/ContextSelectorToggle.js +4 -6
- package/dist/js/components/ContextSelector/ContextSelectorToggle.js.map +1 -1
- package/dist/js/components/Dropdown/Toggle.d.ts.map +1 -1
- package/dist/js/components/Dropdown/Toggle.js +1 -2
- package/dist/js/components/Dropdown/Toggle.js.map +1 -1
- package/dist/js/components/Modal/Modal.d.ts.map +1 -1
- package/dist/js/components/Modal/Modal.js +1 -1
- package/dist/js/components/Modal/Modal.js.map +1 -1
- package/dist/js/components/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/js/components/NumberInput/NumberInput.js +2 -2
- package/dist/js/components/NumberInput/NumberInput.js.map +1 -1
- package/dist/js/components/OptionsMenu/OptionsMenuToggleWithText.d.ts.map +1 -1
- package/dist/js/components/OptionsMenu/OptionsMenuToggleWithText.js +1 -2
- package/dist/js/components/OptionsMenu/OptionsMenuToggleWithText.js.map +1 -1
- package/dist/js/components/Pagination/Navigation.js +1 -1
- package/dist/js/components/Pagination/Navigation.js.map +1 -1
- package/dist/js/components/SearchInput/AdvancedSearchMenu.d.ts.map +1 -1
- package/dist/js/components/SearchInput/AdvancedSearchMenu.js +1 -2
- package/dist/js/components/SearchInput/AdvancedSearchMenu.js.map +1 -1
- package/dist/js/components/Tooltip/Tooltip.js +2 -2
- package/dist/js/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/js/components/Wizard/Wizard.js +1 -1
- package/dist/js/components/Wizard/Wizard.js.map +1 -1
- package/dist/umd/react-core.min.css +156 -155
- package/dist/umd/react-core.min.js +5 -5
- package/package.json +6 -6
- package/src/components/AboutModal/AboutModal.tsx +2 -2
- package/src/components/AboutModal/__tests__/AboutModal.test.tsx +5 -2
- package/src/components/Alert/__tests__/Alert.test.tsx +3 -2
- package/src/components/AlertGroup/__tests__/AlertGroup.test.tsx +6 -4
- package/src/components/Card/examples/CardLegacySelectable.tsx +1 -1
- package/src/components/Checkbox/__tests__/Checkbox.test.tsx +4 -2
- package/src/components/ChipGroup/__tests__/ChipGroup.test.tsx +4 -2
- package/src/components/ClipboardCopy/__tests__/ClipboardCopyButton.test.tsx +4 -2
- package/src/components/ClipboardCopy/__tests__/ClipboardCopyToggle.test.tsx +4 -2
- package/src/components/ContextSelector/ContextSelector.tsx +2 -2
- package/src/components/ContextSelector/ContextSelectorToggle.tsx +5 -9
- package/src/components/ContextSelector/__tests__/ContextSelector.test.tsx +4 -2
- package/src/components/ContextSelector/__tests__/ContextSelectorItem.test.tsx +3 -2
- package/src/components/ContextSelector/__tests__/ContextSelectorToggle.test.tsx +20 -10
- package/src/components/DataList/__tests__/DataList.test.tsx +3 -2
- package/src/components/DataList/__tests__/DataListCheck.test.tsx +3 -2
- package/src/components/Drawer/__tests__/Drawer.test.tsx +6 -3
- package/src/components/Dropdown/Toggle.tsx +2 -3
- package/src/components/Dropdown/__tests__/Dropdown.test.tsx +3 -2
- package/src/components/Dropdown/__tests__/DropdownToggle.test.tsx +6 -4
- package/src/components/Dropdown/__tests__/DropdownToggleAction.test.tsx +3 -2
- package/src/components/Dropdown/__tests__/DropdownToggleCheckbox.test.tsx +4 -2
- package/src/components/ExpandableSection/__tests__/ExpandableSection.test.tsx +3 -2
- package/src/components/Form/__tests__/FormGroup.test.tsx +6 -4
- package/src/components/FormSelect/__tests__/FormSelect.test.tsx +3 -3
- package/src/components/Label/__tests__/Label.test.tsx +4 -2
- package/src/components/LabelGroup/__tests__/LabelGroup.test.tsx +4 -2
- package/src/components/LoginPage/__tests__/LoginForm.test.tsx +9 -6
- package/src/components/Modal/Modal.tsx +2 -2
- package/src/components/Modal/__tests__/Modal.test.tsx +5 -2
- package/src/components/Modal/__tests__/ModalBoxCloseButton.test.tsx +3 -2
- package/src/components/Nav/__tests__/Nav.test.tsx +10 -6
- package/src/components/NumberInput/NumberInput.tsx +3 -3
- package/src/components/NumberInput/__tests__/NumberInput.test.tsx +42 -17
- package/src/components/OptionsMenu/OptionsMenuToggleWithText.tsx +2 -3
- package/src/components/Pagination/Navigation.tsx +2 -2
- package/src/components/Pagination/__tests__/Pagination.test.tsx +83 -44
- package/src/components/Radio/__tests__/Radio.test.tsx +4 -2
- package/src/components/SearchInput/AdvancedSearchMenu.tsx +2 -3
- package/src/components/SearchInput/__tests__/SearchInput.test.tsx +32 -34
- package/src/components/SearchInput/__tests__/__snapshots__/SearchInput.test.tsx.snap +4 -1
- package/src/components/Select/__tests__/Select.test.tsx +17 -9
- package/src/components/Select/__tests__/SelectToggle.test.tsx +14 -8
- package/src/components/SimpleList/__tests__/SimpleList.test.tsx +6 -4
- package/src/components/Switch/__tests__/Switch.test.tsx +4 -2
- package/src/components/Tabs/__tests__/OverflowTab.test.tsx +42 -23
- package/src/components/TextArea/__tests__/TextArea.test.tsx +4 -2
- package/src/components/TextInput/__tests__/TextInput.test.tsx +4 -2
- package/src/components/TextInputGroup/__tests__/TextInputGroupMain.test.tsx +13 -9
- package/src/components/TimePicker/__tests__/TimePicker.test.tsx +36 -26
- package/src/components/ToggleGroup/__tests__/ToggleGroup.test.tsx +4 -2
- package/src/components/Tooltip/Tooltip.tsx +3 -3
- package/src/components/Wizard/Wizard.tsx +2 -2
- package/src/components/Wizard/__tests__/Wizard.test.tsx +18 -14
- package/src/demos/PrimaryDetail.md +1 -1
- package/src/next/components/Wizard/__tests__/Wizard.test.tsx +21 -15
|
@@ -91,7 +91,9 @@ describe('Label', () => {
|
|
|
91
91
|
expect(asFragment()).toMatchSnapshot();
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
test('editable label', () => {
|
|
94
|
+
test('editable label', async () => {
|
|
95
|
+
const user = userEvent.setup();
|
|
96
|
+
|
|
95
97
|
const { asFragment } = render(
|
|
96
98
|
<Label onClose={jest.fn()} onEditCancel={jest.fn()} onEditComplete={jest.fn()} isEditable>
|
|
97
99
|
Something
|
|
@@ -103,7 +105,7 @@ describe('Label', () => {
|
|
|
103
105
|
expect(button).toBeInTheDocument();
|
|
104
106
|
expect(asFragment()).toMatchSnapshot();
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
await user.click(button);
|
|
107
109
|
expect(screen.queryByRole('button', { name: 'Something' })).toBeNull();
|
|
108
110
|
expect(asFragment()).toMatchSnapshot();
|
|
109
111
|
});
|
|
@@ -34,7 +34,9 @@ describe('LabelGroup', () => {
|
|
|
34
34
|
expect(asFragment()).toMatchSnapshot();
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
test('label group expanded', () => {
|
|
37
|
+
test('label group expanded', async () => {
|
|
38
|
+
const user = userEvent.setup();
|
|
39
|
+
|
|
38
40
|
render(
|
|
39
41
|
<LabelGroup>
|
|
40
42
|
<Label>1</Label>
|
|
@@ -47,7 +49,7 @@ describe('LabelGroup', () => {
|
|
|
47
49
|
|
|
48
50
|
expect(showMoreButton.textContent).toBe('1 more');
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
await user.click(showMoreButton);
|
|
51
53
|
expect(showMoreButton.textContent).toBe('Show Less');
|
|
52
54
|
});
|
|
53
55
|
|
|
@@ -11,30 +11,33 @@ describe('LoginForm', () => {
|
|
|
11
11
|
expect(asFragment()).toMatchSnapshot();
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
test('should call onChangeUsername callback', () => {
|
|
14
|
+
test('should call onChangeUsername callback', async () => {
|
|
15
15
|
const mockFn = jest.fn();
|
|
16
|
+
const user = userEvent.setup();
|
|
16
17
|
|
|
17
18
|
render(<LoginForm onChangeUsername={mockFn} rememberMeLabel="Remember me" />);
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
await user.type(screen.getByText('Username'), 'updatedUserName');
|
|
20
21
|
expect(mockFn).toHaveBeenCalled();
|
|
21
22
|
});
|
|
22
23
|
|
|
23
|
-
test('should call onChangePassword callback', () => {
|
|
24
|
+
test('should call onChangePassword callback', async () => {
|
|
24
25
|
const mockFn = jest.fn();
|
|
26
|
+
const user = userEvent.setup();
|
|
25
27
|
|
|
26
28
|
render(<LoginForm onChangePassword={mockFn} rememberMeLabel="Remember me" />);
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
await user.type(screen.getByText('Password'), 'updatedPassword');
|
|
29
31
|
expect(mockFn).toHaveBeenCalled();
|
|
30
32
|
});
|
|
31
33
|
|
|
32
|
-
test('should call onChangeRememberMe callback', () => {
|
|
34
|
+
test('should call onChangeRememberMe callback', async () => {
|
|
33
35
|
const mockFn = jest.fn();
|
|
36
|
+
const user = userEvent.setup();
|
|
34
37
|
|
|
35
38
|
render(<LoginForm onChangeRememberMe={mockFn} rememberMeLabel="Remember me" />);
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
await user.click(screen.getByLabelText('Remember me'));
|
|
38
41
|
expect(mockFn).toHaveBeenCalled();
|
|
39
42
|
});
|
|
40
43
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import * as ReactDOM from 'react-dom';
|
|
3
|
-
import { canUseDOM,
|
|
3
|
+
import { canUseDOM, KeyTypes, PickOptional } from '../../helpers';
|
|
4
4
|
import { css } from '@patternfly/react-styles';
|
|
5
5
|
import styles from '@patternfly/react-styles/css/components/Backdrop/backdrop';
|
|
6
6
|
import { ModalContent } from './ModalContent';
|
|
@@ -120,7 +120,7 @@ export class Modal extends React.Component<ModalProps, ModalState> {
|
|
|
120
120
|
|
|
121
121
|
handleEscKeyClick = (event: KeyboardEvent): void => {
|
|
122
122
|
const { onEscapePress } = this.props;
|
|
123
|
-
if (event.
|
|
123
|
+
if (event.key === KeyTypes.Escape && this.props.isOpen) {
|
|
124
124
|
onEscapePress ? onEscapePress(event) : this.props.onClose();
|
|
125
125
|
}
|
|
126
126
|
};
|
|
@@ -7,6 +7,7 @@ import { css } from '../../../../../react-styles/dist/js';
|
|
|
7
7
|
import styles from '@patternfly/react-styles/css/components/Backdrop/backdrop';
|
|
8
8
|
|
|
9
9
|
import { Modal } from '../Modal';
|
|
10
|
+
import { KeyTypes } from '../../../helpers';
|
|
10
11
|
|
|
11
12
|
jest.spyOn(document, 'createElement');
|
|
12
13
|
jest.spyOn(document.body, 'addEventListener');
|
|
@@ -24,10 +25,12 @@ describe('Modal', () => {
|
|
|
24
25
|
expect(document.createElement).toHaveBeenCalledWith('div');
|
|
25
26
|
});
|
|
26
27
|
|
|
27
|
-
test('modal closes with escape', () => {
|
|
28
|
+
test('modal closes with escape', async () => {
|
|
29
|
+
const user = userEvent.setup();
|
|
30
|
+
|
|
28
31
|
render(<Modal {...props} isOpen appendTo={document.body} />);
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
await user.type(screen.getByText(props.title), `{${KeyTypes.Escape}}`);
|
|
31
34
|
expect(props.onClose).toHaveBeenCalled();
|
|
32
35
|
});
|
|
33
36
|
|
|
@@ -6,12 +6,13 @@ import userEvent from '@testing-library/user-event';
|
|
|
6
6
|
import { ModalBoxCloseButton } from '../ModalBoxCloseButton';
|
|
7
7
|
|
|
8
8
|
describe('ModalBoxCloseButton', () => {
|
|
9
|
-
test('onClose called when clicked', () => {
|
|
9
|
+
test('onClose called when clicked', async () => {
|
|
10
10
|
const onClose = jest.fn();
|
|
11
|
+
const user = userEvent.setup();
|
|
11
12
|
|
|
12
13
|
render(<ModalBoxCloseButton className="test-box-close-button-class" onClose={onClose} />);
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
await user.click(screen.getByRole('button'));
|
|
15
16
|
expect(onClose).toHaveBeenCalledTimes(1);
|
|
16
17
|
});
|
|
17
18
|
});
|
|
@@ -56,7 +56,9 @@ describe('Nav', () => {
|
|
|
56
56
|
expect(asFragment()).toMatchSnapshot();
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
test('Default Nav List - Trigger item active update', () => {
|
|
59
|
+
test('Default Nav List - Trigger item active update', async () => {
|
|
60
|
+
const user = userEvent.setup();
|
|
61
|
+
|
|
60
62
|
const { asFragment } = renderNav(
|
|
61
63
|
<Nav>
|
|
62
64
|
<NavList>
|
|
@@ -69,7 +71,7 @@ describe('Nav', () => {
|
|
|
69
71
|
</Nav>
|
|
70
72
|
);
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
await user.click(screen.getByText('Link 2'));
|
|
73
75
|
expect(asFragment()).toMatchSnapshot();
|
|
74
76
|
});
|
|
75
77
|
|
|
@@ -90,8 +92,9 @@ describe('Nav', () => {
|
|
|
90
92
|
expect(asFragment()).toMatchSnapshot();
|
|
91
93
|
});
|
|
92
94
|
|
|
93
|
-
test('Expandable Nav verify onExpand', () => {
|
|
95
|
+
test('Expandable Nav verify onExpand', async () => {
|
|
94
96
|
const onExpand = jest.fn();
|
|
97
|
+
const user = userEvent.setup();
|
|
95
98
|
|
|
96
99
|
renderNav(
|
|
97
100
|
<Nav>
|
|
@@ -107,12 +110,13 @@ describe('Nav', () => {
|
|
|
107
110
|
</Nav>
|
|
108
111
|
);
|
|
109
112
|
|
|
110
|
-
|
|
113
|
+
await user.click(screen.getByRole('button'));
|
|
111
114
|
expect(onExpand).toHaveBeenCalled();
|
|
112
115
|
});
|
|
113
116
|
|
|
114
|
-
test('Expandable Nav List - Trigger toggle', () => {
|
|
117
|
+
test('Expandable Nav List - Trigger toggle', async () => {
|
|
115
118
|
window.location.hash = '#link2';
|
|
119
|
+
const user = userEvent.setup();
|
|
116
120
|
|
|
117
121
|
const { asFragment } = renderNav(
|
|
118
122
|
<Nav>
|
|
@@ -128,7 +132,7 @@ describe('Nav', () => {
|
|
|
128
132
|
</Nav>
|
|
129
133
|
);
|
|
130
134
|
|
|
131
|
-
|
|
135
|
+
await user.click(screen.getByText('Section 1'));
|
|
132
136
|
expect(asFragment()).toMatchSnapshot();
|
|
133
137
|
});
|
|
134
138
|
|
|
@@ -5,7 +5,7 @@ import MinusIcon from '@patternfly/react-icons/dist/esm/icons/minus-icon';
|
|
|
5
5
|
import PlusIcon from '@patternfly/react-icons/dist/esm/icons/plus-icon';
|
|
6
6
|
import { InputGroup } from '../InputGroup';
|
|
7
7
|
import { Button, ButtonProps } from '../Button';
|
|
8
|
-
import {
|
|
8
|
+
import { KeyTypes, ValidatedOptions } from '../../helpers';
|
|
9
9
|
import { TextInput } from '../TextInput';
|
|
10
10
|
|
|
11
11
|
export interface NumberInputProps extends React.HTMLProps<HTMLDivElement> {
|
|
@@ -56,11 +56,11 @@ export interface NumberInputProps extends React.HTMLProps<HTMLDivElement> {
|
|
|
56
56
|
type DefaultKeyDownHandlerArgs = Pick<NumberInputProps, 'inputName' | 'onMinus' | 'onPlus'>;
|
|
57
57
|
|
|
58
58
|
const defaultKeyDownHandler = (args: DefaultKeyDownHandlerArgs) => (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
59
|
-
if (
|
|
59
|
+
if (KeyTypes.ArrowUp === event.key && args.onPlus) {
|
|
60
60
|
event.preventDefault();
|
|
61
61
|
args.onPlus(null, args.inputName);
|
|
62
62
|
}
|
|
63
|
-
if (
|
|
63
|
+
if (KeyTypes.ArrowDown === event.key && args.onMinus) {
|
|
64
64
|
event.preventDefault();
|
|
65
65
|
args.onMinus(null, args.inputName);
|
|
66
66
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
3
|
import { NumberInput } from '../NumberInput';
|
|
4
4
|
import userEvent from '@testing-library/user-event';
|
|
5
5
|
|
|
@@ -101,71 +101,96 @@ describe('numberInput', () => {
|
|
|
101
101
|
expect(onChangeMock).not.toHaveBeenCalled();
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
test('calls onChange callback when input changes', () => {
|
|
104
|
+
test('calls onChange callback when input changes', async () => {
|
|
105
105
|
const onChangeMock = jest.fn();
|
|
106
|
+
const user = userEvent.setup();
|
|
107
|
+
|
|
106
108
|
render(<NumberInput onChange={onChangeMock}>55</NumberInput>);
|
|
107
109
|
|
|
108
110
|
const input = screen.getByRole('spinbutton');
|
|
109
|
-
|
|
111
|
+
await user.type(input, '55');
|
|
110
112
|
|
|
111
113
|
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
112
114
|
});
|
|
113
115
|
|
|
114
|
-
test('does not call onBlur callback when input does not lose focus', () => {
|
|
116
|
+
test('does not call onBlur callback when input does not lose focus', async () => {
|
|
115
117
|
const onBlurMock = jest.fn();
|
|
118
|
+
const user = userEvent.setup();
|
|
116
119
|
|
|
117
120
|
render(<NumberInput onBlur={onBlurMock}>5</NumberInput>);
|
|
118
121
|
|
|
119
122
|
const input = screen.getByRole('spinbutton');
|
|
120
|
-
|
|
123
|
+
await user.click(input);
|
|
121
124
|
|
|
122
125
|
expect(onBlurMock).not.toHaveBeenCalled();
|
|
123
126
|
});
|
|
124
127
|
|
|
125
|
-
test('calls onBlur callback when input loses focus', () => {
|
|
128
|
+
test('calls onBlur callback when input loses focus', async () => {
|
|
126
129
|
const onBlurMock = jest.fn();
|
|
130
|
+
const user = userEvent.setup();
|
|
127
131
|
|
|
128
132
|
render(<NumberInput onBlur={onBlurMock}>5</NumberInput>);
|
|
129
133
|
|
|
130
134
|
const input = screen.getByRole('spinbutton');
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
await user.click(input);
|
|
136
|
+
await user.click(document.body);
|
|
133
137
|
|
|
134
138
|
expect(onBlurMock).toHaveBeenCalledTimes(1);
|
|
135
139
|
});
|
|
136
140
|
|
|
137
|
-
test('removes leading zeros from a positive whole number', () => {
|
|
141
|
+
test('removes leading zeros from a positive whole number', async () => {
|
|
142
|
+
const user = userEvent.setup();
|
|
143
|
+
|
|
138
144
|
render(<NumberInput value={10} onChange={() => {}} />);
|
|
139
145
|
|
|
140
146
|
const input = screen.getByRole('spinbutton');
|
|
141
|
-
|
|
147
|
+
|
|
148
|
+
await user.click(input);
|
|
149
|
+
|
|
150
|
+
// fireEvent is used here due to an issue with the current version of userEvent where userEvent.type/.keyboard does
|
|
151
|
+
// not appear to cause the '0' to be properly added to the input's display value
|
|
152
|
+
fireEvent.change(input, { target: { value: '010' } });
|
|
142
153
|
expect(input).toHaveDisplayValue('010');
|
|
143
154
|
|
|
144
|
-
|
|
155
|
+
await user.click(document.body);
|
|
145
156
|
|
|
146
157
|
expect(input).toHaveDisplayValue('10');
|
|
147
158
|
});
|
|
148
159
|
|
|
149
|
-
test('removes leading zeros from a negative whole number', () => {
|
|
160
|
+
test('removes leading zeros from a negative whole number', async () => {
|
|
161
|
+
const user = userEvent.setup();
|
|
162
|
+
|
|
150
163
|
render(<NumberInput value={-18} onChange={() => {}} />);
|
|
151
164
|
|
|
152
165
|
const input = screen.getByRole('spinbutton');
|
|
153
|
-
|
|
166
|
+
|
|
167
|
+
await user.click(input);
|
|
168
|
+
|
|
169
|
+
// fireEvent is used here due to an issue with the current version of userEvent where userEvent.type/.keyboard does
|
|
170
|
+
// not appear to cause the '0' to be properly added to the input's display value
|
|
171
|
+
fireEvent.change(input, { target: { value: '-018' } });
|
|
154
172
|
expect(input).toHaveDisplayValue('-018');
|
|
155
173
|
|
|
156
|
-
|
|
174
|
+
await user.click(document.body);
|
|
157
175
|
|
|
158
176
|
expect(input).toHaveDisplayValue('-18');
|
|
159
177
|
});
|
|
160
178
|
|
|
161
|
-
test('removes leading zeros from a decimal number', () => {
|
|
179
|
+
test('removes leading zeros from a decimal number', async () => {
|
|
180
|
+
const user = userEvent.setup();
|
|
181
|
+
|
|
162
182
|
render(<NumberInput value={47.01} onChange={() => {}} />);
|
|
163
183
|
|
|
164
184
|
const input = screen.getByRole('spinbutton');
|
|
165
|
-
|
|
185
|
+
|
|
186
|
+
await user.click(input);
|
|
187
|
+
|
|
188
|
+
// fireEvent is used here due to an issue with the current version of userEvent where userEvent.type/.keyboard does
|
|
189
|
+
// not appear to cause the '0' to be properly added to the input's display value
|
|
190
|
+
fireEvent.change(input, { target: { value: '047.01' } });
|
|
166
191
|
expect(input).toHaveDisplayValue('047.01');
|
|
167
192
|
|
|
168
|
-
|
|
193
|
+
await user.click(document.body);
|
|
169
194
|
|
|
170
195
|
expect(input).toHaveDisplayValue('47.01');
|
|
171
196
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { css } from '@patternfly/react-styles';
|
|
3
|
-
import {
|
|
3
|
+
import { KeyTypes } from '../../helpers/constants';
|
|
4
4
|
import styles from '@patternfly/react-styles/css/components/OptionsMenu/options-menu';
|
|
5
5
|
import { DropdownContext } from '../Dropdown';
|
|
6
6
|
|
|
@@ -96,10 +96,9 @@ export const OptionsMenuToggleWithText: React.FunctionComponent<OptionsMenuToggl
|
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
const onEscPress = (event: KeyboardEvent) => {
|
|
99
|
-
const keyCode = event.keyCode || event.which;
|
|
100
99
|
if (
|
|
101
100
|
isOpen &&
|
|
102
|
-
(
|
|
101
|
+
(event.key === KeyTypes.Escape || event.key === 'Tab') &&
|
|
103
102
|
parentRef &&
|
|
104
103
|
parentRef.current &&
|
|
105
104
|
parentRef.current.contains(event.target as Node)
|
|
@@ -8,7 +8,7 @@ import AngleDoubleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-d
|
|
|
8
8
|
import { Button, ButtonVariant } from '../Button';
|
|
9
9
|
import { OnSetPage } from './Pagination';
|
|
10
10
|
import { pluralize, PickOptional } from '../../helpers';
|
|
11
|
-
import {
|
|
11
|
+
import { KeyTypes } from '../../helpers/constants';
|
|
12
12
|
|
|
13
13
|
export interface NavigationProps extends React.HTMLProps<HTMLElement> {
|
|
14
14
|
/** Additional classes for the container */
|
|
@@ -113,7 +113,7 @@ export class Navigation extends React.Component<NavigationProps, NavigationState
|
|
|
113
113
|
lastPage: number,
|
|
114
114
|
onPageInput: (event: React.SyntheticEvent<HTMLButtonElement>, page: number) => void
|
|
115
115
|
): void {
|
|
116
|
-
if (event.
|
|
116
|
+
if (event.key === KeyTypes.Enter) {
|
|
117
117
|
const inputPage = Navigation.parseInteger(this.state.userInputPage, lastPage) as number;
|
|
118
118
|
onPageInput(event, Number.isNaN(inputPage) ? (page as number) : inputPage);
|
|
119
119
|
this.handleNewPage(event, Number.isNaN(inputPage) ? (page as number) : inputPage);
|
|
@@ -4,6 +4,7 @@ import { render, screen } from '@testing-library/react';
|
|
|
4
4
|
import userEvent from '@testing-library/user-event';
|
|
5
5
|
|
|
6
6
|
import { Pagination, PaginationVariant } from '../index';
|
|
7
|
+
import { KeyTypes } from '../../../helpers';
|
|
7
8
|
|
|
8
9
|
describe('Pagination', () => {
|
|
9
10
|
describe('component render', () => {
|
|
@@ -117,166 +118,204 @@ describe('Pagination', () => {
|
|
|
117
118
|
describe('onSetPage', () => {
|
|
118
119
|
const onSetPage = jest.fn();
|
|
119
120
|
|
|
120
|
-
test('should call first', () => {
|
|
121
|
+
test('should call first', async () => {
|
|
122
|
+
const user = userEvent.setup();
|
|
123
|
+
|
|
121
124
|
render(<Pagination onSetPage={onSetPage} itemCount={40} page={2} />);
|
|
122
125
|
|
|
123
|
-
|
|
126
|
+
await user.click(screen.getByRole('button', { name: 'Go to first page' }));
|
|
124
127
|
expect(onSetPage).toHaveBeenCalled();
|
|
125
128
|
});
|
|
126
129
|
|
|
127
|
-
test('should call previous', () => {
|
|
130
|
+
test('should call previous', async () => {
|
|
131
|
+
const user = userEvent.setup();
|
|
132
|
+
|
|
128
133
|
render(<Pagination onSetPage={onSetPage} itemCount={40} page={3} />);
|
|
129
134
|
|
|
130
|
-
|
|
135
|
+
await user.click(screen.getByRole('button', { name: 'Go to previous page' }));
|
|
131
136
|
expect(onSetPage).toHaveBeenCalled();
|
|
132
137
|
});
|
|
133
138
|
|
|
134
|
-
test('should call next', () => {
|
|
139
|
+
test('should call next', async () => {
|
|
140
|
+
const user = userEvent.setup();
|
|
141
|
+
|
|
135
142
|
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
136
143
|
|
|
137
|
-
|
|
144
|
+
await user.click(screen.getByRole('button', { name: 'Go to next page' }));
|
|
138
145
|
expect(onSetPage).toHaveBeenCalled();
|
|
139
146
|
});
|
|
140
147
|
|
|
141
|
-
test('should call last', () => {
|
|
148
|
+
test('should call last', async () => {
|
|
149
|
+
const user = userEvent.setup();
|
|
150
|
+
|
|
142
151
|
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
143
152
|
|
|
144
|
-
|
|
153
|
+
await user.click(screen.getByRole('button', { name: 'Go to last page' }));
|
|
145
154
|
expect(onSetPage).toHaveBeenCalled();
|
|
146
155
|
});
|
|
147
156
|
|
|
148
|
-
test('should call input', () => {
|
|
157
|
+
test('should call input', async () => {
|
|
158
|
+
const user = userEvent.setup();
|
|
159
|
+
|
|
149
160
|
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
150
161
|
|
|
151
162
|
const input = screen.getByLabelText('Current page');
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
await user.type(input, '1');
|
|
164
|
+
await user.type(input, `{${KeyTypes.Enter}}`);
|
|
154
165
|
|
|
155
166
|
expect(onSetPage).toHaveBeenCalled();
|
|
156
167
|
});
|
|
157
168
|
|
|
158
|
-
test('should call input wrong value', () => {
|
|
169
|
+
test('should call input wrong value', async () => {
|
|
170
|
+
const user = userEvent.setup();
|
|
171
|
+
|
|
159
172
|
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
160
173
|
|
|
161
174
|
const input = screen.getByLabelText('Current page');
|
|
162
|
-
|
|
163
|
-
|
|
175
|
+
await user.type(input, 'a');
|
|
176
|
+
await user.type(input, `{${KeyTypes.Enter}}`);
|
|
164
177
|
|
|
165
178
|
expect(onSetPage).toHaveBeenCalled();
|
|
166
179
|
});
|
|
167
180
|
|
|
168
|
-
test('should call input huge page number', () => {
|
|
181
|
+
test('should call input huge page number', async () => {
|
|
182
|
+
const user = userEvent.setup();
|
|
183
|
+
|
|
169
184
|
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
170
185
|
|
|
171
186
|
const input = screen.getByLabelText('Current page');
|
|
172
|
-
|
|
173
|
-
|
|
187
|
+
await user.type(input, '10');
|
|
188
|
+
await user.type(input, `{${KeyTypes.Enter}}`);
|
|
174
189
|
|
|
175
190
|
expect(onSetPage).toHaveBeenCalled();
|
|
176
191
|
});
|
|
177
192
|
|
|
178
|
-
test('should call input small page number', () => {
|
|
193
|
+
test('should call input small page number', async () => {
|
|
194
|
+
const user = userEvent.setup();
|
|
195
|
+
|
|
179
196
|
render(<Pagination onSetPage={onSetPage} itemCount={40} />);
|
|
180
197
|
|
|
181
198
|
const input = screen.getByLabelText('Current page');
|
|
182
|
-
|
|
183
|
-
|
|
199
|
+
await user.type(input, '-10');
|
|
200
|
+
await user.type(input, `{${KeyTypes.Enter}}`);
|
|
184
201
|
|
|
185
202
|
expect(onSetPage).toHaveBeenCalled();
|
|
186
203
|
});
|
|
187
204
|
|
|
188
|
-
test('should NOT call', () => {
|
|
205
|
+
test('should NOT call', async () => {
|
|
206
|
+
const user = userEvent.setup();
|
|
207
|
+
|
|
189
208
|
render(<Pagination itemCount={40} />);
|
|
190
209
|
|
|
191
|
-
|
|
210
|
+
await user.click(screen.getByRole('button', { name: 'Go to last page' }));
|
|
192
211
|
expect(onSetPage).not.toHaveBeenCalled();
|
|
193
212
|
});
|
|
194
213
|
});
|
|
195
214
|
|
|
196
215
|
describe('onFirst', () => {
|
|
197
216
|
const onFirst = jest.fn();
|
|
198
|
-
test('should call', () => {
|
|
217
|
+
test('should call', async () => {
|
|
218
|
+
const user = userEvent.setup();
|
|
219
|
+
|
|
199
220
|
render(<Pagination onFirstClick={onFirst} itemCount={40} page={2} />);
|
|
200
221
|
|
|
201
|
-
|
|
222
|
+
await user.click(screen.getByRole('button', { name: 'Go to first page' }));
|
|
202
223
|
expect(onFirst).toHaveBeenCalled();
|
|
203
224
|
});
|
|
204
225
|
|
|
205
|
-
test('should NOT call', () => {
|
|
226
|
+
test('should NOT call', async () => {
|
|
227
|
+
const user = userEvent.setup();
|
|
228
|
+
|
|
206
229
|
render(<Pagination itemCount={40} page={2} />);
|
|
207
230
|
|
|
208
|
-
|
|
231
|
+
await user.click(screen.getByRole('button', { name: 'Go to first page' }));
|
|
209
232
|
expect(onFirst).not.toHaveBeenCalled();
|
|
210
233
|
});
|
|
211
234
|
});
|
|
212
235
|
|
|
213
236
|
describe('onLast', () => {
|
|
214
237
|
const onLast = jest.fn();
|
|
215
|
-
test('should call', () => {
|
|
238
|
+
test('should call', async () => {
|
|
239
|
+
const user = userEvent.setup();
|
|
240
|
+
|
|
216
241
|
render(<Pagination onLastClick={onLast} itemCount={40} />);
|
|
217
242
|
|
|
218
|
-
|
|
243
|
+
await user.click(screen.getByRole('button', { name: 'Go to last page' }));
|
|
219
244
|
expect(onLast).toHaveBeenCalled();
|
|
220
245
|
});
|
|
221
246
|
|
|
222
|
-
test('should NOT call', () => {
|
|
247
|
+
test('should NOT call', async () => {
|
|
248
|
+
const user = userEvent.setup();
|
|
249
|
+
|
|
223
250
|
render(<Pagination itemCount={40} />);
|
|
224
251
|
|
|
225
|
-
|
|
252
|
+
await user.click(screen.getByRole('button', { name: 'Go to last page' }));
|
|
226
253
|
expect(onLast).not.toHaveBeenCalled();
|
|
227
254
|
});
|
|
228
255
|
});
|
|
229
256
|
|
|
230
257
|
describe('onPrevious', () => {
|
|
231
258
|
const onPrevious = jest.fn();
|
|
232
|
-
test('should call', () => {
|
|
259
|
+
test('should call', async () => {
|
|
260
|
+
const user = userEvent.setup();
|
|
261
|
+
|
|
233
262
|
render(<Pagination onPreviousClick={onPrevious} itemCount={40} page={3} />);
|
|
234
263
|
|
|
235
|
-
|
|
264
|
+
await user.click(screen.getByRole('button', { name: 'Go to previous page' }));
|
|
236
265
|
expect(onPrevious).toHaveBeenCalled();
|
|
237
266
|
});
|
|
238
267
|
|
|
239
|
-
test('should NOT call', () => {
|
|
268
|
+
test('should NOT call', async () => {
|
|
269
|
+
const user = userEvent.setup();
|
|
270
|
+
|
|
240
271
|
render(<Pagination itemCount={40} />);
|
|
241
272
|
|
|
242
|
-
|
|
273
|
+
await user.click(screen.getByRole('button', { name: 'Go to previous page' }));
|
|
243
274
|
expect(onPrevious).not.toHaveBeenCalled();
|
|
244
275
|
});
|
|
245
276
|
});
|
|
246
277
|
|
|
247
278
|
describe('onNext', () => {
|
|
248
279
|
const onNext = jest.fn();
|
|
249
|
-
test('should call', () => {
|
|
280
|
+
test('should call', async () => {
|
|
281
|
+
const user = userEvent.setup();
|
|
282
|
+
|
|
250
283
|
render(<Pagination onNextClick={onNext} itemCount={40} />);
|
|
251
284
|
|
|
252
|
-
|
|
285
|
+
await user.click(screen.getByRole('button', { name: 'Go to next page' }));
|
|
253
286
|
expect(onNext).toHaveBeenCalled();
|
|
254
287
|
});
|
|
255
288
|
|
|
256
|
-
test('should NOT call', () => {
|
|
289
|
+
test('should NOT call', async () => {
|
|
290
|
+
const user = userEvent.setup();
|
|
291
|
+
|
|
257
292
|
render(<Pagination itemCount={40} />);
|
|
258
293
|
|
|
259
|
-
|
|
294
|
+
await user.click(screen.getByRole('button', { name: 'Go to previous page' }));
|
|
260
295
|
expect(onNext).not.toHaveBeenCalled();
|
|
261
296
|
});
|
|
262
297
|
});
|
|
263
298
|
|
|
264
299
|
describe('onPerPage', () => {
|
|
265
300
|
const onPerPage = jest.fn();
|
|
266
|
-
test('should call', () => {
|
|
301
|
+
test('should call', async () => {
|
|
302
|
+
const user = userEvent.setup();
|
|
303
|
+
|
|
267
304
|
render(<Pagination onPerPageSelect={onPerPage} itemCount={40} />);
|
|
268
305
|
|
|
269
|
-
|
|
270
|
-
|
|
306
|
+
await user.click(screen.getByRole('button', { name: 'Items per page' }));
|
|
307
|
+
await user.click(screen.getByText('20 per page'));
|
|
271
308
|
|
|
272
309
|
expect(onPerPage).toHaveBeenCalled();
|
|
273
310
|
});
|
|
274
311
|
|
|
275
|
-
test('should NOT call', () => {
|
|
312
|
+
test('should NOT call', async () => {
|
|
313
|
+
const user = userEvent.setup();
|
|
314
|
+
|
|
276
315
|
render(<Pagination itemCount={40} />);
|
|
277
316
|
|
|
278
|
-
|
|
279
|
-
|
|
317
|
+
await user.click(screen.getByRole('button', { name: 'Items per page' }));
|
|
318
|
+
await user.click(screen.getByText('20 per page'));
|
|
280
319
|
|
|
281
320
|
expect(onPerPage).not.toHaveBeenCalled();
|
|
282
321
|
});
|
|
@@ -73,10 +73,12 @@ describe('Radio', () => {
|
|
|
73
73
|
expect(asFragment()).toMatchSnapshot();
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
test('Radio passes value and event to onChange handler', () => {
|
|
76
|
+
test('Radio passes value and event to onChange handler', async () => {
|
|
77
|
+
const user = userEvent.setup();
|
|
78
|
+
|
|
77
79
|
render(<Radio id="check" {...props} aria-label="check" name="check" />);
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
await user.click(screen.getByRole('radio'));
|
|
80
82
|
expect(props.onChange).toHaveBeenCalledWith(true, expect.any(Object));
|
|
81
83
|
});
|
|
82
84
|
|