Skip to content

Commit 9c0780d

Browse files
committed
add more tests
1 parent cbd5cd6 commit 9c0780d

File tree

3 files changed

+97
-6
lines changed

3 files changed

+97
-6
lines changed

packages/material-renderers/test/renderers/MaterialArrayControl.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,28 @@ describe('Material array control', () => {
303303
expect(
304304
wrapper.text().includes('This is an array description')
305305
).toBeTruthy();
306+
expect(wrapper.find('thead .MuiFormHelperText-root').exists()).toBeTruthy();
307+
});
308+
309+
it('should not render description container if there is none', () => {
310+
const descriptionSchema = {
311+
...fixture.schema,
312+
};
313+
// make sure there is no description
314+
delete descriptionSchema.description;
315+
316+
const core = initCore(descriptionSchema, fixture.uischema, fixture.data);
317+
wrapper = mount(
318+
<JsonFormsStateProvider
319+
initState={{ renderers: materialRenderers, core }}
320+
>
321+
<MaterialArrayControlRenderer
322+
schema={descriptionSchema}
323+
uischema={fixture.uischema}
324+
/>
325+
</JsonFormsStateProvider>
326+
);
327+
expect(wrapper.find('thead .MuiFormHelperText-root').exists()).toBeFalsy();
306328
});
307329

308330
it('should delete an item', () => {

packages/material-renderers/test/renderers/MaterialArrayLayout.test.tsx

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
THE SOFTWARE.
2424
*/
2525
import './MatchMediaMock';
26-
import { ControlElement } from '@jsonforms/core';
26+
import { ControlElement, JsonSchema7 } from '@jsonforms/core';
2727
import * as React from 'react';
2828

2929
import { materialRenderers } from '../../src';
@@ -50,7 +50,7 @@ const data = [
5050
message2: 'Yolo 2',
5151
},
5252
];
53-
const schema = {
53+
const schema: JsonSchema7 = {
5454
type: 'array',
5555
items: {
5656
type: 'object',
@@ -66,7 +66,7 @@ const schema = {
6666
},
6767
};
6868

69-
const nestedSchema = {
69+
const nestedSchema: JsonSchema7 = {
7070
type: 'array',
7171
items: {
7272
...schema,
@@ -568,4 +568,46 @@ describe('Material array layout', () => {
568568
expect(getChildLabel(wrapper, 0)).toBe('El Barto was here 2');
569569
expect(getChildLabel(wrapper, 1)).toBe('Yolo 2');
570570
});
571+
572+
it('should render description', () => {
573+
const descriptionSchema = {
574+
...nestedSchema,
575+
description: 'This is an array description',
576+
};
577+
578+
wrapper = mount(
579+
<JsonForms
580+
data={data}
581+
schema={descriptionSchema}
582+
uischema={uischema}
583+
renderers={materialRenderers}
584+
/>
585+
);
586+
expect(
587+
wrapper.text().includes('This is an array description')
588+
).toBeTruthy();
589+
expect(
590+
wrapper.find('.MuiToolbar-root .MuiFormHelperText-root').exists()
591+
).toBeTruthy();
592+
});
593+
594+
it('should not render description container if there is none', () => {
595+
const descriptionSchema = {
596+
...nestedSchema,
597+
};
598+
// make sure there is no description
599+
delete descriptionSchema.description;
600+
601+
wrapper = mount(
602+
<JsonForms
603+
data={data}
604+
schema={descriptionSchema}
605+
uischema={uischema}
606+
renderers={materialRenderers}
607+
/>
608+
);
609+
expect(
610+
wrapper.find('.MuiToolbar-root .MuiFormHelperText-root').exists()
611+
).toBeFalsy();
612+
});
571613
});

packages/material-renderers/test/renderers/MaterialListWithDetailRenderer.test.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
THE SOFTWARE.
2424
*/
2525
import './MatchMediaMock';
26-
import { ControlElement } from '@jsonforms/core';
26+
import { ControlElement, JsonSchema7 } from '@jsonforms/core';
2727
import * as React from 'react';
2828

2929
import { materialRenderers } from '../../src';
@@ -47,7 +47,7 @@ const data = [
4747
message: 'Yolo',
4848
},
4949
];
50-
const schema = {
50+
const schema: JsonSchema7 = {
5151
type: 'array',
5252
items: {
5353
type: 'object',
@@ -69,7 +69,7 @@ const uischema: ControlElement = {
6969
scope: '#',
7070
};
7171

72-
const nestedSchema = {
72+
const nestedSchema: JsonSchema7 = {
7373
type: 'array',
7474
items: {
7575
...schema,
@@ -279,6 +279,33 @@ describe('Material list with detail renderer', () => {
279279
expect(
280280
wrapper.text().includes('This is an array description')
281281
).toBeTruthy();
282+
expect(
283+
wrapper.find('.MuiToolbar-root .MuiFormHelperText-root').exists()
284+
).toBeTruthy();
285+
});
286+
287+
it('should not render description container if there is none', () => {
288+
const descriptionSchema = {
289+
...schema,
290+
};
291+
// make sure there is no description
292+
delete descriptionSchema.description;
293+
294+
const core = initCore(schema, uischema, data);
295+
wrapper = mount(
296+
<JsonFormsStateProvider
297+
initState={{ renderers: materialRenderers, core }}
298+
>
299+
<MaterialListWithDetailRenderer
300+
schema={descriptionSchema}
301+
uischema={uischema}
302+
/>
303+
</JsonFormsStateProvider>
304+
);
305+
306+
expect(
307+
wrapper.find('.MuiToolbar-root .MuiFormHelperText-root').exists()
308+
).toBeFalsy();
282309
});
283310

284311
it('add data to the array', () => {

0 commit comments

Comments
 (0)