@@ -200,6 +200,74 @@ describe('ng-model', () {
200
200
}));
201
201
});
202
202
203
+ describe ('no type attribute' , () {
204
+ it ('should be set "text" as default value for "type" attribute' , inject (() {
205
+ _.compile ('<input ng-model="model">' );
206
+ _.rootScope.$digest ();
207
+ expect ((_.rootElement as dom.InputElement ).attributes['type' ]).toEqual ('text' );
208
+ }));
209
+
210
+ it ('should update input value from model' , inject (() {
211
+ _.compile ('<input ng-model="model">' );
212
+ _.rootScope.$digest ();
213
+
214
+ expect ((_.rootElement as dom.InputElement ).value).toEqual ('' );
215
+
216
+ _.rootScope.$apply ('model = "misko"' );
217
+ expect ((_.rootElement as dom.InputElement ).value).toEqual ('misko' );
218
+ }));
219
+
220
+ it ('should render null as the empty string' , inject (() {
221
+ _.compile ('<input ng-model="model">' );
222
+ _.rootScope.$digest ();
223
+
224
+ expect ((_.rootElement as dom.InputElement ).value).toEqual ('' );
225
+
226
+ _.rootScope.$apply ('model = null' );
227
+ expect ((_.rootElement as dom.InputElement ).value).toEqual ('' );
228
+ }));
229
+
230
+ it ('should update model from the input value' , inject (() {
231
+ _.compile ('<input ng-model="model" probe="p">' );
232
+ Probe probe = _.rootScope.p;
233
+ var ngModel = probe.directive (NgModel );
234
+ InputElement inputElement = probe.element;
235
+
236
+ inputElement.value = 'abc' ;
237
+ _.triggerEvent (inputElement, 'change' );
238
+ expect (_.rootScope.model).toEqual ('abc' );
239
+
240
+ inputElement.value = 'def' ;
241
+ var input = probe.directive (InputTextLikeDirective );
242
+ input.processValue ();
243
+ expect (_.rootScope.model).toEqual ('def' );
244
+ }));
245
+
246
+ it ('should write to input only if value is different' , inject (() {
247
+ var scope = _.rootScope;
248
+ var element = new dom.InputElement ();
249
+ var model = new NgModel (scope, new NodeAttrs (new DivElement ()), element, new NgNullForm ());
250
+ dom.querySelector ('body' ).append (element);
251
+ var input = new InputTextLikeDirective (element, model, scope);
252
+
253
+ element.value = 'abc' ;
254
+ element.selectionStart = 1 ;
255
+ element.selectionEnd = 2 ;
256
+
257
+ model.render ('abc' );
258
+
259
+ expect (element.value).toEqual ('abc' );
260
+ expect (element.selectionStart).toEqual (1 );
261
+ expect (element.selectionEnd).toEqual (2 );
262
+
263
+ model.render ('xyz' );
264
+
265
+ expect (element.value).toEqual ('xyz' );
266
+ expect (element.selectionStart).toEqual (3 );
267
+ expect (element.selectionEnd).toEqual (3 );
268
+ }));
269
+ });
270
+
203
271
describe ('type="checkbox"' , () {
204
272
it ('should update input value from model' , inject ((Scope scope) {
205
273
var element = _.compile ('<input type="checkbox" ng-model="model">' );
0 commit comments