@@ -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,196 @@ 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}}
290
+ ><HelloWorld />
291
+ {{~#if this.more~}}
292
+ <div {{on 'click' this.didInsert}}></div>
293
+ {{~/if~}}
294
+ </div>` ,
295
+ {
296
+ didInsert : didInsert ,
297
+ modifier : modifier ,
298
+ more : false ,
299
+ }
300
+ ) ;
301
+
302
+ this . assertRenderTree ( [
303
+ {
304
+ type : 'modifier' ,
305
+ name : 'did-update' ,
306
+ args : { positional : [ didInsert ] , named : { } } ,
307
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
308
+ template : null ,
309
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
310
+ children : [ ] ,
311
+ } ,
312
+ {
313
+ type : 'modifier' ,
314
+ name : 'on' ,
315
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
316
+ instance : ( instance : any ) => typeof instance === 'object' ,
317
+ template : null ,
318
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
319
+ children : [ ] ,
320
+ } ,
321
+ {
322
+ type : 'modifier' ,
323
+ name : 'DidInsertModifier' ,
324
+ args : { positional : [ didInsert ] , named : { } } ,
325
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
326
+ template : null ,
327
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
328
+ children : [ ] ,
329
+ } ,
330
+ {
331
+ type : 'modifier' ,
332
+ name : 'did-insert' ,
333
+ args : { positional : [ didInsert ] , named : { } } ,
334
+ instance : ( instance : any ) => typeof instance . install === 'function' ,
335
+ template : null ,
336
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
337
+ children : [ ] ,
338
+ } ,
339
+ {
340
+ type : 'component' ,
341
+ name : 'HelloWorld' ,
342
+ args : { positional : [ ] , named : { } } ,
343
+ instance : ( instance : any ) => instance !== undefined ,
344
+ template : '(unknown template module)' ,
345
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
346
+ children : [ ] ,
347
+ } ,
348
+ ] ) ;
349
+
350
+ this . rerender ( {
351
+ more : true ,
352
+ } ) ;
353
+
354
+ this . assertRenderTree ( [
355
+ {
356
+ type : 'modifier' ,
357
+ name : 'on' ,
358
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
359
+ instance : ( instance : any ) => typeof instance === 'object' ,
360
+ template : null ,
361
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
362
+ children : [ ] ,
363
+ } ,
364
+ {
365
+ type : 'modifier' ,
366
+ name : 'did-update' ,
367
+ args : { positional : [ didInsert ] , named : { } } ,
368
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
369
+ template : null ,
370
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
371
+ children : [ ] ,
372
+ } ,
373
+ {
374
+ type : 'modifier' ,
375
+ name : 'DidInsertModifier' ,
376
+ args : { positional : [ didInsert ] , named : { } } ,
377
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
378
+ template : null ,
379
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
380
+ children : [ ] ,
381
+ } ,
382
+ {
383
+ type : 'modifier' ,
384
+ name : 'did-insert' ,
385
+ args : { positional : [ didInsert ] , named : { } } ,
386
+ instance : ( instance : any ) => typeof instance . install === 'function' ,
387
+ template : null ,
388
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
389
+ children : [ ] ,
390
+ } ,
391
+ {
392
+ type : 'component' ,
393
+ name : 'HelloWorld' ,
394
+ args : { positional : [ ] , named : { } } ,
395
+ instance : ( instance : any ) => instance !== undefined ,
396
+ template : '(unknown template module)' ,
397
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
398
+ children : [ ] ,
399
+ } ,
400
+ {
401
+ type : 'modifier' ,
402
+ name : 'on' ,
403
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
404
+ instance : ( instance : any ) => typeof instance === 'object' ,
405
+ template : null ,
406
+ bounds : this . nodeBounds ( this . element . firstChild ! . lastChild ) ,
407
+ children : [ ] ,
408
+ } ,
409
+ ] ) ;
410
+
411
+ this . rerender ( {
412
+ more : false ,
413
+ } ) ;
414
+
415
+ this . assertRenderTree ( [
416
+ {
417
+ type : 'modifier' ,
418
+ name : 'did-update' ,
419
+ args : { positional : [ didInsert ] , named : { } } ,
420
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
421
+ template : null ,
422
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
423
+ children : [ ] ,
424
+ } ,
425
+ {
426
+ type : 'modifier' ,
427
+ name : 'on' ,
428
+ args : { positional : [ 'click' , didInsert ] , named : { } } ,
429
+ instance : ( instance : any ) => typeof instance === 'object' ,
430
+ template : null ,
431
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
432
+ children : [ ] ,
433
+ } ,
434
+ {
435
+ type : 'modifier' ,
436
+ name : 'DidInsertModifier' ,
437
+ args : { positional : [ didInsert ] , named : { } } ,
438
+ instance : ( instance : any ) => typeof instance . installModifier === 'function' ,
439
+ template : null ,
440
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
441
+ children : [ ] ,
442
+ } ,
443
+ {
444
+ type : 'modifier' ,
445
+ name : 'did-insert' ,
446
+ args : { positional : [ didInsert ] , named : { } } ,
447
+ instance : ( instance : any ) => typeof instance . install === 'function' ,
448
+ template : null ,
449
+ bounds : this . nodeBounds ( this . element . firstChild ) ,
450
+ children : [ ] ,
451
+ } ,
452
+ {
453
+ type : 'component' ,
454
+ name : 'HelloWorld' ,
455
+ args : { positional : [ ] , named : { } } ,
456
+ instance : ( instance : any ) => instance !== undefined ,
457
+ template : '(unknown template module)' ,
458
+ bounds : this . nodeBounds ( this . element . firstChild ! . firstChild ) ,
459
+ children : [ ] ,
460
+ } ,
461
+ ] ) ;
462
+ }
463
+
256
464
@test 'getDebugCustomRenderTree works' ( ) {
257
465
let bucket1 = { } ;
258
466
let instance1 = { } ;
@@ -502,7 +710,7 @@ class DebugRenderTreeTest extends RenderTest {
502
710
this . assertRenderNode ( actualNode , expected , `${ actualNode . type } :${ actualNode . name } ` ) ;
503
711
} ) ;
504
712
} else {
505
- this . assert . deepEqual ( actual , [ ] , path ) ;
713
+ this . assert . deepEqual ( actual , expectedNodes , path ) ;
506
714
}
507
715
}
508
716
0 commit comments