From 14b0c93b431dd07ab3509dba0cc01c6ac13f47cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=8A=9B?= Date: Tue, 10 Dec 2019 17:31:59 +0800 Subject: [PATCH 1/3] Update schema.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix schema中array设置minItems 却报错`长度或条目数不能大于` --- packages/react-schema-renderer/src/shared/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-schema-renderer/src/shared/schema.ts b/packages/react-schema-renderer/src/shared/schema.ts index 67d862d98fa..18403cd3faf 100644 --- a/packages/react-schema-renderer/src/shared/schema.ts +++ b/packages/react-schema-renderer/src/shared/schema.ts @@ -166,7 +166,7 @@ export class Schema implements ISchema { rules.push({ max: this.maxItems }) } if (isValid(this.minItems)) { - rules.push({ max: this.minItems }) + rules.push({ min: this.minItems }) } if (isValid(this.maxLength)) { rules.push({ max: this.maxLength }) From f024284470e83f57fa98cd2eb634b5410fb74edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=8A=9B?= Date: Wed, 11 Dec 2019 19:39:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?test:=20=E6=96=B0=E5=A2=9E=E6=95=B0?= =?UTF-8?q?=E7=BB=84minItems=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/__tests__/json-schema.spec.tsx | 60 ++++++++++++++++++- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/packages/react-schema-renderer/src/__tests__/json-schema.spec.tsx b/packages/react-schema-renderer/src/__tests__/json-schema.spec.tsx index 2b9fc86e722..ecd43ba834b 100644 --- a/packages/react-schema-renderer/src/__tests__/json-schema.spec.tsx +++ b/packages/react-schema-renderer/src/__tests__/json-schema.spec.tsx @@ -3,10 +3,25 @@ import { registerFormField, connect, SchemaMarkupForm as SchemaForm, - SchemaMarkupField as Field + SchemaMarkupField as Field, + registerFieldMiddleware } from '../index' +import '@testing-library/jest-dom/extend-expect' +import { toArr } from '@uform/shared' import { render, fireEvent, wait } from '@testing-library/react' +registerFieldMiddleware(Field => { + return props => { + const index = props.schema['x-props'] && props.schema['x-props'].index + return ( +
+ +
{props.errors}
+
+ ) + } +}) + registerFormField( 'string', connect()(props => ( @@ -14,6 +29,22 @@ registerFormField( )) ) +registerFormField('array', props => { + const { value, renderField } = props + return ( + + {toArr(value).map((item, index) => { + return ( +
+ {renderField(index)} +
+ ) + })} +
+ ) +}) + + describe('test all apis', () => { //todo test('title', () => { @@ -60,8 +91,31 @@ describe('test all apis', () => { //todo }) - test('minimum', () => { - //todo + test('array minimum', async () => { + const handleSubmit = jest.fn() + const handleValidateFailed = jest.fn() + const TestComponent = () => ( + + + + + + + + + ) + + const { getByTestId, getByText } = render() + + fireEvent.click(getByTestId('btn')) + await wait() + fireEvent.click(getByTestId('btn')) + await wait() + expect(handleSubmit).toHaveBeenCalledTimes(0) + expect(handleValidateFailed).toHaveBeenCalledTimes(2) + expect(getByText('The length or number of entries must be at least 2')).toBeVisible() }) test('exclusiveMinimum', () => { From 15fa31b2f463aeaac82ae991fbb35be749742818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=8A=9B?= Date: Wed, 11 Dec 2019 19:56:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?test:=20=E6=9B=B4=E6=94=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/__tests__/json-schema.spec.tsx | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/packages/react-schema-renderer/src/__tests__/json-schema.spec.tsx b/packages/react-schema-renderer/src/__tests__/json-schema.spec.tsx index ecd43ba834b..5a5cd1ba934 100644 --- a/packages/react-schema-renderer/src/__tests__/json-schema.spec.tsx +++ b/packages/react-schema-renderer/src/__tests__/json-schema.spec.tsx @@ -87,11 +87,35 @@ describe('test all apis', () => { //todo }) + test('minimum', () => { + //todo + }) + test('exclusiveMaximum', () => { //todo }) - test('array minimum', async () => { + test('exclusiveMinimum', () => { + //todo + }) + + test('maxLength', () => { + //todo + }) + + test('minLength', () => { + //todo + }) + + test('pattern', () => { + //todo + }) + + test('maxItems', () => { + //todo + }) + + test('array minItems', async () => { const handleSubmit = jest.fn() const handleValidateFailed = jest.fn() const TestComponent = () => ( @@ -118,29 +142,6 @@ describe('test all apis', () => { expect(getByText('The length or number of entries must be at least 2')).toBeVisible() }) - test('exclusiveMinimum', () => { - //todo - }) - - test('maxLength', () => { - //todo - }) - - test('minLength', () => { - //todo - }) - - test('pattern', () => { - //todo - }) - - test('maxItems', () => { - //todo - }) - - test('minItems', () => { - //todo - }) test('uniqueItems', () => { //todo })