1
+ import { dispatchFakeEvent } from '@angular/cdk/testing' ;
1
2
import { Component , ViewChild } from '@angular/core' ;
3
+ import { async , ComponentFixture , fakeAsync , flush , TestBed , tick } from '@angular/core/testing' ;
2
4
import { FormsModule } from '@angular/forms' ;
3
- import { ComponentFixture , TestBed , async , fakeAsync , flush , tick } from '@angular/core/testing' ;
4
5
import { 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' ;
9
6
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
10
- import { dispatchFakeEvent } from '@angular/cdk/testing' ;
7
+ import { CdkTextareaAutosize } from './autosize' ;
8
+ import { InputModule } from './input-module' ;
11
9
12
10
13
- describe ( 'MatTextareaAutosize ' , ( ) => {
11
+ describe ( 'CdkTextareaAutosize ' , ( ) => {
14
12
let fixture : ComponentFixture < AutosizeTextAreaWithContent > ;
15
13
let textarea : HTMLTextAreaElement ;
16
- let autosize : MatTextareaAutosize ;
14
+ let autosize : CdkTextareaAutosize ;
17
15
18
16
beforeEach ( async ( ( ) => {
19
17
TestBed . configureTestingModule ( {
20
18
imports : [
21
19
FormsModule ,
22
- MatInputModule ,
23
- MatStepperModule ,
24
- MatTabsModule ,
20
+ InputModule ,
25
21
NoopAnimationsModule ,
26
22
] ,
27
23
declarations : [
28
- AutosizeTextareaInAStep ,
29
- AutosizeTextareaInATab ,
30
24
AutosizeTextAreaWithContent ,
31
25
AutosizeTextAreaWithValue ,
32
26
AutosizeTextareaWithNgModel ,
33
- AutosizeTextareaWithLongPlaceholder
34
27
] ,
35
28
} ) ;
36
29
@@ -43,7 +36,7 @@ describe('MatTextareaAutosize', () => {
43
36
44
37
textarea = fixture . nativeElement . querySelector ( 'textarea' ) ;
45
38
autosize = fixture . debugElement . query (
46
- By . directive ( MatTextareaAutosize ) ) . injector . get < MatTextareaAutosize > ( MatTextareaAutosize ) ;
39
+ By . directive ( CdkTextareaAutosize ) ) . injector . get < CdkTextareaAutosize > ( CdkTextareaAutosize ) ;
47
40
} ) ;
48
41
49
42
it ( 'should resize the textarea based on its content' , ( ) => {
@@ -116,7 +109,7 @@ describe('MatTextareaAutosize', () => {
116
109
. toBeGreaterThan ( previousMaxHeight , 'Expected increased max-height with maxRows increase.' ) ;
117
110
} ) ;
118
111
119
- it ( 'should export the matAutosize reference' , ( ) => {
112
+ it ( 'should export the cdkAutosize reference' , ( ) => {
120
113
expect ( fixture . componentInstance . autosize ) . toBeTruthy ( ) ;
121
114
expect ( fixture . componentInstance . autosize . resizeToFitContent ) . toBeTruthy ( ) ;
122
115
} ) ;
@@ -163,7 +156,7 @@ describe('MatTextareaAutosize', () => {
163
156
// detection should be triggered after a multiline content is set.
164
157
fixture = TestBed . createComponent ( AutosizeTextAreaWithContent ) ;
165
158
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 ) ;
167
160
168
161
fixture . componentInstance . content = `
169
162
Line
@@ -178,27 +171,6 @@ describe('MatTextareaAutosize', () => {
178
171
. toBe ( textarea . scrollHeight , 'Expected textarea height to match its scrollHeight' ) ;
179
172
} ) ;
180
173
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
-
202
174
it ( 'should resize when an associated form control value changes' , fakeAsync ( ( ) => {
203
175
const fixtureWithForms = TestBed . createComponent ( AutosizeTextareaWithNgModel ) ;
204
176
textarea = fixtureWithForms . nativeElement . querySelector ( 'textarea' ) ;
@@ -237,20 +209,6 @@ describe('MatTextareaAutosize', () => {
237
209
. toBeGreaterThan ( previousHeight , 'Expected the textarea height to have increased.' ) ;
238
210
} ) ) ;
239
211
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
-
254
212
it ( 'should trigger a resize when the window is resized' , fakeAsync ( ( ) => {
255
213
spyOn ( autosize , 'resizeToFitContent' ) ;
256
214
@@ -271,72 +229,31 @@ const textareaStyleReset = `
271
229
272
230
@Component ( {
273
231
template : `
274
- <textarea matTextareaAutosize [matAutosizeMinRows ]="minRows" [matAutosizeMaxRows ]="maxRows"
275
- #autosize="matTextareaAutosize ">
232
+ <textarea cdkTextareaAutosize [cdkAutosizeMinRows ]="minRows" [cdkAutosizeMaxRows ]="maxRows"
233
+ #autosize="cdkTextareaAutosize ">
276
234
{{content}}
277
235
</textarea>` ,
278
236
styles : [ textareaStyleReset ] ,
279
237
} )
280
238
class AutosizeTextAreaWithContent {
281
- @ViewChild ( 'autosize' ) autosize : MatTextareaAutosize ;
239
+ @ViewChild ( 'autosize' ) autosize : CdkTextareaAutosize ;
282
240
minRows : number | null = null ;
283
241
maxRows : number | null = null ;
284
242
content : string = '' ;
285
243
}
286
244
287
245
@Component ( {
288
- template : `<textarea matTextareaAutosize [value]="value"></textarea>` ,
246
+ template : `<textarea cdkTextareaAutosize [value]="value"></textarea>` ,
289
247
styles : [ textareaStyleReset ] ,
290
248
} )
291
249
class AutosizeTextAreaWithValue {
292
250
value : string = '' ;
293
251
}
294
252
295
253
@Component ( {
296
- template : `<textarea matTextareaAutosize [(ngModel)]="model"></textarea>` ,
254
+ template : `<textarea cdkTextareaAutosize [(ngModel)]="model"></textarea>` ,
297
255
styles : [ textareaStyleReset ] ,
298
256
} )
299
257
class AutosizeTextareaWithNgModel {
300
258
model = '' ;
301
259
}
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