From 6711ef02a35a161574bd6813bb2f02f7b3b70b74 Mon Sep 17 00:00:00 2001 From: liujuping Date: Mon, 28 Mar 2022 23:26:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BD=8E=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=84=E4=BB=B6Slot=E4=B8=8B=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F=E6=9C=AA=E8=A7=A3=E6=9E=90=E5=AE=8C=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__snapshots__/renderer.test.tsx.snap | 62 ++++++++++++++ .../test/renderer/renderer.test.tsx | 85 ++++++++++++++++++- .../renderer-core/test/utils/components.tsx | 8 +- packages/utils/build.test.json | 6 ++ packages/utils/jest.config.js | 14 +++ packages/utils/package.json | 1 + packages/utils/src/schema.ts | 2 +- .../src/__snapshots__/schema.test.ts.snap | 23 +++++ packages/utils/test/src/schema.test.ts | 27 ++++++ 9 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 packages/utils/build.test.json create mode 100644 packages/utils/jest.config.js create mode 100644 packages/utils/test/src/__snapshots__/schema.test.ts.snap create mode 100644 packages/utils/test/src/schema.test.ts diff --git a/packages/renderer-core/test/renderer/__snapshots__/renderer.test.tsx.snap b/packages/renderer-core/test/renderer/__snapshots__/renderer.test.tsx.snap index b253ac9c5..36b4b2bd1 100644 --- a/packages/renderer-core/test/renderer/__snapshots__/renderer.test.tsx.snap +++ b/packages/renderer-core/test/renderer/__snapshots__/renderer.test.tsx.snap @@ -1008,6 +1008,68 @@ exports[`JSExpression JSFunction props with loop 1`] = ` `; +exports[`JSExpression JSSlot has loop 1`] = ` +
+
+
+ 这是一个低代码业务组件~ +
+
+
+
+ 这是一个低代码业务组件~ +
+
+
+
+ 这是一个低代码业务组件~ +
+
+
+`; + exports[`JSExpression base props 1`] = `
{ componentSnapshot = component; done(); - });; + }); }); + + it('JSSlot has loop', (done) => { + const schema = { + componentName: "Page", + props: {}, + children: [ + { + componentName: "SlotComponent", + id: "node_k8bnubvz", + props: { + mobileSlot: { + type: "JSSlot", + title: "mobile容器", + name: "mobileSlot", + value: [ + { + condition: true, + hidden: false, + children: [ + { + condition: true, + hidden: false, + loopArgs: [ + "item", + "index" + ], + isLocked: false, + conditionGroup: "", + componentName: "Text", + id: "node_ocl1ao1o7w4", + title: "", + props: { + maxLine: 0, + showTitle: false, + className: "text_l1ao7pfb", + behavior: "NORMAL", + content: "这是一个低代码业务组件~", + __style__: ":root {\n font-size: 14px;\n color: #666;\n}", + fieldId: "text_l1ao7lvp" + } + } + ], + loop: { + type: "JSExpression", + value: "state.content" + }, + loopArgs: [ + "item", + "index" + ], + isLocked: false, + conditionGroup: "", + componentName: "Div", + id: "node_ocl1ao1o7w3", + title: "", + props: { + useFieldIdAsDomId: false, + customClassName: "", + className: "div_l1ao7pfc", + behavior: "NORMAL", + __style__: ":root {\n padding: 12px;\n background: #f2f2f2;\n border: 1px solid #ddd;\n}", + fieldId: "div_l1ao7lvq" + } + } + ] + }, + }, + } + ], + state: { + content: { + type: "JSExpression", + value: "[{}, {}, {}]", + }, + }, + }; + + getComp(schema, components.Div).then(({ component, inst }) => { + expect(inst.length).toBe(3); + componentSnapshot = component; + done(); + }); + }) }) \ No newline at end of file diff --git a/packages/renderer-core/test/utils/components.tsx b/packages/renderer-core/test/utils/components.tsx index 5fdadb2c3..1eb7593a8 100644 --- a/packages/renderer-core/test/utils/components.tsx +++ b/packages/renderer-core/test/utils/components.tsx @@ -1,6 +1,10 @@ import { Box, Breadcrumb, Form, Select, Input, Button, Table, Pagination, Dialog } from '@alifd/next'; -const Div = (props) => (
{props.children}
); +const Div = (props: any) => (
{props.children}
); + +const Text = (props: any) => (
{props.content}
); + +const SlotComponent = (props: any) => props.mobileSlot; const components = { Box, @@ -17,6 +21,8 @@ const components = { Dialog, ErrorComponent: Select, Div, + SlotComponent, + Text, }; export default components; \ No newline at end of file diff --git a/packages/utils/build.test.json b/packages/utils/build.test.json new file mode 100644 index 000000000..228c07e7f --- /dev/null +++ b/packages/utils/build.test.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "build-plugin-component", + "@ali/lowcode-test-mate/plugin/index.ts" + ] +} diff --git a/packages/utils/jest.config.js b/packages/utils/jest.config.js new file mode 100644 index 000000000..6bcf05cb0 --- /dev/null +++ b/packages/utils/jest.config.js @@ -0,0 +1,14 @@ +const esModules = ['@recore/obx-react'].join('|'); + +module.exports = { + transformIgnorePatterns: [ + `/node_modules/(?!${esModules})/`, + ], + moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], + collectCoverage: true, + collectCoverageFrom: [ + 'src/**/*.{ts,tsx}', + '!**/node_modules/**', + '!**/vendor/**', + ], +}; diff --git a/packages/utils/package.json b/packages/utils/package.json index 1d8bf226d..84bbbe1df 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -9,6 +9,7 @@ "main": "lib/index.js", "module": "es/index.js", "scripts": { + "test": "build-scripts test --config build.test.json", "build": "build-scripts build --skip-demo" }, "dependencies": { diff --git a/packages/utils/src/schema.ts b/packages/utils/src/schema.ts index 477670ded..83646386c 100644 --- a/packages/utils/src/schema.ts +++ b/packages/utils/src/schema.ts @@ -26,7 +26,7 @@ export function compatibleLegaoSchema(props: any): any { type: 'JSSlot', title: (props.value.props as any)?.slotTitle, name: (props.value.props as any)?.slotName, - value: props.value.children, + value: compatibleLegaoSchema(props.value.children), params: (props.value.props as any)?.slotParams, }; } else { diff --git a/packages/utils/test/src/__snapshots__/schema.test.ts.snap b/packages/utils/test/src/__snapshots__/schema.test.ts.snap new file mode 100644 index 000000000..e926c89b3 --- /dev/null +++ b/packages/utils/test/src/__snapshots__/schema.test.ts.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Schema Ut props 1`] = ` +Object { + "props": Object { + "mobileSlot": Object { + "name": undefined, + "params": undefined, + "title": undefined, + "type": "JSSlot", + "value": Array [ + Object { + "loop": Object { + "mock": undefined, + "type": "JSExpression", + "value": "props.content", + }, + }, + ], + }, + }, +} +`; diff --git a/packages/utils/test/src/schema.test.ts b/packages/utils/test/src/schema.test.ts new file mode 100644 index 000000000..138dd7a82 --- /dev/null +++ b/packages/utils/test/src/schema.test.ts @@ -0,0 +1,27 @@ +import { compatibleLegaoSchema } from '../../src/schema'; +describe('Schema Ut', () => { + it('props', () => { + const schema = { + props: { + mobileSlot: { + type: "JSBlock", + value: { + componentName: "Slot", + children: [ + { + loop: { + variable: "props.content", + type: "variable" + }, + } + ], + } + }, + }, + }; + + const result = compatibleLegaoSchema(schema); + expect(result).toMatchSnapshot(); + expect(result.props.mobileSlot.value[0].loop.type).toBe('JSExpression'); + }); +}) \ No newline at end of file