Skip to content

Commit

Permalink
feat(utils): parseUnitedSchema supports transparent DataSchema keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
mengshang918 committed Apr 14, 2022
1 parent a5290f8 commit 8f00445
Show file tree
Hide file tree
Showing 16 changed files with 1,693 additions and 305 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@rollup/plugin-replace": "^2.3.2",
"@rollup/plugin-strip": "^1.3.3",
"@types/jest": "^26.0.5",
"@types/lodash": "^4.14.181",
"@types/react": "^16.9.36",
"@types/react-color": "^3.0.2",
"@types/react-dom": "^16.9.8",
Expand Down
52 changes: 43 additions & 9 deletions packages/utils/__tests__/parse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseUnitedSchema } from '../src/index'
import { parseUnitedSchema, UnitedSchema } from '../src/index'
import {
unitedSchema as test1,
parsedSchema as verify1,
Expand Down Expand Up @@ -31,45 +31,79 @@ import {
unitedSchema as test8,
parsedSchema as verify8,
} from '../__testsdata__/array.schema'
import {
unitedSchema as test9,
parsedSchema as verify9,
} from '../__testsdata__/errMsg4.schema'
import {
unitedSchema as test10,
parsedSchema as verify10,
} from '../__testsdata__/root.schema'
import {
unitedSchema as test11,
parsedSchema as verify11,
} from '../__testsdata__/test.schema'
import {
unitedSchema as test12,
parsedSchema as verify12,
} from '../__testsdata__/repeatField.schema'

describe('parseUnitedSchema', () => {
test('test datePicker.schema.js', () => {
const data = parseUnitedSchema(test7)
const data = parseUnitedSchema(test7 as UnitedSchema)
expect(data).toStrictEqual(verify7)
})

test('test multinest.schema.js', () => {
const data = parseUnitedSchema(test1)
const data = parseUnitedSchema(test1 as UnitedSchema)
expect(data).toStrictEqual(verify1)
})

test('test nest.schema.js', () => {
const data = parseUnitedSchema(test2)
const data = parseUnitedSchema(test2 as UnitedSchema)
expect(data).toStrictEqual(verify2)
})

test('test nestObject.schema.js', () => {
const data = parseUnitedSchema(test3)
const data = parseUnitedSchema(test3 as UnitedSchema)
expect(data).toStrictEqual(verify3)
})

test('test errMsg.schema.js', () => {
const data = parseUnitedSchema(test4)
const data = parseUnitedSchema(test4 as UnitedSchema)
expect(data).toStrictEqual(verify4)
})

test('test errMsg.schema2.js', () => {
const data = parseUnitedSchema(test5)
const data = parseUnitedSchema(test5 as UnitedSchema)
expect(data).toStrictEqual(verify5)
})

test('test errMsg.schema3.js', () => {
const data = parseUnitedSchema(test6)
const data = parseUnitedSchema(test6 as UnitedSchema)
expect(data).toStrictEqual(verify6)
})

test('test errMsg4.schema.js', () => {
const data = parseUnitedSchema(test9 as UnitedSchema)
expect(data).toStrictEqual(verify9)
})

test('test array.schema.js', () => {
const data = parseUnitedSchema(test8)
const data = parseUnitedSchema(test8 as UnitedSchema)
expect(data).toStrictEqual(verify8)
})
test('test root.schema.js', () => {
const data = parseUnitedSchema(test10 as UnitedSchema)
expect(data).toStrictEqual(verify10)
})

test('test test.schema.js', () => {
const data = parseUnitedSchema(test11 as UnitedSchema)
expect(data).toStrictEqual(verify11)
})
test('test repeatField.schema.js', () => {
const data = parseUnitedSchema(test12 as UnitedSchema)
expect(data).toStrictEqual(verify12)
})
})
1 change: 1 addition & 0 deletions packages/utils/__testsdata__/array.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ export const parsedSchema = {
unitedSchemaKey: 'schema.0.items',
},
},
customProps: [],
}
1 change: 1 addition & 0 deletions packages/utils/__testsdata__/errMsg.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ export const parsedSchema = {
unitedSchemaKey: 'schema.0',
},
},
customProps: [],
}
1 change: 1 addition & 0 deletions packages/utils/__testsdata__/errMsg2.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ export const parsedSchema = {
unitedSchemaKey: 'schema.0',
},
},
customProps: [],
}
1 change: 1 addition & 0 deletions packages/utils/__testsdata__/errMsg3.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ export const parsedSchema = {
},
theme: 'antd',
},
customProps: [],
}
150 changes: 150 additions & 0 deletions packages/utils/__testsdata__/errMsg4.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
export const unitedSchema = {
theme: 'antd',
validateTime: 'submit',
requiredMode: 'default',
type: 'object',
footer: {},
formMode: 'edit',
containerStyle: {},
'ui:a1': 1,
ui: {
mode: 'edit',
a1: 2,
b: 2,
'$:type': 'drip',
},
'ui:a': 1,
'ui:b': 1,
schema: [
{
fieldKey: 'name',
title: '名字',
type: 'string',
requiredMsg: '该项必填',
ui: {
type: 'text',
placeholder: '请输入name,当name1有值时,该表单隐藏',
description: {
type: 'icon',
title: 'hover触发提示',
trigger: 'hover',
},
},
},
{
title: '下拉输入',
type: 'object',
fieldKey: 'babelRadio',
ui: {
type: 'selectText',
placeholder: '请选择',
allowClear: true,
multiple: true,
requestCache: true,
options: [
{
label: '北京',
value: '0',
},
{
label: '上海',
value: '1',
},
{
label: '成都',
value: '2',
},
{
label: '武汉',
value: '3',
},
],
},
},
],
}

export const parsedSchema = {
dataSchema: {
validateTime: 'submit',
requiredMode: 'default',
type: 'object',
properties: {
name: {
title: '名字',
type: 'string',
},
babelRadio: {
title: '下拉输入',
type: 'object',
},
},
required: ['name'],
errorMessage: {
required: {
name: '该项必填',
},
},
},
uiSchema: {
theme: 'antd',
footer: {},
formMode: 'edit',
containerStyle: {},
mode: 'edit',
a: 1,
a1: 2,
b: 2,
order: ['name', 'babelRadio'],
'$:type': 'drip',
properties: {
name: {
type: 'text',
placeholder: '请输入name,当name1有值时,该表单隐藏',
description: {
type: 'icon',
title: 'hover触发提示',
trigger: 'hover',
},
},
babelRadio: {
type: 'selectText',
placeholder: '请选择',
allowClear: true,
multiple: true,
requestCache: true,
options: [
{
label: '北京',
value: '0',
},
{
label: '上海',
value: '1',
},
{
label: '成都',
value: '2',
},
{
label: '武汉',
value: '3',
},
],
},
},
},
typePath: {
babelRadio: {
fatherKey: '',
type: 'object',
unitedSchemaKey: 'schema.1',
},
name: {
fatherKey: '',
type: 'string',
unitedSchemaKey: 'schema.0',
},
},
customProps: [],
}
1 change: 1 addition & 0 deletions packages/utils/__testsdata__/multinest.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,5 @@ export const parsedSchema = {
unitedSchemaKey: 'schema.1.items.schema.0.items',
},
},
customProps: [],
}
3 changes: 2 additions & 1 deletion packages/utils/__testsdata__/nest.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const parsedSchema = {
},
tupleItem: {
type: 'array',
order: [0, 1],
order: ['0', '1'],
properties: {
0: {
type: 'input',
Expand Down Expand Up @@ -290,4 +290,5 @@ export const parsedSchema = {
unitedSchemaKey: 'schema.3.items.schema.1',
},
},
customProps: [],
}
3 changes: 2 additions & 1 deletion packages/utils/__testsdata__/nestObject.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const parsedSchema = {
},
tupleItem: {
type: 'array',
order: [0, 1],
order: ['0', '1'],
properties: {
0: {
type: 'input',
Expand Down Expand Up @@ -338,4 +338,5 @@ export const parsedSchema = {
unitedSchemaKey: 'schema.3.items.schema.1',
},
},
customProps: [],
}
Loading

0 comments on commit 8f00445

Please sign in to comment.