1+ import renderer from 'react-test-renderer' ;
2+ import React from 'react' ;
3+ import { createElement } from 'react' ;
4+ import '../utils/react-env-init' ;
5+ import { leafWrapper } from '../../src/hoc/leaf' ;
6+ import components from '../utils/components' ;
7+ import Node from '../utils/node' ;
8+
9+
10+ const baseRenderer : any = {
11+ __debug ( ) { } ,
12+ __getComponentProps ( schema : any ) {
13+ return schema . props ;
14+ } ,
15+ __getSchemaChildrenVirtualDom ( ) { } ,
16+ context : {
17+ engine : {
18+ createElement,
19+ }
20+ } ,
21+ props : {
22+ __host : { } ,
23+ getNode : ( ) => { } ,
24+ __container : ( ) => { } ,
25+ }
26+ }
27+
28+ describe ( 'leafWrapper' , ( ) => {
29+ const Div = leafWrapper ( components . Div as any , {
30+ schema : {
31+ id : 'div' ,
32+ } ,
33+ baseRenderer,
34+ componentInfo : { } ,
35+ scope : { } ,
36+ } ) ;
37+
38+ const DivNode = new Node ( { } ) ;
39+ const TextNode = new Node ( { } ) ;
40+
41+ const Text = leafWrapper ( components . Text as any , {
42+ schema : {
43+ id : 'div' ,
44+ props : {
45+ content : 'content'
46+ }
47+ } ,
48+ baseRenderer,
49+ componentInfo : { } ,
50+ scope : { } ,
51+ } ) ;
52+
53+ const component = renderer . create (
54+ // @ts -ignore
55+ < Div _leaf = { DivNode } >
56+ < Text _leaf = { TextNode } content = "content" > </ Text >
57+ </ Div >
58+ ) ;
59+
60+ it ( 'base' , ( ) => {
61+ let tree = component . toJSON ( ) ;
62+ expect ( tree ) . toMatchSnapshot ( ) ;
63+ } ) ;
64+
65+ it ( 'change props' , ( ) => {
66+ TextNode . emitPropChange ( {
67+ key : 'content' ,
68+ newValue : 'new content' ,
69+ } as any ) ;
70+
71+ let tree = component . toJSON ( ) ;
72+ expect ( tree ) . toMatchSnapshot ( ) ;
73+ } ) ;
74+ } ) ;
75+
76+
77+ describe ( 'loop' , ( ) => {
78+ const Div = leafWrapper ( components . Div as any , {
79+ schema : {
80+ id : 'div' ,
81+ } ,
82+ baseRenderer,
83+ componentInfo : { } ,
84+ scope : { } ,
85+ } ) ;
86+
87+ const DivNode = new Node ( { } ) ;
88+ const TextNode = new Node ( { } ) ;
89+
90+ const Text = leafWrapper ( components . Text as any , {
91+ schema : {
92+ id : 'div' ,
93+ props : {
94+ content : 'content'
95+ }
96+ } ,
97+ baseRenderer,
98+ componentInfo : { } ,
99+ scope : { } ,
100+ } ) ;
101+
102+ const component = renderer . create (
103+ // @ts -ignore
104+ < Div _leaf = { DivNode } >
105+ < Text _leaf = { TextNode } content = "content" > </ Text >
106+ </ Div >
107+ ) ;
108+ } )
0 commit comments