|
6 | 6 | getDefaultBasedOnSchemaType, |
7 | 7 | getInnerSchemaForArrayItem, |
8 | 8 | getObjectDefaults, |
| 9 | + getValidFormData, |
9 | 10 | } from '../../src/schema/getDefaultFormState'; |
10 | 11 | import { RECURSIVE_REF, RECURSIVE_REF_ALLOF } from '../testUtils/testData'; |
11 | 12 | import { IExpectType, TestValidatorType } from './types'; |
@@ -2058,6 +2059,29 @@ export default function getDefaultFormStateTest(testValidator: TestValidatorType |
2058 | 2059 | }, |
2059 | 2060 | ]); |
2060 | 2061 | }); |
| 2062 | + describe('getValidFormData', () => { |
| 2063 | + let schema: RJSFSchema; |
| 2064 | + it('Test schema with non valid formData for enum property', () => { |
| 2065 | + schema = { |
| 2066 | + type: 'string', |
| 2067 | + enum: ['a', 'b', 'c'], |
| 2068 | + }; |
| 2069 | + |
| 2070 | + expect(getValidFormData(testValidator, schema, schema, 'd')).toBeUndefined(); |
| 2071 | + }); |
| 2072 | + it('Test schema with valid formData for enum property', () => { |
| 2073 | + expect(getValidFormData(testValidator, schema, schema, 'b')).toEqual('b'); |
| 2074 | + }); |
| 2075 | + it('Test schema with const property', () => { |
| 2076 | + schema = { |
| 2077 | + type: 'string', |
| 2078 | + enum: ['a', 'b', 'c'], |
| 2079 | + const: 'a', |
| 2080 | + }; |
| 2081 | + |
| 2082 | + expect(getValidFormData(testValidator, schema, schema, 'a')).toEqual('a'); |
| 2083 | + }); |
| 2084 | + }); |
2061 | 2085 | describe('default form state behavior: ignore min items unless required', () => { |
2062 | 2086 | it('should return empty data for an optional array property with minItems', () => { |
2063 | 2087 | const schema: RJSFSchema = { |
|
0 commit comments