@@ -54,7 +54,60 @@ describe('Node 方法测试', () => {
5454 project = null ;
5555 } ) ;
5656
57- it ( 'condition group' , ( ) => { } ) ;
57+ // Case 1: When children is null
58+ test ( 'initialChildren returns result of initialChildren function when children is null ' , ( ) => {
59+ const node = new Node ( doc , { componentName : 'Button' , props : { a : 1 } } ) ;
60+ const result = node . initialChildren ( null ) ;
61+ // 预期结果是一个空数组
62+ expect ( result ) . toEqual ( [ ] ) ;
63+ } ) ;
64+
65+ // Case 2: When children is undefined
66+ test ( 'initialChildren returns result of initialChildren function when children is null ' , ( ) => {
67+ const node = new Node ( doc , { componentName : 'Button' , props : { a : 1 } } ) ;
68+ const result = node . initialChildren ( undefined ) ;
69+ // 预期结果是一个空数组
70+ expect ( result ) . toEqual ( [ ] ) ;
71+ } ) ;
72+
73+ // Case 3: When children is array
74+ test ( 'initialChildren returns result of initialChildren function when children is null ' , ( ) => {
75+ const node = new Node ( doc , { componentName : 'Button' , props : { a : 1 } } ) ;
76+ const childrenArray = [ { id : 1 , name : 'Child 1' } , { id : 2 , name : 'Child 2' } ] ;
77+ const result = node . initialChildren ( childrenArray ) ;
78+ // 预期结果是一个数组
79+ expect ( result ) . toEqual ( childrenArray ) ;
80+ } ) ;
81+
82+ // Case 4: When children is not null and not an array
83+ test ( 'initialChildren returns result of initialChildren function when children is null ' , ( ) => {
84+ const node = new Node ( doc , { componentName : 'Button' , props : { a : 1 } } ) ;
85+ const childObject = { id : 1 , name : 'Child 1' } ;
86+ const result = node . initialChildren ( childObject ) ;
87+ // 预期结果是一个数组
88+ expect ( result ) . toEqual ( [ childObject ] ) ;
89+ } ) ;
90+
91+ // Case 5: When children 0
92+ test ( 'initialChildren returns result of initialChildren function when children is null ' , ( ) => {
93+ const node = new Node ( doc , { componentName : 'Button' , props : { a : 1 } } ) ;
94+ const childObject = 0 ;
95+ const result = node . initialChildren ( childObject ) ;
96+ // 预期结果是一个数组
97+ expect ( result ) . toEqual ( [ 0 ] ) ;
98+ } ) ;
99+
100+ // Case 6: When children false
101+ test ( 'initialChildren returns result of initialChildren function when children is null ' , ( ) => {
102+ const node = new Node ( doc , { componentName : 'Button' , props : { a : 1 } } ) ;
103+ const childObject = false ;
104+ const result = node . initialChildren ( childObject ) ;
105+ // 预期结果是一个数组
106+ expect ( result ) . toEqual ( [ false ] ) ;
107+ } ) ;
108+
109+
110+ it ( 'condition group' , ( ) => { } ) ;
58111
59112 it ( 'getExtraProp / setExtraProp' , ( ) => {
60113 const firstBtn = doc . getNode ( 'node_k1ow3cbn' ) ! ;
@@ -367,7 +420,7 @@ describe('Node 方法测试', () => {
367420 expect ( mockFn ) . not . toHaveBeenCalled ( ) ;
368421 } ) ;
369422
370- it ( 'addSlot / unlinkSlot / removeSlot' , ( ) => { } ) ;
423+ it ( 'addSlot / unlinkSlot / removeSlot' , ( ) => { } ) ;
371424
372425 it ( 'setProps' , ( ) => {
373426 const firstBtn = doc . getNode ( 'node_k1ow3cbn' ) ! ;
@@ -407,7 +460,7 @@ describe('Node 方法测试', () => {
407460 designer . createComponentMeta ( btnMetadata ) ;
408461 const btn = doc . getNode ( 'node_k1ow3cbn' ) ;
409462 // 从 componentMeta 中获取到 title 值
410- expect ( btn . title ) . toEqual ( { type : 'i18n' , 'zh-CN' : '按钮' , 'en-US' : 'Button' } ) ;
463+ expect ( btn . title ) . toEqual ( { type : 'i18n' , 'zh-CN' : '按钮' , 'en-US' : 'Button' } ) ;
411464 // 从 extraProp 中获取值
412465 btn . setExtraProp ( 'title' , 'hello button' ) ;
413466 expect ( btn . title ) . toBe ( 'hello button' ) ;
@@ -546,7 +599,7 @@ describe('Node 方法测试', () => {
546599 expect ( comparePosition ( firstBtn , firstCard ) ) . toBe ( PositionNO . BeforeOrAfter ) ;
547600 } ) ;
548601
549- it ( 'getZLevelTop' , ( ) => { } ) ;
602+ it ( 'getZLevelTop' , ( ) => { } ) ;
550603 it ( 'propsData' , ( ) => {
551604 expect ( new Node ( doc , { componentName : 'Leaf' } ) . propsData ) . toBeNull ( ) ;
552605 expect ( new Node ( doc , { componentName : 'Fragment' } ) . propsData ) . toBeNull ( ) ;
0 commit comments