Skip to content

Commit ce3ac5e

Browse files
committed
Update MUI tests
1 parent d458852 commit ce3ac5e

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

packages/mui-component-mapper/src/files/select.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Autocomplete from '@material-ui/lab/Autocomplete';
1717
* @param {Array<Object>} options all options avaiable
1818
* @returns {String}
1919
*/
20-
const getOptionLabel = (option, options) => {
20+
export const getOptionLabel = (option, options) => {
2121
if (typeof option === 'undefined') {
2222
return '';
2323
}
@@ -44,7 +44,7 @@ const getOptionLabel = (option, options) => {
4444
* @param {Boolean} isMulti multiple select flag
4545
* @returns {Object|Array<Object>}
4646
*/
47-
const createValue = (option, isMulti) => {
47+
export const createValue = (option, isMulti) => {
4848
if (isMulti) {
4949
return Array.isArray(option) ? option.map((item) => (typeof item === 'object' ? item : { value: item })) : option;
5050
}

packages/mui-component-mapper/src/tests/form-fields.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ describe('formFields', () => {
231231
beforeEach(() => {
232232
initialProps = {
233233
...initialProps,
234+
name: 'multiple',
234235
options: [
235236
{ label: 'Cat', value: 'cats' },
236237
{ label: 'Dog', value: 'dogs' },
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import FormRenderer from '@data-driven-forms/react-form-renderer';
3+
import { mount } from 'enzyme';
4+
import { Typography } from '@material-ui/core';
5+
6+
import { componentMapper, FormTemplate } from '..';
7+
8+
describe('<FormTemplate />', () => {
9+
it('<Description /> renders correctly', () => {
10+
const wrapper = mount(
11+
<FormRenderer
12+
onSubmit={jest.fn()}
13+
componentMapper={componentMapper}
14+
FormTemplate={FormTemplate}
15+
schema={{ description: 'Some description', fields: [] }}
16+
/>
17+
);
18+
19+
expect(wrapper.find(Typography).text()).toEqual('Some description');
20+
});
21+
22+
it('<Title /> renders correctly', () => {
23+
const wrapper = mount(
24+
<FormRenderer onSubmit={jest.fn()} componentMapper={componentMapper} FormTemplate={FormTemplate} schema={{ title: 'Some title', fields: [] }} />
25+
);
26+
27+
expect(wrapper.find(Typography).text()).toEqual('Some title');
28+
});
29+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { getOptionLabel, createValue } from '../files/select';
2+
3+
describe('<Select />', () => {
4+
describe('helpers', () => {
5+
describe('#getOptionLabel', () => {
6+
it('undefined', () => {
7+
expect(getOptionLabel(undefined)).toEqual('');
8+
});
9+
10+
it('empty string', () => {
11+
expect(getOptionLabel('')).toEqual('');
12+
});
13+
14+
it('empty array', () => {
15+
expect(getOptionLabel([])).toEqual('');
16+
});
17+
18+
it('object', () => {
19+
expect(getOptionLabel({ label: 'some label' })).toEqual('some label');
20+
});
21+
22+
it('find in options', () => {
23+
const options = [
24+
{ value: '1', label: 'one' },
25+
{ value: 'key', label: 'this label' },
26+
{ value: '2', label: 'two' }
27+
];
28+
29+
expect(getOptionLabel('key', options)).toEqual('this label');
30+
});
31+
});
32+
33+
describe('#createOptions', () => {
34+
it('is multi - single', () => {
35+
const option = { label: 'label', value: '123' };
36+
37+
expect(createValue(option, true)).toEqual(option);
38+
});
39+
40+
it('is multi - array with objects', () => {
41+
const option = [
42+
{ label: 'label', value: '123' },
43+
{ label: 'label 2', value: '456' }
44+
];
45+
46+
expect(createValue(option, true)).toEqual(option);
47+
});
48+
49+
it('is multi - array with values', () => {
50+
const option = ['123', '456'];
51+
52+
expect(createValue(option, true)).toEqual([{ value: '123' }, { value: '456' }]);
53+
});
54+
55+
it('is multi - array with values and object', () => {
56+
const option = ['123', '456', { value: '789', label: 'some label' }];
57+
58+
expect(createValue(option, true)).toEqual([{ value: '123' }, { value: '456' }, { value: '789', label: 'some label' }]);
59+
});
60+
61+
it('createValue', () => {
62+
const option = { label: 'label', value: '123' };
63+
64+
expect(createValue(option, false)).toEqual(option);
65+
});
66+
});
67+
});
68+
});

0 commit comments

Comments
 (0)