Skip to content

Commit ae6cb0a

Browse files
committed
unit: more tests for FieldSetStepper
1 parent 143822d commit ae6cb0a

File tree

9 files changed

+119
-23
lines changed

9 files changed

+119
-23
lines changed

src/FieldSet/FieldSetArray.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { FieldSetArrayProps } from '../types/FieldSetArray.type';
1717
import Utils from '../helpers/utils';
1818

1919
// Variant
20-
import RENDER_ARRAY_WRAPPERS from './variants/fieldset/array/field-array.wrappers';
20+
import RENDER_ARRAY_WRAPPERS from './variants/fieldset-array/field-array.wrappers';
2121

2222
export const RawFieldSetArray = (props: FieldSetArrayProps) => {
2323
const {

src/FieldSet/__tests__/FieldSet.spec.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,48 @@ describe('FieldSet', () => {
9494
expect(ffComp.prop('data')).toBe(data.name);
9595
expect(ffComp.prop('objectData')).toStrictEqual(data);
9696
});
97+
it('mounts with single field with additional properties (control)', () => {
98+
const schema = {
99+
type: 'object',
100+
additionalProperties: {
101+
name: {
102+
'type': 'string',
103+
'title': 'Name',
104+
},
105+
},
106+
};
107+
108+
const data = { name: 'Bob' };
109+
110+
// act
111+
const wrapper = mount(
112+
<RawFieldSetObject
113+
classes={{ row }}
114+
schema={schema}
115+
data={data}
116+
path={''}
117+
uiSchema={{}}
118+
xhrSchema={{}}
119+
onKeyDown={jest.fn}
120+
onChange={jest.fn}
121+
onXHRSchemaEvent={jest.fn}
122+
id={'1'}
123+
idxKey={'1'}
124+
validation={{}}
125+
isTabContent={false}
126+
tabKey={''}
127+
/>,
128+
);
129+
130+
// check
131+
expect(wrapper).toHaveLength(1);
132+
// expect(wrapper.prop('className')).toMatch(/rowClassName/);
133+
const ffComp = wrapper.find(FormField);
134+
expect(ffComp).toHaveLength(2);
135+
expect(ffComp.at(1).prop('path')).toBe('name');
136+
expect(ffComp.at(1).prop('data')).toBe(data.name);
137+
expect(ffComp.at(1).prop('objectData')).toStrictEqual(data);
138+
});
97139
it('respects orientation hint', () => {
98140
const schema = {
99141
type: 'object',
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Library
2+
import React from 'react';
3+
import { mount } from 'enzyme';
4+
5+
// Internal
6+
import FieldSetStepper from '../FieldSetStepper';
7+
8+
// Initial Contexts
9+
import { StepperContext } from '../../helpers/context';
10+
11+
const { root, row } = {
12+
root: 'rootClassName',
13+
row: 'rowClassName',
14+
};
15+
16+
describe('FieldSetStepper', () => {
17+
it('mounts with single field (control)', () => {
18+
const schema = {
19+
type: 'object',
20+
properties: {
21+
name: {
22+
'type': 'string',
23+
'title': 'Name',
24+
},
25+
},
26+
};
27+
28+
const uiSchema = {
29+
'ui:page': {
30+
'ui:layout': 'steps',
31+
'props': {
32+
'includeSkipButton': false,
33+
'ui:schemaErrors': true
34+
}
35+
}
36+
};
37+
38+
const data = { name: 'Bob' };
39+
40+
// act
41+
const wrapper = mount(
42+
<StepperContext.Provider value={[1, false] as any}>
43+
<FieldSetStepper
44+
classes={{ row }}
45+
schema={schema}
46+
data={data}
47+
path={''}
48+
uiSchema={uiSchema}
49+
xhrSchema={{}}
50+
onKeyDown={jest.fn}
51+
onChange={jest.fn}
52+
onXHRSchemaEvent={jest.fn}
53+
id={'1'}
54+
idxKey={'1'}
55+
validation={{}}
56+
isTabContent={false}
57+
tabKey={''}
58+
/>
59+
</StepperContext.Provider>,
60+
);
61+
62+
// check
63+
expect(wrapper).toHaveLength(1);
64+
const ffComp = wrapper.find('WithStyles(ForwardRef(Stepper))');
65+
expect(ffComp).toHaveLength(1);
66+
expect(ffComp.prop('activeStep')).toBe(1);
67+
});
68+
});

src/FieldSet/variants/fieldset/array/field-array.variants.tsx renamed to src/FieldSet/variants/fieldset-array/field-array.variants.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import IconButton from '@material-ui/core/IconButton';
77
import AddCircle from '@material-ui/icons/AddCircle';
88

99
// Helpers
10-
import getDefaultValue from '../../../../helpers/get-default-value';
10+
import getDefaultValue from '../../../helpers/get-default-value';
1111

1212
// config
13-
import FIELDSET_CONFIG, { ArrayVariants, ArrayWrapperVariants } from '../../../../config/fieldset.config';
13+
import FIELDSET_CONFIG, { ArrayVariants, ArrayWrapperVariants } from '../../../config/fieldset.config';
1414

1515
// Component
16-
import FormField from '../../../../FormField';
17-
import ReorderableFormField from '../../../ReorderableFormField';
16+
import FormField from '../../../FormField';
17+
import ReorderableFormField from '../../ReorderableFormField';
1818

1919
const { ARRAY_VARIANTS } = FIELDSET_CONFIG;
2020

src/FieldSet/variants/fieldset/array/field-array.wrappers.tsx renamed to src/FieldSet/variants/fieldset-array/field-array.wrappers.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import React from 'react';
44

55
// Helpers
6-
import getDefinitionSchemaFromRef from '../../../../helpers/get-definition-schema';
6+
import getDefinitionSchemaFromRef from '../../../helpers/get-definition-schema';
77

88
// Utils
9-
import Utils from '../../../../helpers/utils';
9+
import Utils from '../../../helpers/utils';
1010

1111
// Variants
1212
import FIELDSET_ARRAY_VARIANTS, {

src/FieldSet/variants/fieldset/object.variants.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/FieldSet/variants/fieldset/stepper.variants.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/FieldSet/variants/fieldset/tabs.variants.tsx

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/__tests__/FormField.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ describe('FormField', () => {
138138
const path = '';
139139
const schema = {
140140
'type': 'object',
141+
'description': 'Something Extra',
141142
'properties': {
142143
firstName: {
143144
type: 'string',
144-
title: 'First Name',
145+
title: 'First Name'
145146
},
146147
surname: {
147148
type: 'string',

0 commit comments

Comments
 (0)