1+ import { dispatchFakeEvent } from '@angular/cdk/testing' ;
12import { Component , ViewChild } from '@angular/core' ;
3+ import { async , ComponentFixture , fakeAsync , flush , TestBed , tick } from '@angular/core/testing' ;
24import { FormsModule } from '@angular/forms' ;
3- import { ComponentFixture , TestBed , async , fakeAsync , flush , tick } from '@angular/core/testing' ;
45import { By } from '@angular/platform-browser' ;
5- import { MatInputModule } from './index' ;
6- import { MatTextareaAutosize } from './autosize' ;
7- import { MatStepperModule } from '@angular/material/stepper' ;
8- import { MatTabsModule } from '@angular/material/tabs' ;
96import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
10- import { dispatchFakeEvent } from '@angular/cdk/testing' ;
7+ import { CdkTextareaAutosize } from './autosize' ;
8+ import { InputModule } from './input-module' ;
119
1210
13- describe ( 'MatTextareaAutosize ' , ( ) => {
11+ describe ( 'CdkTextareaAutosize ' , ( ) => {
1412 let fixture : ComponentFixture < AutosizeTextAreaWithContent > ;
1513 let textarea : HTMLTextAreaElement ;
16- let autosize : MatTextareaAutosize ;
14+ let autosize : CdkTextareaAutosize ;
1715
1816 beforeEach ( async ( ( ) => {
1917 TestBed . configureTestingModule ( {
2018 imports : [
2119 FormsModule ,
22- MatInputModule ,
23- MatStepperModule ,
24- MatTabsModule ,
20+ InputModule ,
2521 NoopAnimationsModule ,
2622 ] ,
2723 declarations : [
28- AutosizeTextareaInAStep ,
29- AutosizeTextareaInATab ,
3024 AutosizeTextAreaWithContent ,
3125 AutosizeTextAreaWithValue ,
3226 AutosizeTextareaWithNgModel ,
33- AutosizeTextareaWithLongPlaceholder
3427 ] ,
3528 } ) ;
3629
@@ -43,7 +36,7 @@ describe('MatTextareaAutosize', () => {
4336
4437 textarea = fixture . nativeElement . querySelector ( 'textarea' ) ;
4538 autosize = fixture . debugElement . query (
46- By . directive ( MatTextareaAutosize ) ) . injector . get < MatTextareaAutosize > ( MatTextareaAutosize ) ;
39+ By . directive ( CdkTextareaAutosize ) ) . injector . get < CdkTextareaAutosize > ( CdkTextareaAutosize ) ;
4740 } ) ;
4841
4942 it ( 'should resize the textarea based on its content' , ( ) => {
@@ -116,7 +109,7 @@ describe('MatTextareaAutosize', () => {
116109 . toBeGreaterThan ( previousMaxHeight , 'Expected increased max-height with maxRows increase.' ) ;
117110 } ) ;
118111
119- it ( 'should export the matAutosize reference' , ( ) => {
112+ it ( 'should export the cdkAutosize reference' , ( ) => {
120113 expect ( fixture . componentInstance . autosize ) . toBeTruthy ( ) ;
121114 expect ( fixture . componentInstance . autosize . resizeToFitContent ) . toBeTruthy ( ) ;
122115 } ) ;
@@ -163,7 +156,7 @@ describe('MatTextareaAutosize', () => {
163156 // detection should be triggered after a multiline content is set.
164157 fixture = TestBed . createComponent ( AutosizeTextAreaWithContent ) ;
165158 textarea = fixture . nativeElement . querySelector ( 'textarea' ) ;
166- autosize = fixture . debugElement . query ( By . css ( 'textarea' ) ) . injector . get ( MatTextareaAutosize ) ;
159+ autosize = fixture . debugElement . query ( By . css ( 'textarea' ) ) . injector . get ( CdkTextareaAutosize ) ;
167160
168161 fixture . componentInstance . content = `
169162 Line
@@ -178,27 +171,6 @@ describe('MatTextareaAutosize', () => {
178171 . toBe ( textarea . scrollHeight , 'Expected textarea height to match its scrollHeight' ) ;
179172 } ) ;
180173
181- it ( 'should not calculate wrong content height due to long placeholders' , ( ) => {
182- const fixtureWithPlaceholder = TestBed . createComponent ( AutosizeTextareaWithLongPlaceholder ) ;
183- fixtureWithPlaceholder . detectChanges ( ) ;
184-
185- textarea = fixtureWithPlaceholder . nativeElement . querySelector ( 'textarea' ) ;
186- autosize = fixtureWithPlaceholder . debugElement . query (
187- By . directive ( MatTextareaAutosize ) ) . injector . get < MatTextareaAutosize > ( MatTextareaAutosize ) ;
188-
189- autosize . resizeToFitContent ( true ) ;
190-
191- const heightWithLongPlaceholder = textarea . clientHeight ;
192-
193- fixtureWithPlaceholder . componentInstance . placeholder = 'Short' ;
194- fixtureWithPlaceholder . detectChanges ( ) ;
195-
196- autosize . resizeToFitContent ( true ) ;
197-
198- expect ( textarea . clientHeight ) . toBe ( heightWithLongPlaceholder ,
199- 'Expected the textarea height to be the same with a long placeholder.' ) ;
200- } ) ;
201-
202174 it ( 'should resize when an associated form control value changes' , fakeAsync ( ( ) => {
203175 const fixtureWithForms = TestBed . createComponent ( AutosizeTextareaWithNgModel ) ;
204176 textarea = fixtureWithForms . nativeElement . querySelector ( 'textarea' ) ;
@@ -237,20 +209,6 @@ describe('MatTextareaAutosize', () => {
237209 . toBeGreaterThan ( previousHeight , 'Expected the textarea height to have increased.' ) ;
238210 } ) ) ;
239211
240- it ( 'should work in a tab' , ( ) => {
241- const fixtureWithForms = TestBed . createComponent ( AutosizeTextareaInATab ) ;
242- fixtureWithForms . detectChanges ( ) ;
243- textarea = fixtureWithForms . nativeElement . querySelector ( 'textarea' ) ;
244- expect ( textarea . getBoundingClientRect ( ) . height ) . toBeGreaterThan ( 1 ) ;
245- } ) ;
246-
247- it ( 'should work in a step' , ( ) => {
248- const fixtureWithForms = TestBed . createComponent ( AutosizeTextareaInAStep ) ;
249- fixtureWithForms . detectChanges ( ) ;
250- textarea = fixtureWithForms . nativeElement . querySelector ( 'textarea' ) ;
251- expect ( textarea . getBoundingClientRect ( ) . height ) . toBeGreaterThan ( 1 ) ;
252- } ) ;
253-
254212 it ( 'should trigger a resize when the window is resized' , fakeAsync ( ( ) => {
255213 spyOn ( autosize , 'resizeToFitContent' ) ;
256214
@@ -271,72 +229,31 @@ const textareaStyleReset = `
271229
272230@Component ( {
273231 template : `
274- <textarea matTextareaAutosize [matAutosizeMinRows ]="minRows" [matAutosizeMaxRows ]="maxRows"
275- #autosize="matTextareaAutosize ">
232+ <textarea cdkTextareaAutosize [cdkAutosizeMinRows ]="minRows" [cdkAutosizeMaxRows ]="maxRows"
233+ #autosize="cdkTextareaAutosize ">
276234 {{content}}
277235 </textarea>` ,
278236 styles : [ textareaStyleReset ] ,
279237} )
280238class AutosizeTextAreaWithContent {
281- @ViewChild ( 'autosize' ) autosize : MatTextareaAutosize ;
239+ @ViewChild ( 'autosize' ) autosize : CdkTextareaAutosize ;
282240 minRows : number | null = null ;
283241 maxRows : number | null = null ;
284242 content : string = '' ;
285243}
286244
287245@Component ( {
288- template : `<textarea matTextareaAutosize [value]="value"></textarea>` ,
246+ template : `<textarea cdkTextareaAutosize [value]="value"></textarea>` ,
289247 styles : [ textareaStyleReset ] ,
290248} )
291249class AutosizeTextAreaWithValue {
292250 value : string = '' ;
293251}
294252
295253@Component ( {
296- template : `<textarea matTextareaAutosize [(ngModel)]="model"></textarea>` ,
254+ template : `<textarea cdkTextareaAutosize [(ngModel)]="model"></textarea>` ,
297255 styles : [ textareaStyleReset ] ,
298256} )
299257class AutosizeTextareaWithNgModel {
300258 model = '' ;
301259}
302-
303- @Component ( {
304- template : `
305- <mat-form-field style="width: 100px">
306- <textarea matInput matTextareaAutosize [placeholder]="placeholder"></textarea>
307- </mat-form-field>` ,
308- styles : [ textareaStyleReset ] ,
309- } )
310- class AutosizeTextareaWithLongPlaceholder {
311- placeholder = 'Long Long Long Long Long Long Long Long Placeholder' ;
312- }
313-
314- @Component ( {
315- template : `
316- <mat-tab-group>
317- <mat-tab label="Tab 1">
318- <mat-form-field>
319- <textarea matInput matTextareaAutosize>
320- Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
321- </textarea>
322- </mat-form-field>
323- </mat-tab>
324- </mat-tab-group>
325- `
326- } )
327- class AutosizeTextareaInATab { }
328-
329- @Component ( {
330- template : `
331- <mat-horizontal-stepper>
332- <mat-step label="Step 1">
333- <mat-form-field>
334- <textarea matInput matTextareaAautosize>
335- Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
336- </textarea>
337- </mat-form-field>
338- </mat-step>
339- </mat-horizontal-stepper>
340- `
341- } )
342- class AutosizeTextareaInAStep { }
0 commit comments