Skip to content

Commit 07aed04

Browse files
chore: Update Objects tests to tests all the label variations (rjsf-team#3556)
Updated the `objectTests` to add testing of titles and descriptions from both schema and uiSchema, along with disabling labels globally - Updated the snapshots
1 parent f3d9b78 commit 07aed04

File tree

8 files changed

+17380
-4
lines changed

8 files changed

+17380
-4
lines changed

packages/antd/test/__snapshots__/Object.test.tsx.snap

Lines changed: 2534 additions & 0 deletions
Large diffs are not rendered by default.

packages/bootstrap-4/test/__snapshots__/Object.test.tsx.snap

Lines changed: 1349 additions & 0 deletions
Large diffs are not rendered by default.

packages/chakra-ui/test/__snapshots__/Object.test.tsx.snap

Lines changed: 2002 additions & 0 deletions
Large diffs are not rendered by default.

packages/core/testSnap/objectTests.tsx

Lines changed: 119 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
import { ComponentType } from 'react';
22
import renderer from 'react-test-renderer';
3-
import { RJSFSchema } from '@rjsf/utils';
3+
import { RJSFSchema, UiSchema } from '@rjsf/utils';
44
import validator from '@rjsf/validator-ajv8';
55

66
import { FormProps } from '../src';
77

8-
// export type ObjectRenderCustomOptions = {
9-
// checkboxes?: TestRendererOptions;
10-
// }
8+
const titleAndDesc = {
9+
title: 'Test field',
10+
description: 'a test description'
11+
};
12+
13+
const uiTitleAndDesc: UiSchema = {
14+
'ui:options': {
15+
title: 'My Field',
16+
description: 'a fancier description'
17+
},
18+
a: {
19+
'ui:options': {
20+
title: 'My Item A',
21+
description: 'a fancier item A description'
22+
}
23+
},
24+
b: {
25+
'ui:options': {
26+
title: 'My Item B',
27+
description: 'a fancier item B description'
28+
}
29+
}
30+
31+
};
32+
33+
const labelsOff: UiSchema = {
34+
'ui:globalOptions': { label: false }
35+
};
1136

1237
export default function arrayTests(Form: ComponentType<FormProps>) {
1338
describe('object fields', () => {
@@ -30,5 +55,95 @@ export default function arrayTests(Form: ComponentType<FormProps>) {
3055
const tree = renderer.create(<Form schema={schema} validator={validator} formData={{ foo: 'foo' }} />).toJSON();
3156
expect(tree).toMatchSnapshot();
3257
});
58+
describe('with title and description', () => {
59+
test('object', () => {
60+
const schema: RJSFSchema = {
61+
type: 'object',
62+
...titleAndDesc,
63+
properties: {
64+
a: { type: 'string', title: 'A', description: 'A description' },
65+
b: { type: 'number', title: 'B', description: 'B description' },
66+
},
67+
};
68+
const tree = renderer.create(<Form schema={schema} validator={validator} />).toJSON();
69+
expect(tree).toMatchSnapshot();
70+
});
71+
test('additionalProperties', () => {
72+
const schema: RJSFSchema = {
73+
type: 'object',
74+
...titleAndDesc,
75+
additionalProperties: true,
76+
};
77+
const tree = renderer.create(<Form schema={schema} validator={validator} formData={{ foo: 'foo' }} />).toJSON();
78+
expect(tree).toMatchSnapshot();
79+
});
80+
});
81+
describe('with title and description from uiSchema', () => {
82+
test('object', () => {
83+
const schema: RJSFSchema = {
84+
type: 'object',
85+
properties: {
86+
a: { type: 'string', title: 'A' },
87+
b: { type: 'number', title: 'B' },
88+
},
89+
};
90+
const tree = renderer.create(<Form schema={schema} uiSchema={uiTitleAndDesc} validator={validator} />).toJSON();
91+
expect(tree).toMatchSnapshot();
92+
});
93+
test('additionalProperties', () => {
94+
const schema: RJSFSchema = {
95+
type: 'object',
96+
additionalProperties: true,
97+
};
98+
const tree = renderer.create(<Form schema={schema} uiSchema={uiTitleAndDesc} validator={validator} formData={{ foo: 'foo' }} />).toJSON();
99+
expect(tree).toMatchSnapshot();
100+
});
101+
});
102+
describe('with title and description from both', () => {
103+
test('object', () => {
104+
const schema: RJSFSchema = {
105+
type: 'object',
106+
...titleAndDesc,
107+
properties: {
108+
a: { type: 'string', title: 'A', description: 'A description' },
109+
b: { type: 'number', title: 'B', description: 'B description' },
110+
},
111+
};
112+
const tree = renderer.create(<Form schema={schema} uiSchema={uiTitleAndDesc} validator={validator} />).toJSON();
113+
expect(tree).toMatchSnapshot();
114+
});
115+
test('additionalProperties', () => {
116+
const schema: RJSFSchema = {
117+
type: 'object',
118+
...titleAndDesc,
119+
additionalProperties: true,
120+
};
121+
const tree = renderer.create(<Form schema={schema} uiSchema={uiTitleAndDesc} validator={validator} formData={{ foo: 'foo' }} />).toJSON();
122+
expect(tree).toMatchSnapshot();
123+
});
124+
});
125+
describe('with title and description with global label off', () => {
126+
test('object', () => {
127+
const schema: RJSFSchema = {
128+
type: 'object',
129+
...titleAndDesc,
130+
properties: {
131+
a: { type: 'string', title: 'A', description: 'A description' },
132+
b: { type: 'number', title: 'B', description: 'B description' },
133+
},
134+
};
135+
const tree = renderer.create(<Form schema={schema} uiSchema={labelsOff} validator={validator} />).toJSON();
136+
expect(tree).toMatchSnapshot();
137+
});
138+
test('additionalProperties', () => {
139+
const schema: RJSFSchema = {
140+
type: 'object',
141+
...titleAndDesc,
142+
additionalProperties: true,
143+
};
144+
const tree = renderer.create(<Form schema={schema} uiSchema={labelsOff} validator={validator} formData={{ foo: 'foo' }} />).toJSON();
145+
expect(tree).toMatchSnapshot();
146+
});
147+
});
33148
});
34149
}

0 commit comments

Comments
 (0)