GeezerVison is showing github.com — test: add renderer-core hoc/leaf single test · Alvison/lowcode-engine@11319e1
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/jest.config.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,6 +23,8 @@ const jestConfig = { | 23 | 23 | collectCoverageFrom: [ | 24 | 24 | 'src/**/*.ts', | 25 | 25 | 'src/**/*.tsx', | | 26 | + '!src/utils/logger.ts', | | 27 | + '!src/types/index.ts', | 26 | 28 | ], | 27 | 29 | }; | 28 | 30 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/renderer-core/src/hoc/leaf.tsx +6-24Lines changed: 6 additions & 24 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -216,24 +216,6 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 216 | 216 | this.recordTime(); | 217 | 217 | } | 218 | 218 |
| 219 | | - get childrenMap(): any { | 220 | | - const map = new Map(); | 221 | | - | 222 | | - if (!this.hasChildren) { | 223 | | - return map; | 224 | | - } | 225 | | - | 226 | | - this.children.forEach((d: any) => { | 227 | | - if (Array.isArray(d)) { | 228 | | - map.set(d[0].props.componentId, d); | 229 | | - return; | 230 | | - } | 231 | | - map.set(d.props.componentId, d); | 232 | | - }); | 233 | | - | 234 | | - return map; | 235 | | - } | 236 | | - | 237 | 219 | get defaultState() { | 238 | 220 | const { | 239 | 221 | hidden = false, | @@ -253,18 +235,18 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 253 | 235 | super(props, context); | 254 | 236 | // 监听以下事件,当变化时更新自己 | 255 | 237 | __debug(`${schema.componentName}[${this.props.componentId}] leaf render in SimulatorRendererView`); | 256 | | - clearRerenderEvent(this.props.componentId); | | 238 | + clearRerenderEvent(componentCacheId); | 257 | 239 | const _leaf = this.leaf; | 258 | 240 | this.initOnPropsChangeEvent(_leaf); | 259 | 241 | this.initOnChildrenChangeEvent(_leaf); | 260 | 242 | this.initOnVisibleChangeEvent(_leaf); | 261 | 243 | this.curEventLeaf = _leaf; | 262 | 244 |
| 263 | | - cache.ref.set(props.componentId, { | | 245 | + cache.ref.set(componentCacheId, { | 264 | 246 | makeUnitRender: this.makeUnitRender, | 265 | 247 | }); | 266 | 248 |
| 267 | | - let cacheState = cache.state.get(props.componentId); | | 249 | + let cacheState = cache.state.get(componentCacheId); | 268 | 250 | if (!cacheState || cacheState.__tag !== props.__tag) { | 269 | 251 | cacheState = this.defaultState; | 270 | 252 | } | @@ -275,7 +257,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 275 | 257 | private curEventLeaf: Node | undefined; | 276 | 258 |
| 277 | 259 | setState(state: any) { | 278 | | - cache.state.set(this.props.componentId, { | | 260 | + cache.state.set(componentCacheId, { | 279 | 261 | ...this.state, | 280 | 262 | ...state, | 281 | 263 | __tag: this.props.__tag, | @@ -489,7 +471,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 489 | 471 | // TODO: 缓存同级其他元素的 children。 | 490 | 472 | // 缓存二级 children Next 查询筛选组件有问题 | 491 | 473 | // 缓存一级 children Next Tab 组件有问题 | 492 | | - const nextChild = getChildren(leaf?.export?.(TransformStage.Render) as types.ISchema, scope, Comp); // this.childrenMap | | 474 | + const nextChild = getChildren(leaf?.export?.(TransformStage.Render) as types.ISchema, scope, Comp); | 493 | 475 | __debug(`${schema.componentName}[${this.props.componentId}] component trigger onChildrenChange event`, nextChild); | 494 | 476 | this.setState({ | 495 | 477 | nodeChildren: nextChild, | @@ -531,7 +513,7 @@ export function leafWrapper(Comp: types.IBaseRenderComponent, { | 531 | 513 | } | 532 | 514 |
| 533 | 515 | get leaf(): Node | undefined { | 534 | | - return this.props._leaf || getNode(this.props.componentId); | | 516 | + return this.props._leaf || getNode(componentCacheId); | 535 | 517 | } | 536 | 518 |
| 537 | 519 | render() { | |
Collapse file Copy file name to clipboard +128-79Lines changed: 128 additions & 79 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP | 2 | 2 |
| 3 | | -exports[`leafWrapper base 1`] = ` | 4 | | -<div | 5 | | - _leaf={ | 6 | | - Node { | 7 | | - "emitter": EventEmitter { | 8 | | - "_events": Object { | 9 | | - "onChildrenChange": [Function], | 10 | | - "onPropChange": [Function], | 11 | | - "onVisibleChange": [Function], | 12 | | - }, | 13 | | - "_eventsCount": 3, | 14 | | - "_maxListeners": undefined, | 15 | | - Symbol(kCapture): false, | 16 | | - }, | 17 | | - "hasLoop": false, | 18 | | - "schema": Object {}, | 19 | | - } | 20 | | - } | 21 | | -> | 22 | | - <div> | | 3 | +exports[`children this.props.children is array 1`] = ` | | 4 | +<div> | | 5 | + <div | | 6 | + content="content" | | 7 | + > | | 8 | + content | | 9 | + </div> | | 10 | + <div | | 11 | + content="content" | | 12 | + > | | 13 | + content | | 14 | + </div> | | 15 | +</div> | | 16 | +`; | | 17 | + | | 18 | +exports[`lifecycle leaf change and make componentWillReceiveProps 1`] = ` | | 19 | +<div> | | 20 | + <div | | 21 | + __tag="222" | | 22 | + content="content new leaf" | | 23 | + > | | 24 | + content new leaf | | 25 | + </div> | | 26 | +</div> | | 27 | +`; | | 28 | + | | 29 | +exports[`lifecycle props change and make componentWillReceiveProps 1`] = ` | | 30 | +<div> | | 31 | + <div | | 32 | + content="content" | | 33 | + > | | 34 | + content | | 35 | + </div> | | 36 | +</div> | | 37 | +`; | | 38 | + | | 39 | +exports[`lifecycle props change and make componentWillReceiveProps 2`] = ` | | 40 | +<div> | | 41 | + <div | | 42 | + content="content 123" | | 43 | + > | | 44 | + content 123 | | 45 | + </div> | | 46 | +</div> | | 47 | +`; | | 48 | + | | 49 | +exports[`lifecycle props change and make componentWillReceiveProps 3`] = ` | | 50 | +<div> | | 51 | + <div | | 52 | + __tag="111" | | 53 | + content="content 123" | | 54 | + > | | 55 | + content 123 | | 56 | + </div> | | 57 | +</div> | | 58 | +`; | | 59 | + | | 60 | +exports[`mini unit render leaf has a loop, render from parent 1`] = ` | | 61 | +<div> | | 62 | + this is a new children | | 63 | +</div> | | 64 | +`; | | 65 | + | | 66 | +exports[`mini unit render make text props change 1`] = ` | | 67 | +<div> | | 68 | + <div | | 69 | + content="content" | | 70 | + > | 23 | 71 | content | 24 | 72 | </div> | 25 | 73 | </div> | 26 | 74 | `; | 27 | 75 |
| 28 | | -exports[`leafWrapper change ___condition___ props 1`] = ` | | 76 | +exports[`mini unit render make text props change 2`] = ` | 29 | 77 | <div | 30 | | - _leaf={ | 31 | | - Node { | 32 | | - "emitter": EventEmitter { | 33 | | - "_events": Object { | 34 | | - "onChildrenChange": [Function], | 35 | | - "onPropChange": [Function], | 36 | | - "onVisibleChange": [Function], | 37 | | - }, | 38 | | - "_eventsCount": 3, | 39 | | - "_maxListeners": undefined, | 40 | | - Symbol(kCapture): false, | 41 | | - }, | 42 | | - "hasLoop": false, | 43 | | - "schema": Object {}, | 44 | | - } | 45 | | - } | | 78 | + newPropKey="newPropValue" | 46 | 79 | /> | 47 | 80 | `; | 48 | 81 |
| 49 | | -exports[`leafWrapper change ___condition___ props, but not hidden component 1`] = ` | 50 | | -<div | 51 | | - _leaf={ | 52 | | - Node { | 53 | | - "emitter": EventEmitter { | 54 | | - "_events": Object { | 55 | | - "onChildrenChange": [Function], | 56 | | - "onPropChange": [Function], | 57 | | - "onVisibleChange": [Function], | 58 | | - }, | 59 | | - "_eventsCount": 3, | 60 | | - "_maxListeners": undefined, | 61 | | - Symbol(kCapture): false, | 62 | | - }, | 63 | | - "hasLoop": false, | 64 | | - "schema": Object {}, | 65 | | - } | 66 | | - } | 67 | | -> | 68 | | - <div> | 69 | | - new content | | 82 | +exports[`mini unit render parent is a mock leaf 1`] = ` | | 83 | +<div> | | 84 | + <div | | 85 | + content="new content to mock" | | 86 | + > | | 87 | + new content to mock | 70 | 88 | </div> | 71 | 89 | </div> | 72 | 90 | `; | 73 | 91 |
| 74 | | -exports[`leafWrapper change props 1`] = ` | 75 | | -<div | 76 | | - _leaf={ | 77 | | - Node { | 78 | | - "emitter": EventEmitter { | 79 | | - "_events": Object { | 80 | | - "onChildrenChange": [Function], | 81 | | - "onPropChange": [Function], | 82 | | - "onVisibleChange": [Function], | 83 | | - }, | 84 | | - "_eventsCount": 3, | 85 | | - "_maxListeners": undefined, | 86 | | - Symbol(kCapture): false, | 87 | | - }, | 88 | | - "hasLoop": false, | 89 | | - "schema": Object {}, | 90 | | - } | 91 | | - } | 92 | | -> | 93 | | - <div> | 94 | | - new content | | 92 | +exports[`mini unit render props has new children 1`] = ` | | 93 | +<div> | | 94 | + children 01 | | 95 | + children 02 | | 96 | +</div> | | 97 | +`; | | 98 | + | | 99 | +exports[`onChildrenChange children is array string 1`] = ` | | 100 | +<div> | | 101 | + onChildrenChange content 01 | | 102 | + onChildrenChange content 02 | | 103 | +</div> | | 104 | +`; | | 105 | + | | 106 | +exports[`onPropChange change textNode [key:___condition___] props, but not hidden component 1`] = ` | | 107 | +<div> | | 108 | + <div | | 109 | + content="content" | | 110 | + > | | 111 | + content | | 112 | + </div> | | 113 | +</div> | | 114 | +`; | | 115 | + | | 116 | +exports[`onPropChange change textNode [key:___condition___] props, hide textNode component 1`] = `<div />`; | | 117 | + | | 118 | +exports[`onPropChange change textNode [key:content], content in this.props but not in leaf.export result 1`] = ` | | 119 | +<div> | | 120 | + <div | | 121 | + content="content" | | 122 | + > | | 123 | + content | | 124 | + </div> | | 125 | +</div> | | 126 | +`; | | 127 | + | | 128 | +exports[`onPropChange change textNode [key:content], content in this.props but not in leaf.export result 2`] = ` | | 129 | +<div> | | 130 | + <div | | 131 | + content={null} | | 132 | + /> | | 133 | +</div> | | 134 | +`; | | 135 | + | | 136 | +exports[`onVisibleChange visible is false 1`] = `<div />`; | | 137 | + | | 138 | +exports[`onVisibleChange visible is true 1`] = ` | | 139 | +<div> | | 140 | + <div | | 141 | + content="content" | | 142 | + > | | 143 | + content | 95 | 144 | </div> | 96 | 145 | </div> | 97 | 146 | `; |
|