Skip to content

Commit 52da8b5

Browse files
committed
Add tests for submit by enter
1 parent 65319fd commit 52da8b5

File tree

10 files changed

+1080
-846
lines changed

10 files changed

+1080
-846
lines changed

packages/pf3-component-mapper/src/form-fields/switch-field.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Switch extends React.Component {
4747
}
4848

4949
render() {
50-
const { onText, offText, disabled, isReadOnly, bsSize, ...props } = this.props;
50+
const { onText, offText, disabled, isReadOnly, bsSize, formOptions, ...props } = this.props;
5151
return (
5252
<div>
5353
<label
@@ -62,7 +62,7 @@ class Switch extends React.Component {
6262
props.onChange({ target: { checked: !props.checked }});
6363
} else if (e.keyCode === ENTER_CODE) {
6464
e.preventDefault();
65-
props.formOptions.handleSubmit();
65+
formOptions.handleSubmit();
6666
}
6767
} }
6868
>
@@ -102,6 +102,9 @@ Switch.propTypes = {
102102
checked: PropTypes.oneOfType([ PropTypes.bool, PropTypes.string ]),
103103
onChange: PropTypes.func.isRequired,
104104
bsSize: PropTypes.oneOf([ 'mn', 'mini' ]),
105+
formOptions: PropTypes.shape({
106+
handleSubmit: PropTypes.func.isRequired,
107+
}).isRequired,
105108
};
106109

107110
Switch.defaultProps = {

packages/pf3-component-mapper/src/tests/__snapshots__/form-fields.test.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,13 @@ exports[`FormFields <SwitchField /> should render Switch correctly 1`] = `
411411
<div>
412412
<label
413413
className="pf3-switch"
414+
onKeyDown={[Function]}
414415
style={
415416
Object {
416417
"width": 80,
417418
}
418419
}
420+
tabIndex={0}
419421
>
420422
<input
421423
checked=""
@@ -551,11 +553,13 @@ exports[`FormFields <SwitchField /> should render Switch with label correctly 1`
551553
<div>
552554
<label
553555
className="pf3-switch"
556+
onKeyDown={[Function]}
554557
style={
555558
Object {
556559
"width": 80,
557560
}
558561
}
562+
tabIndex={0}
559563
>
560564
<input
561565
checked=""
@@ -681,11 +685,13 @@ exports[`FormFields <SwitchField /> should render Switch with onText (custom pro
681685
<div>
682686
<label
683687
className="pf3-switch"
688+
onKeyDown={[Function]}
684689
style={
685690
Object {
686691
"width": 80,
687692
}
688693
}
694+
tabIndex={0}
689695
>
690696
<input
691697
checked=""
@@ -811,11 +817,13 @@ exports[`FormFields <SwitchField /> should render Switch with placeholder correc
811817
<div>
812818
<label
813819
className="pf3-switch"
820+
onKeyDown={[Function]}
814821
style={
815822
Object {
816823
"width": 80,
817824
}
818825
}
826+
tabIndex={0}
819827
>
820828
<input
821829
checked=""
@@ -942,11 +950,13 @@ exports[`FormFields <SwitchField /> should render disabled Switch correctly 1`]
942950
<div>
943951
<label
944952
className="pf3-switch disabled"
953+
onKeyDown={[Function]}
945954
style={
946955
Object {
947956
"width": 80,
948957
}
949958
}
959+
tabIndex={-1}
950960
>
951961
<input
952962
checked=""
@@ -1074,11 +1084,13 @@ exports[`FormFields <SwitchField /> should render mini Switch correctly 1`] = `
10741084
<div>
10751085
<label
10761086
className="pf3-switch mini"
1087+
onKeyDown={[Function]}
10771088
style={
10781089
Object {
10791090
"width": 80,
10801091
}
10811092
}
1093+
tabIndex={0}
10821094
>
10831095
<input
10841096
checked=""
@@ -1205,11 +1217,13 @@ exports[`FormFields <SwitchField /> should render readOnly Switch correctly 1`]
12051217
<div>
12061218
<label
12071219
className="pf3-switch disabled"
1220+
onKeyDown={[Function]}
12081221
style={
12091222
Object {
12101223
"width": 80,
12111224
}
12121225
}
1226+
tabIndex={-1}
12131227
>
12141228
<input
12151229
checked=""
@@ -1337,11 +1351,13 @@ exports[`FormFields <SwitchField /> should render sm Switch correctly 1`] = `
13371351
<div>
13381352
<label
13391353
className="pf3-switch mini"
1354+
onKeyDown={[Function]}
13401355
style={
13411356
Object {
13421357
"width": 80,
13431358
}
13441359
}
1360+
tabIndex={0}
13451361
>
13461362
<input
13471363
checked=""

0 commit comments

Comments
 (0)