Skip to content

Commit a868a80

Browse files
committed
unit: more tests for components
1 parent bf82c84 commit a868a80

File tree

6 files changed

+92
-92
lines changed

6 files changed

+92
-92
lines changed

src/fields/components/Picker/src/__tests__/Picker.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Library
2-
import moment from 'moment';
32
import React from 'react';
43
import { mount } from 'enzyme';
54
import { MuiPickersUtilsProvider } from '@material-ui/pickers';

src/fields/components/Picker/src/index.tsx

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,21 @@
11
// Library
22
import React from 'react';
3-
import {
4-
KeyboardDatePicker,
5-
KeyboardDateTimePicker,
6-
KeyboardTimePicker,
7-
DatePicker,
8-
TimePicker,
9-
DateTimePicker,
10-
} from '@material-ui/pickers';
11-
import pickerProps from './picker.props';
3+
import pickerProps, { renderPickerComp } from './picker.props';
124

13-
const renderPickerComp = (type) => {
14-
switch (type) {
15-
case 'material-date':
16-
return {
17-
PickerComp: KeyboardDatePicker,
18-
maskInput: [/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
19-
format: 'DD-MM-YYYY',
20-
placeholder: '__-__-____',
21-
};
22-
case 'material-date-keyboard-disable':
23-
return {
24-
PickerComp: DatePicker,
25-
maskInput: [/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
26-
format: 'DD-MM-YYYY',
27-
placeholder: '__-__-____',
28-
};
29-
case 'material-time-keyboard-disable':
30-
return {
31-
PickerComp: TimePicker,
32-
maskInput: [/\d/, /\d/, ':', /\d/, /\d/, ' ', /a|p/i, 'M'],
33-
format: 'hh:mm A',
34-
placeholder: '__:__ __',
35-
};
36-
case 'material-time':
37-
return {
38-
PickerComp: KeyboardTimePicker,
39-
maskInput: [/\d/, /\d/, ':', /\d/, /\d/, ' ', /a|p/i, 'M'],
40-
format: 'hh:mm A',
41-
placeholder: '__:__ __',
42-
};
43-
case 'material-datetime':
44-
return {
45-
PickerComp: KeyboardDateTimePicker,
46-
maskInput: [
47-
/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/, ' ', /\d/, /\d/, ':', /\d/, /\d/, ' ', /a|p/i,
48-
'M',
49-
],
50-
format: 'DD-MM-YYYY hh:mm A',
51-
placeholder: '__-__-___ __:__ __',
52-
};
53-
case 'material-datetime-keyboard-disable':
54-
return {
55-
PickerComp: DateTimePicker,
56-
maskInput: [
57-
/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/, ' ', /\d/, /\d/, ':', /\d/, /\d/, ' ', /a|p/i,
58-
'M',
59-
],
60-
format: 'DD-MM-YYYY hh:mm A',
61-
placeholder: '__-__-___ __:__ __',
62-
};
63-
default:
64-
return {
65-
PickerComp: KeyboardDatePicker,
66-
maskInput: [/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
67-
format: 'DD-MM-YYYY',
68-
placeholder: '__-__-____',
69-
};
70-
}
71-
};
72-
73-
export default ({ path, label, title, value, options = {}, htmlid, type, uiSchema = {}, onChange, ...rest }) => {
5+
export default ({
6+
path,
7+
label,
8+
title,
9+
value,
10+
options = {},
11+
htmlid,
12+
type,
13+
uiSchema = {},
14+
onChange,
15+
...rest
16+
}) => {
7417
const pickerType = uiSchema['ui:props']?.variant || uiSchema['ui:widget'] || type;
75-
const { PickerComp, maskInput, placeholder, format } = renderPickerComp(pickerType);
18+
const { PickerComp, placeholder, format } = renderPickerComp(pickerType);
7619
return (
7720
<div
7821
id={htmlid}

src/fields/components/Picker/src/picker.props.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1+
// Library
2+
import {
3+
KeyboardDatePicker,
4+
KeyboardDateTimePicker,
5+
KeyboardTimePicker,
6+
DatePicker,
7+
TimePicker,
8+
DateTimePicker,
9+
} from '@material-ui/pickers';
10+
11+
export const renderPickerComp = (type) => {
12+
switch (type) {
13+
case 'material-date':
14+
return {
15+
PickerComp: KeyboardDatePicker,
16+
maskInput: [/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
17+
format: 'DD-MM-YYYY',
18+
placeholder: '__-__-____',
19+
};
20+
case 'material-date-keyboard-disable':
21+
return {
22+
PickerComp: DatePicker,
23+
maskInput: [/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
24+
format: 'DD-MM-YYYY',
25+
placeholder: '__-__-____',
26+
};
27+
case 'material-time-keyboard-disable':
28+
return {
29+
PickerComp: TimePicker,
30+
maskInput: [/\d/, /\d/, ':', /\d/, /\d/, ' ', /a|p/i, 'M'],
31+
format: 'hh:mm A',
32+
placeholder: '__:__ __',
33+
};
34+
case 'material-time':
35+
return {
36+
PickerComp: KeyboardTimePicker,
37+
maskInput: [/\d/, /\d/, ':', /\d/, /\d/, ' ', /a|p/i, 'M'],
38+
format: 'hh:mm A',
39+
placeholder: '__:__ __',
40+
};
41+
case 'material-datetime':
42+
return {
43+
PickerComp: KeyboardDateTimePicker,
44+
maskInput: [
45+
/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/, ' ', /\d/, /\d/, ':', /\d/, /\d/, ' ', /a|p/i,
46+
'M',
47+
],
48+
format: 'DD-MM-YYYY hh:mm A',
49+
placeholder: '__-__-___ __:__ __',
50+
};
51+
case 'material-datetime-keyboard-disable':
52+
return {
53+
PickerComp: DateTimePicker,
54+
maskInput: [
55+
/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/, ' ', /\d/, /\d/, ':', /\d/, /\d/, ' ', /a|p/i,
56+
'M',
57+
],
58+
format: 'DD-MM-YYYY hh:mm A',
59+
placeholder: '__-__-___ __:__ __',
60+
};
61+
default:
62+
return {
63+
PickerComp: KeyboardDatePicker,
64+
maskInput: [/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
65+
format: 'DD-MM-YYYY',
66+
placeholder: '__-__-____',
67+
};
68+
}
69+
};
70+
171
const onChangeHandler = (onChange) => (val) => {
272
const value = val && val.format && val.format();
373
onChange(

src/fields/components/Slider/src/__tests__/Slider.spec.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ const value = 20;
1313

1414
describe('Slider', () => {
1515
it('mounts with standard attributes (control)', () => {
16-
const path = 'done';
1716
const label = 'Done';
1817
schema.description = label;
1918
const wrapper = mount(
2019
<SliderComp
2120
label={label}
22-
path={path}
2321
value={value}
24-
schema={schema}
2522
onChange={jest.fn}
2623
/>,
2724
);
@@ -40,7 +37,6 @@ describe('Slider', () => {
4037
}
4138
const wrapper = mount(
4239
<SliderComp
43-
schema={schema}
4440
value={value}
4541
onChange={jest.fn}
4642
options={
@@ -57,10 +53,8 @@ describe('Slider', () => {
5753
const onChange = jest.fn();
5854
const wrapper = mount(
5955
<SliderComp
60-
path={'a'}
6156
value={value}
6257
onChange={onChange}
63-
schema={schema}
6458
/>,
6559
);
6660
const cbComp = wrapper.find('ForwardRef(Slider)');

src/fields/components/Slider/src/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ function valuetext(value) {
2020

2121
export default ({
2222
label = '',
23-
path = '',
2423
value,
25-
schema,
2624
onChange,
2725
disabled = false,
2826
options = {},

src/fields/configure/component/__tests__/get-component.props.spec.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,14 @@ describe('getComponentProps', () => {
156156
});
157157
});
158158

159-
// Should be moved to components
160-
// describe('with ui:widget=textarea', () => {
161-
// it('sets rows and multiline', () => {
162-
// const schema = { 'title': 'First name', 'type': 'string' };
163-
// const uiSchema = { 'ui:widget': 'textarea' };
164-
// const componentProps = getComponentProps({ schema, uiSchema });
165-
// expect(componentProps).toHaveProperty('rows');
166-
// expect(componentProps).toHaveProperty('multiline');
167-
// expect(componentProps.rows).toBe(5);
168-
// expect(componentProps.multiline).toBe(true);
169-
// });
170-
// });
159+
describe('with ui:widget=textarea', () => {
160+
it('sets widget to textarea', () => {
161+
const schema = { 'title': 'First name', 'type': 'string' };
162+
const uiSchema = { 'ui:widget': 'textarea' };
163+
const componentProps = getComponentProps({ schema, uiSchema });
164+
expect(componentProps.widget).toBe('textarea');
165+
});
166+
});
171167

172168
it('passes mui:* properties', () => {
173169
const schema = { 'title': 'First name' };

0 commit comments

Comments
 (0)