@@ -15,7 +15,9 @@ describe('MatExpansionPanel', () => {
1515 declarations : [
1616 PanelWithContent ,
1717 PanelWithContentInNgIf ,
18- PanelWithCustomMargin
18+ PanelWithCustomMargin ,
19+ LazyPanelWithContent ,
20+ LazyPanelOpenOnLoad ,
1921 ] ,
2022 } ) ;
2123 TestBed . compileComponents ( ) ;
@@ -35,6 +37,29 @@ describe('MatExpansionPanel', () => {
3537 expect ( contentEl . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
3638 } ) ;
3739
40+ it ( 'should be able to render panel content lazily' , fakeAsync ( ( ) => {
41+ let fixture = TestBed . createComponent ( LazyPanelWithContent ) ;
42+ let content = fixture . debugElement . query ( By . css ( '.mat-expansion-panel-content' ) ) . nativeElement ;
43+ fixture . detectChanges ( ) ;
44+
45+ expect ( content . textContent . trim ( ) ) . toBe ( '' , 'Expected content element to be empty.' ) ;
46+
47+ fixture . componentInstance . expanded = true ;
48+ fixture . detectChanges ( ) ;
49+
50+ expect ( content . textContent . trim ( ) )
51+ . toContain ( 'Some content' , 'Expected content to be rendered.' ) ;
52+ } ) ) ;
53+
54+ it ( 'should render the content for a lazy-loaded panel that is opened on init' , fakeAsync ( ( ) => {
55+ let fixture = TestBed . createComponent ( LazyPanelOpenOnLoad ) ;
56+ let content = fixture . debugElement . query ( By . css ( '.mat-expansion-panel-content' ) ) . nativeElement ;
57+ fixture . detectChanges ( ) ;
58+
59+ expect ( content . textContent . trim ( ) )
60+ . toContain ( 'Some content' , 'Expected content to be rendered.' ) ;
61+ } ) ) ;
62+
3863 it ( 'emit correct events for change in panel expanded state' , ( ) => {
3964 const fixture = TestBed . createComponent ( PanelWithContent ) ;
4065 fixture . componentInstance . expanded = true ;
@@ -61,12 +86,13 @@ describe('MatExpansionPanel', () => {
6186
6287 it ( 'should not be able to focus content while closed' , fakeAsync ( ( ) => {
6388 const fixture = TestBed . createComponent ( PanelWithContent ) ;
64- const button = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
6589
6690 fixture . componentInstance . expanded = true ;
6791 fixture . detectChanges ( ) ;
6892 tick ( 250 ) ;
6993
94+ const button = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
95+
7096 button . focus ( ) ;
7197 expect ( document . activeElement ) . toBe ( button , 'Expected button to start off focusable.' ) ;
7298
@@ -260,3 +286,30 @@ class PanelWithContentInNgIf {
260286class PanelWithCustomMargin {
261287 expanded : boolean = false ;
262288}
289+
290+ @Component ( {
291+ template : `
292+ <mat-expansion-panel [expanded]="expanded">
293+ <mat-expansion-panel-header>Panel Title</mat-expansion-panel-header>
294+
295+ <ng-template matExpansionPanelContent>
296+ <p>Some content</p>
297+ <button>I am a button</button>
298+ </ng-template>
299+ </mat-expansion-panel>`
300+ } )
301+ class LazyPanelWithContent {
302+ expanded = false ;
303+ }
304+
305+ @Component ( {
306+ template : `
307+ <mat-expansion-panel [expanded]="true">
308+ <mat-expansion-panel-header>Panel Title</mat-expansion-panel-header>
309+
310+ <ng-template matExpansionPanelContent>
311+ <p>Some content</p>
312+ </ng-template>
313+ </mat-expansion-panel>`
314+ } )
315+ class LazyPanelOpenOnLoad { }
0 commit comments