@@ -14,7 +14,9 @@ describe('MatExpansionPanel', () => {
1414 ] ,
1515 declarations : [
1616 PanelWithContent ,
17- PanelWithCustomMargin
17+ PanelWithCustomMargin ,
18+ LazyPanelWithContent ,
19+ LazyPanelOpenOnLoad ,
1820 ] ,
1921 } ) ;
2022 TestBed . compileComponents ( ) ;
@@ -34,6 +36,29 @@ describe('MatExpansionPanel', () => {
3436 expect ( contentEl . classes [ 'mat-expanded' ] ) . toBeTruthy ( ) ;
3537 } ) ;
3638
39+ it ( 'should be able to render panel content lazily' , fakeAsync ( ( ) => {
40+ let fixture = TestBed . createComponent ( LazyPanelWithContent ) ;
41+ let content = fixture . debugElement . query ( By . css ( '.mat-expansion-panel-content' ) ) . nativeElement ;
42+ fixture . detectChanges ( ) ;
43+
44+ expect ( content . textContent . trim ( ) ) . toBe ( '' , 'Expected content element to be empty.' ) ;
45+
46+ fixture . componentInstance . expanded = true ;
47+ fixture . detectChanges ( ) ;
48+
49+ expect ( content . textContent . trim ( ) )
50+ . toContain ( 'Some content' , 'Expected content to be rendered.' ) ;
51+ } ) ) ;
52+
53+ it ( 'should render the content for a lazy-loaded panel that is opened on init' , fakeAsync ( ( ) => {
54+ let fixture = TestBed . createComponent ( LazyPanelOpenOnLoad ) ;
55+ let content = fixture . debugElement . query ( By . css ( '.mat-expansion-panel-content' ) ) . nativeElement ;
56+ fixture . detectChanges ( ) ;
57+
58+ expect ( content . textContent . trim ( ) )
59+ . toContain ( 'Some content' , 'Expected content to be rendered.' ) ;
60+ } ) ) ;
61+
3762 it ( 'emit correct events for change in panel expanded state' , ( ) => {
3863 const fixture = TestBed . createComponent ( PanelWithContent ) ;
3964 fixture . componentInstance . expanded = true ;
@@ -60,12 +85,13 @@ describe('MatExpansionPanel', () => {
6085
6186 it ( 'should not be able to focus content while closed' , fakeAsync ( ( ) => {
6287 const fixture = TestBed . createComponent ( PanelWithContent ) ;
63- const button = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
6488
6589 fixture . componentInstance . expanded = true ;
6690 fixture . detectChanges ( ) ;
6791 tick ( 250 ) ;
6892
93+ const button = fixture . debugElement . query ( By . css ( 'button' ) ) . nativeElement ;
94+
6995 button . focus ( ) ;
7096 expect ( document . activeElement ) . toBe ( button , 'Expected button to start off focusable.' ) ;
7197
@@ -237,3 +263,30 @@ class PanelWithContent {
237263class PanelWithCustomMargin {
238264 expanded : boolean = false ;
239265}
266+
267+ @Component ( {
268+ template : `
269+ <mat-expansion-panel [expanded]="expanded">
270+ <mat-expansion-panel-header>Panel Title</mat-expansion-panel-header>
271+
272+ <ng-template matExpansionPanelContent>
273+ <p>Some content</p>
274+ <button>I am a button</button>
275+ </ng-template>
276+ </mat-expansion-panel>`
277+ } )
278+ class LazyPanelWithContent {
279+ expanded = false ;
280+ }
281+
282+ @Component ( {
283+ template : `
284+ <mat-expansion-panel [expanded]="true">
285+ <mat-expansion-panel-header>Panel Title</mat-expansion-panel-header>
286+
287+ <ng-template matExpansionPanelContent>
288+ <p>Some content</p>
289+ </ng-template>
290+ </mat-expansion-panel>`
291+ } )
292+ class LazyPanelOpenOnLoad { }
0 commit comments