@@ -5,22 +5,22 @@ import {MdInputModule} from './input';
5
5
import { MdTextareaAutosize } from './autosize' ;
6
6
7
7
8
- describe ( 'MdTextareaAutosize' , ( ) => {
9
- let fixture : ComponentFixture < TextareaWithAutosize > ;
8
+ fdescribe ( 'MdTextareaAutosize' , ( ) => {
9
+ let fixture : ComponentFixture < AutosizeTextAreaWithContent > ;
10
10
let textarea : HTMLTextAreaElement ;
11
11
let autosize : MdTextareaAutosize ;
12
12
13
13
beforeEach ( async ( ( ) => {
14
14
TestBed . configureTestingModule ( {
15
15
imports : [ MdInputModule ] ,
16
- declarations : [ TextareaWithAutosize ] ,
16
+ declarations : [ AutosizeTextAreaWithContent , AutosizeTextAreaWithValue ] ,
17
17
} ) ;
18
18
19
19
TestBed . compileComponents ( ) ;
20
20
} ) ) ;
21
21
22
22
beforeEach ( ( ) => {
23
- fixture = TestBed . createComponent ( TextareaWithAutosize ) ;
23
+ fixture = TestBed . createComponent ( AutosizeTextAreaWithContent ) ;
24
24
fixture . detectChanges ( ) ;
25
25
26
26
textarea = fixture . nativeElement . querySelector ( 'textarea' ) ;
@@ -97,22 +97,83 @@ describe('MdTextareaAutosize', () => {
97
97
expect ( parseInt ( textarea . style . maxHeight ) )
98
98
. toBeGreaterThan ( previousMaxHeight , 'Expected increased max-height with maxRows increase.' ) ;
99
99
} ) ;
100
+
101
+ describe ( 'with value binding' , ( ) => {
102
+ let fixture : ComponentFixture < AutosizeTextAreaWithValue > ;
103
+
104
+ beforeEach ( ( ) => {
105
+ fixture = TestBed . createComponent ( AutosizeTextAreaWithValue ) ;
106
+ fixture . detectChanges ( ) ;
107
+
108
+ textarea = fixture . nativeElement . querySelector ( 'textarea' ) ;
109
+ autosize = fixture . debugElement . query (
110
+ By . directive ( MdTextareaAutosize ) ) . injector . get ( MdTextareaAutosize ) ;
111
+ } ) ;
112
+
113
+ it ( 'should resize the textarea when its value property changes' , ( ) => {
114
+ let previousHeight = textarea . offsetHeight ;
115
+
116
+ fixture . componentInstance . value = `
117
+ Once upon a midnight dreary, while I pondered, weak and weary,
118
+ Over many a quaint and curious volume of forgotten lore—
119
+ While I nodded, nearly napping, suddenly there came a tapping,
120
+ As of some one gently rapping, rapping at my chamber door.
121
+ “’Tis some visitor,” I muttered, “tapping at my chamber door—
122
+ Only this and nothing more.”` ;
123
+
124
+ // TODO(jelbourn): remove `resizeToFitContent` call here when we support resizing based
125
+ // on setting value directly.
126
+ fixture . detectChanges ( ) ;
127
+ autosize . resizeToFitContent ( ) ;
128
+
129
+ expect ( textarea . offsetHeight )
130
+ . toBeGreaterThan ( previousHeight , 'Expected textarea to have grown with added content.' ) ;
131
+ expect ( textarea . offsetHeight )
132
+ . toBe ( textarea . scrollHeight , 'Expected textarea height to match its scrollHeight' ) ;
133
+
134
+ previousHeight = textarea . offsetHeight ;
135
+ fixture . componentInstance . value += `
136
+ Ah, distinctly I remember it was in the bleak December;
137
+ And each separate dying ember wrought its ghost upon the floor.
138
+ Eagerly I wished the morrow;—vainly I had sought to borrow
139
+ From my books surcease of sorrow—sorrow for the lost Lenore—
140
+ For the rare and radiant maiden whom the angels name Lenore—
141
+ Nameless here for evermore.` ;
142
+
143
+ fixture . detectChanges ( ) ;
144
+ autosize . resizeToFitContent ( ) ;
145
+
146
+ expect ( textarea . offsetHeight )
147
+ . toBeGreaterThan ( previousHeight , 'Expected textarea to have grown with added content.' ) ;
148
+ expect ( textarea . offsetHeight )
149
+ . toBe ( textarea . scrollHeight , 'Expected textarea height to match its scrollHeight' ) ;
150
+ } ) ;
151
+ } ) ;
100
152
} ) ;
101
153
102
154
103
- @Component ( {
104
- template : `<textarea md-autosize [minRows]="minRows" [maxRows]="maxRows">{{content}}</textarea>` ,
105
- styles : [ `
106
- /** Reset padding and border to make measurement comparisons easier. */
155
+ // Styles to reset padding and border to make measurement comparisons easier.
156
+ const textareaStyleReset = `
107
157
textarea {
108
158
padding: 0;
109
159
border: none;
110
160
overflow: auto;
111
- }
112
- ` ]
161
+ }` ;
162
+
163
+ @Component ( {
164
+ template : `<textarea md-autosize [minRows]="minRows" [maxRows]="maxRows">{{content}}</textarea>` ,
165
+ styles : [ textareaStyleReset ] ,
113
166
} )
114
- class TextareaWithAutosize {
167
+ class AutosizeTextAreaWithContent {
115
168
minRows : number = null ;
116
169
maxRows : number = null ;
117
170
content : string = '' ;
118
171
}
172
+
173
+ @Component ( {
174
+ template : `<textarea md-autosize [value]="value"></textarea>` ,
175
+ styles : [ textareaStyleReset ] ,
176
+ } )
177
+ class AutosizeTextAreaWithValue {
178
+ value : string = '' ;
179
+ }
0 commit comments