@@ -9,7 +9,7 @@ import type {
9
9
SimpleNode ,
10
10
} from '@glimmer/interfaces' ;
11
11
import type { TemplateOnlyComponent } from '@glimmer/runtime' ;
12
- import { setComponentTemplate } from '@glimmer/manager' ;
12
+ import { modifierCapabilities , setComponentTemplate , setModifierManager } from '@glimmer/manager' ;
13
13
import { EMPTY_ARGS , templateOnlyComponent , TemplateOnlyComponentManager } from '@glimmer/runtime' ;
14
14
import { assign , expect } from '@glimmer/util' ;
15
15
@@ -66,9 +66,27 @@ class DebugRenderTreeDelegate extends JitRenderDelegate {
66
66
67
67
this . registry . register ( 'component' , name , definition ) ;
68
68
}
69
+
70
+ registerCustomModifier ( name : string ) {
71
+ const r = setModifierManager (
72
+ ( ) => ( {
73
+ capabilities : modifierCapabilities ( '3.22' ) ,
74
+ createModifier ( ) { } ,
75
+ installModifier ( ) { } ,
76
+ updateModifier ( ) { } ,
77
+ destroyModifier ( ) { } ,
78
+ } ) ,
79
+ class DidInsertModifier { }
80
+ ) ;
81
+ this . registry . register ( 'modifier' , name , r ) ;
82
+ return r ;
83
+ }
69
84
}
70
85
71
86
class DebugRenderTreeTest extends RenderTest {
87
+ defineModifier ( name : string ) {
88
+ return this . delegate . registerCustomModifier ( name ) ;
89
+ }
72
90
static suiteName = 'Application test: debug render tree' ;
73
91
74
92
declare delegate : DebugRenderTreeDelegate ;
@@ -253,6 +271,77 @@ class DebugRenderTreeTest extends RenderTest {
253
271
] ) ;
254
272
}
255
273
274
+ @test modifiers ( ) {
275
+ this . registerComponent ( 'Glimmer' , 'HelloWorld' , 'Hello World' ) ;
276
+ const didInsert = ( ) => null ;
277
+ this . registerModifier (
278
+ 'did-insert' ,
279
+ class {
280
+ element ?: SimpleElement ;
281
+ didInsertElement ( ) { }
282
+ didUpdate ( ) { }
283
+ willDestroyElement ( ) { }
284
+ }
285
+ ) ;
286
+ const modifier = this . defineModifier ( 'did-update' ) ;
287
+
288
+ this . render (
289
+ `<div {{on 'click' this.didInsert}} {{did-insert this.didInsert}} {{did-update this.didInsert}} {{this.modifier this.didInsert}}><HelloWorld /></div>` ,
290
+ {
291
+ didInsert : didInsert ,
292
+ modifier : modifier ,
293
+ }
294
+ ) ;
295
+
296
+ this . assertRenderTree ( [
297
+ {
298
+ type : 'modifier' ,
299
+ name : 'did-insert' ,
300
+ args : { positional : [ didInsert ] , named : { } } ,
301
+ instance : ( instance : any ) => typeof instance . didInsertElement === 'function' ,
302
+ template : null ,
303
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
304
+ children : [ ] ,
305
+ } ,
306
+ {
307
+ type : 'modifier' ,
308
+ name : 'did-update' ,
309
+ args : { positional : [ didInsert ] , named : { } } ,
310
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
311
+ template : null ,
312
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
313
+ children : [ ] ,
314
+ } ,
315
+ {
316
+ type : 'modifier' ,
317
+ name : 'DidInsertModifier' ,
318
+ args : { positional : [ didInsert ] , named : { } } ,
319
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
320
+ template : null ,
321
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
322
+ children : [ ] ,
323
+ } ,
324
+ {
325
+ type : 'modifier' ,
326
+ name : 'on' ,
327
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
328
+ instance : ( instance : any ) => instance === undefined ,
329
+ template : null ,
330
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
331
+ children : [ ] ,
332
+ } ,
333
+ {
334
+ type : 'component' ,
335
+ name : 'HelloWorld' ,
336
+ args : { positional : [ ] , named : { } } ,
337
+ instance : ( instance : any ) => instance !== undefined ,
338
+ template : '(unknown template module)' ,
339
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
340
+ children : [ ] ,
341
+ } ,
342
+ ] ) ;
343
+ }
344
+
256
345
@test 'getDebugCustomRenderTree works' ( ) {
257
346
let bucket1 = { } ;
258
347
let instance1 = { } ;
@@ -502,7 +591,7 @@ class DebugRenderTreeTest extends RenderTest {
502
591
this . assertRenderNode ( actualNode , expected , `${ actualNode . type } :${ actualNode . name } ` ) ;
503
592
} ) ;
504
593
} else {
505
- this . assert . deepEqual ( actual , [ ] , path ) ;
594
+ this . assert . deepEqual ( actual , expectedNodes , path ) ;
506
595
}
507
596
}
508
597
0 commit comments