diff options
| author | Igor Minar | 2012-03-12 21:12:15 -0700 | 
|---|---|---|
| committer | Igor Minar | 2012-03-12 23:04:11 -0700 | 
| commit | f59e4b11f11261c234a821db67088f0de88a2852 (patch) | |
| tree | 943bb9340139c053ab16255a184121cc6db9ee95 /test | |
| parent | 5e6ba2520174218d26defbe9488a1073da882072 (diff) | |
| download | angular.js-f59e4b11f11261c234a821db67088f0de88a2852.tar.bz2 | |
fix(forms): prefix all form and control properties with $
Diffstat (limited to 'test')
| -rw-r--r-- | test/directive/formSpec.js | 78 | ||||
| -rw-r--r-- | test/directive/inputSpec.js | 152 | ||||
| -rw-r--r-- | test/directive/selectSpec.js | 6 | 
3 files changed, 118 insertions, 118 deletions
diff --git a/test/directive/formSpec.js b/test/directive/formSpec.js index c5e305d3..b1859d44 100644 --- a/test/directive/formSpec.js +++ b/test/directive/formSpec.js @@ -1,14 +1,14 @@  'use strict';  describe('form', function() { -  var doc, widget, scope, $compile; +  var doc, control, scope, $compile;    beforeEach(module(function($compileProvider) {      $compileProvider.directive('storeModelCtrl', function() {        return {          require: 'ngModel',          link: function(scope, elm, attr, ctrl) { -          widget = ctrl; +          control = ctrl;          }        };      }); @@ -33,17 +33,17 @@ describe('form', function() {    it('should remove the widget when element removed', function() {      doc = $compile( -        '<form name="form">' + +        '<form name="myForm">' +            '<input type="text" name="alias" ng-model="value" store-model-ctrl/>' +          '</form>')(scope); -    var form = scope.form; -    widget.setValidity('REQUIRED', false); -    expect(form.alias).toBe(widget); -    expect(form.error.REQUIRED).toEqual([widget]); +    var form = scope.myForm; +    control.$setValidity('REQUIRED', false); +    expect(form.alias).toBe(control); +    expect(form.$error.REQUIRED).toEqual([control]);      doc.find('input').remove(); -    expect(form.error.REQUIRED).toBeUndefined(); +    expect(form.$error.REQUIRED).toBeUndefined();      expect(form.alias).toBeUndefined();    }); @@ -98,22 +98,22 @@ describe('form', function() {      doc = jqLite(          '<ng:form name="parent">' +            '<ng:form name="child">' + -            '<input type="text" ng:model="text" name="text">' + +            '<input ng:model="modelA" name="inputA">' +            '</ng:form>' +          '</ng:form>');      $compile(doc)(scope);      var parent = scope.parent;      var child = scope.child; -    var input = child.text; +    var input = child.inputA; -    input.setValidity('MyError', false); -    expect(parent.error.MyError).toEqual([child]); -    expect(child.error.MyError).toEqual([input]); +    input.$setValidity('MyError', false); +    expect(parent.$error.MyError).toEqual([child]); +    expect(child.$error.MyError).toEqual([input]); -    input.setValidity('MyError', true); -    expect(parent.error.MyError).toBeUndefined(); -    expect(child.error.MyError).toBeUndefined(); +    input.$setValidity('MyError', true); +    expect(parent.$error.MyError).toBeUndefined(); +    expect(child.$error.MyError).toBeUndefined();    }); @@ -131,10 +131,10 @@ describe('form', function() {      scope.$apply(); -    expect(scope.formA.error.REQUIRED.length).toBe(1); -    expect(scope.formA.error.REQUIRED).toEqual([scope.formA.firstName]); -    expect(scope.formB.error.REQUIRED.length).toBe(1); -    expect(scope.formB.error.REQUIRED).toEqual([scope.formB.lastName]); +    expect(scope.formA.$error.REQUIRED.length).toBe(1); +    expect(scope.formA.$error.REQUIRED).toEqual([scope.formA.firstName]); +    expect(scope.formB.$error.REQUIRED.length).toBe(1); +    expect(scope.formB.$error.REQUIRED).toEqual([scope.formB.lastName]);      var inputA = doc.find('input').eq(0),          inputB = doc.find('input').eq(1); @@ -147,8 +147,8 @@ describe('form', function() {      expect(scope.firstName).toBe('val1');      expect(scope.lastName).toBe('val2'); -    expect(scope.formA.error.REQUIRED).toBeUndefined(); -    expect(scope.formB.error.REQUIRED).toBeUndefined(); +    expect(scope.formA.$error.REQUIRED).toBeUndefined(); +    expect(scope.formB.$error.REQUIRED).toBeUndefined();    }); @@ -173,14 +173,14 @@ describe('form', function() {      expect(child).toBeDefined();      expect(input).toBeDefined(); -    input.setValidity('myRule', false); -    expect(input.error.myRule).toEqual(true); -    expect(child.error.myRule).toEqual([input]); -    expect(parent.error.myRule).toEqual([child]); +    input.$setValidity('myRule', false); +    expect(input.$error.myRule).toEqual(true); +    expect(child.$error.myRule).toEqual([input]); +    expect(parent.$error.myRule).toEqual([child]); -    input.setValidity('myRule', true); -    expect(parent.error.myRule).toBeUndefined(); -    expect(child.error.myRule).toBeUndefined(); +    input.$setValidity('myRule', true); +    expect(parent.$error.myRule).toBeUndefined(); +    expect(child.$error.myRule).toBeUndefined();    }); @@ -190,10 +190,10 @@ describe('form', function() {      var widget = scope.form.w1;      expect(widget).toBeDefined(); -    expect(widget.pristine).toBe(true); -    expect(widget.dirty).toBe(false); -    expect(widget.valid).toBe(true); -    expect(widget.invalid).toBe(false); +    expect(widget.$pristine).toBe(true); +    expect(widget.$dirty).toBe(false); +    expect(widget.$valid).toBe(true); +    expect(widget.$invalid).toBe(false);    }); @@ -202,7 +202,7 @@ describe('form', function() {      beforeEach(function() {        doc = $compile(            '<form name="form">' + -            '<input type="text" ng-model="name" name="name" store-model-ctrl/>' + +            '<input ng-model="name" name="name" store-model-ctrl/>' +            '</form>')(scope);        scope.$digest(); @@ -212,18 +212,18 @@ describe('form', function() {      it('should have ng-valid/ng-invalid css class', function() {        expect(doc).toBeValid(); -      widget.setValidity('ERROR', false); +      control.$setValidity('ERROR', false);        scope.$apply();        expect(doc).toBeInvalid(); -      widget.setValidity('ANOTHER', false); +      control.$setValidity('ANOTHER', false);        scope.$apply(); -      widget.setValidity('ERROR', true); +      control.$setValidity('ERROR', true);        scope.$apply();        expect(doc).toBeInvalid(); -      widget.setValidity('ANOTHER', true); +      control.$setValidity('ANOTHER', true);        scope.$apply();        expect(doc).toBeValid();      }); @@ -232,7 +232,7 @@ describe('form', function() {      it('should have ng-pristine/ng-dirty css class', function() {        expect(doc).toBePristine(); -      widget.setViewValue(''); +      control.$setViewValue('');        scope.$apply();        expect(doc).toBeDirty();      }); diff --git a/test/directive/inputSpec.js b/test/directive/inputSpec.js index 724b9fbe..108ef5c3 100644 --- a/test/directive/inputSpec.js +++ b/test/directive/inputSpec.js @@ -19,18 +19,18 @@ describe('NgModelController', function() {    it('should init the properties', function() { -    expect(ctrl.dirty).toBe(false); -    expect(ctrl.pristine).toBe(true); -    expect(ctrl.valid).toBe(true); -    expect(ctrl.invalid).toBe(false); +    expect(ctrl.$dirty).toBe(false); +    expect(ctrl.$pristine).toBe(true); +    expect(ctrl.$valid).toBe(true); +    expect(ctrl.$invalid).toBe(false); -    expect(ctrl.viewValue).toBeDefined(); -    expect(ctrl.modelValue).toBeDefined(); +    expect(ctrl.$viewValue).toBeDefined(); +    expect(ctrl.$modelValue).toBeDefined(); -    expect(ctrl.formatters).toEqual([]); -    expect(ctrl.parsers).toEqual([]); +    expect(ctrl.$formatters).toEqual([]); +    expect(ctrl.$parsers).toEqual([]); -    expect(ctrl.name).toBe('testAlias'); +    expect(ctrl.$name).toBe('testAlias');    }); @@ -40,40 +40,40 @@ describe('NgModelController', function() {        var spy = jasmine.createSpy('setValidity');        ctrl.$form = {$setValidity: spy}; -      ctrl.setValidity('ERROR', false); +      ctrl.$setValidity('ERROR', false);        expect(spy).toHaveBeenCalledOnceWith('ERROR', false, ctrl);        spy.reset(); -      ctrl.setValidity('ERROR', false); +      ctrl.$setValidity('ERROR', false);        expect(spy).not.toHaveBeenCalled();      });      it('should set and unset the error', function() { -      ctrl.setValidity('REQUIRED', false); -      expect(ctrl.error.REQUIRED).toBe(true); +      ctrl.$setValidity('REQUIRED', false); +      expect(ctrl.$error.REQUIRED).toBe(true); -      ctrl.setValidity('REQUIRED', true); -      expect(ctrl.error.REQUIRED).toBeUndefined(); +      ctrl.$setValidity('REQUIRED', true); +      expect(ctrl.$error.REQUIRED).toBeUndefined();      });      it('should set valid/invalid', function() { -      ctrl.setValidity('FIRST', false); -      expect(ctrl.valid).toBe(false); -      expect(ctrl.invalid).toBe(true); +      ctrl.$setValidity('FIRST', false); +      expect(ctrl.$valid).toBe(false); +      expect(ctrl.$invalid).toBe(true); -      ctrl.setValidity('SECOND', false); -      expect(ctrl.valid).toBe(false); -      expect(ctrl.invalid).toBe(true); +      ctrl.$setValidity('SECOND', false); +      expect(ctrl.$valid).toBe(false); +      expect(ctrl.$invalid).toBe(true); -      ctrl.setValidity('SECOND', true); -      expect(ctrl.valid).toBe(false); -      expect(ctrl.invalid).toBe(true); +      ctrl.$setValidity('SECOND', true); +      expect(ctrl.$valid).toBe(false); +      expect(ctrl.$invalid).toBe(true); -      ctrl.setValidity('FIRST', true); -      expect(ctrl.valid).toBe(true); -      expect(ctrl.invalid).toBe(false); +      ctrl.$setValidity('FIRST', true); +      expect(ctrl.$valid).toBe(true); +      expect(ctrl.$invalid).toBe(false);      }); @@ -81,13 +81,13 @@ describe('NgModelController', function() {        var spy = jasmine.createSpy('setValidity');        ctrl.$form = {$setValidity: spy}; -      ctrl.setValidity('ERROR', true); +      ctrl.$setValidity('ERROR', true);        expect(spy).not.toHaveBeenCalled(); -      ctrl.setValidity('ERROR', false); +      ctrl.$setValidity('ERROR', false);        expect(spy).toHaveBeenCalledOnceWith('ERROR', false, ctrl);        spy.reset(); -      ctrl.setValidity('ERROR', true); +      ctrl.$setValidity('ERROR', true);        expect(spy).toHaveBeenCalledOnceWith('ERROR', true, ctrl);      });    }); @@ -96,54 +96,54 @@ describe('NgModelController', function() {    describe('view -> model', function() {      it('should set the value to $viewValue', function() { -      ctrl.setViewValue('some-val'); -      expect(ctrl.viewValue).toBe('some-val'); +      ctrl.$setViewValue('some-val'); +      expect(ctrl.$viewValue).toBe('some-val');      });      it('should pipeline all registered parsers and set result to $modelValue', function() {        var log = []; -      ctrl.parsers.push(function(value) { +      ctrl.$parsers.push(function(value) {          log.push(value);          return value + '-a';        }); -      ctrl.parsers.push(function(value) { +      ctrl.$parsers.push(function(value) {          log.push(value);          return value + '-b';        }); -      ctrl.setViewValue('init'); +      ctrl.$setViewValue('init');        expect(log).toEqual(['init', 'init-a']); -      expect(ctrl.modelValue).toBe('init-a-b'); +      expect(ctrl.$modelValue).toBe('init-a-b');      });      it('should fire viewChangeListeners when the value changes in the view (even if invalid)',          function() {        var spy = jasmine.createSpy('viewChangeListener'); -      ctrl.viewChangeListeners.push(spy); -      ctrl.setViewValue('val'); +      ctrl.$viewChangeListeners.push(spy); +      ctrl.$setViewValue('val');        expect(spy).toHaveBeenCalledOnce();        spy.reset();        // invalid -      ctrl.parsers.push(function() {return undefined;}); -      ctrl.setViewValue('val'); +      ctrl.$parsers.push(function() {return undefined;}); +      ctrl.$setViewValue('val');        expect(spy).toHaveBeenCalledOnce();      });      it('should reset the model when the view is invalid', function() { -      ctrl.setViewValue('aaaa'); -      expect(ctrl.modelValue).toBe('aaaa'); +      ctrl.$setViewValue('aaaa'); +      expect(ctrl.$modelValue).toBe('aaaa');        // add a validator that will make any input invalid -      ctrl.parsers.push(function() {return undefined;}); -      expect(ctrl.modelValue).toBe('aaaa'); -      ctrl.setViewValue('bbbb'); -      expect(ctrl.modelValue).toBeUndefined; +      ctrl.$parsers.push(function() {return undefined;}); +      expect(ctrl.$modelValue).toBe('aaaa'); +      ctrl.$setViewValue('bbbb'); +      expect(ctrl.$modelValue).toBeUndefined;      }); @@ -151,15 +151,15 @@ describe('NgModelController', function() {        var spy = jasmine.createSpy('setDirty');        ctrl.$form = {$setDirty: spy}; -      ctrl.setViewValue(''); -      expect(ctrl.pristine).toBe(false); -      expect(ctrl.dirty).toBe(true); +      ctrl.$setViewValue(''); +      expect(ctrl.$pristine).toBe(false); +      expect(ctrl.$dirty).toBe(true);        expect(spy).toHaveBeenCalledOnce();        spy.reset(); -      ctrl.setViewValue(''); -      expect(ctrl.pristine).toBe(false); -      expect(ctrl.dirty).toBe(true); +      ctrl.$setViewValue(''); +      expect(ctrl.$pristine).toBe(false); +      expect(ctrl.$dirty).toBe(true);        expect(spy).not.toHaveBeenCalled();      });    }); @@ -171,7 +171,7 @@ describe('NgModelController', function() {        scope.$apply(function() {          scope.value = 10;        }); -      expect(ctrl.modelValue).toBe(10); +      expect(ctrl.$modelValue).toBe(10);      }); @@ -179,12 +179,12 @@ describe('NgModelController', function() {          function() {        var log = []; -      ctrl.formatters.unshift(function(value) { +      ctrl.$formatters.unshift(function(value) {          log.push(value);          return value + 2;        }); -      ctrl.formatters.unshift(function(value) { +      ctrl.$formatters.unshift(function(value) {          log.push(value);          return value + '';        }); @@ -193,35 +193,35 @@ describe('NgModelController', function() {          scope.value = 3;        });        expect(log).toEqual([3, 5]); -      expect(ctrl.viewValue).toBe('5'); +      expect(ctrl.$viewValue).toBe('5');      });      it('should $render only if value changed', function() { -      spyOn(ctrl, 'render'); +      spyOn(ctrl, '$render');        scope.$apply(function() {          scope.value = 3;        }); -      expect(ctrl.render).toHaveBeenCalledOnce(); -      ctrl.render.reset(); +      expect(ctrl.$render).toHaveBeenCalledOnce(); +      ctrl.$render.reset(); -      ctrl.formatters.push(function() {return 3;}); +      ctrl.$formatters.push(function() {return 3;});        scope.$apply(function() {          scope.value = 5;        }); -      expect(ctrl.render).not.toHaveBeenCalled(); +      expect(ctrl.$render).not.toHaveBeenCalled();      });      it('should clear the view even if invalid', function() { -      spyOn(ctrl, 'render'); +      spyOn(ctrl, '$render'); -      ctrl.formatters.push(function() {return undefined;}); +      ctrl.$formatters.push(function() {return undefined;});        scope.$apply(function() {          scope.value = 5;        }); -      expect(ctrl.render).toHaveBeenCalledOnce(); +      expect(ctrl.$render).toHaveBeenCalledOnce();      });    });  }); @@ -296,10 +296,10 @@ describe('input', function() {      compileInput('<input ng-model="name" name="alias" required>');      scope.$apply(); -    expect(scope.form.error.REQUIRED.length).toBe(1); +    expect(scope.form.$error.REQUIRED.length).toBe(1);      inputElm.remove(); -    expect(scope.form.error.REQUIRED).toBeUndefined(); +    expect(scope.form.$error.REQUIRED).toBeUndefined();    }); @@ -535,12 +535,12 @@ describe('input', function() {          changeInputValueTo('1');          expect(inputElm).toBeInvalid();          expect(scope.value).toBeFalsy(); -        expect(scope.form.alias.error.MIN).toBeTruthy(); +        expect(scope.form.alias.$error.MIN).toBeTruthy();          changeInputValueTo('100');          expect(inputElm).toBeValid();          expect(scope.value).toBe(100); -        expect(scope.form.alias.error.MIN).toBeFalsy(); +        expect(scope.form.alias.$error.MIN).toBeFalsy();        });      }); @@ -554,12 +554,12 @@ describe('input', function() {          changeInputValueTo('20');          expect(inputElm).toBeInvalid();          expect(scope.value).toBeFalsy(); -        expect(scope.form.alias.error.MAX).toBeTruthy(); +        expect(scope.form.alias.$error.MAX).toBeTruthy();          changeInputValueTo('0');          expect(inputElm).toBeValid();          expect(scope.value).toBe(0); -        expect(scope.form.alias.error.MAX).toBeFalsy(); +        expect(scope.form.alias.$error.MAX).toBeFalsy();        });      }); @@ -572,7 +572,7 @@ describe('input', function() {          changeInputValueTo('0');          expect(inputElm).toBeValid();          expect(scope.value).toBe(0); -        expect(scope.form.alias.error.REQUIRED).toBeFalsy(); +        expect(scope.form.alias.$error.REQUIRED).toBeFalsy();        });        it('should be valid even if value 0 is set from model', function() { @@ -584,7 +584,7 @@ describe('input', function() {          expect(inputElm).toBeValid();          expect(inputElm.val()).toBe('0') -        expect(scope.form.alias.error.REQUIRED).toBeFalsy(); +        expect(scope.form.alias.$error.REQUIRED).toBeFalsy();        });      });    }); @@ -599,12 +599,12 @@ describe('input', function() {        expect(scope.email).toBe('vojta@google.com');        expect(inputElm).toBeValid(); -      expect(widget.error.EMAIL).toBeUndefined(); +      expect(widget.$error.EMAIL).toBeUndefined();        changeInputValueTo('invalid@');        expect(scope.email).toBeUndefined();        expect(inputElm).toBeInvalid(); -      expect(widget.error.EMAIL).toBeTruthy(); +      expect(widget.$error.EMAIL).toBeTruthy();      }); @@ -627,12 +627,12 @@ describe('input', function() {        changeInputValueTo('http://www.something.com');        expect(scope.url).toBe('http://www.something.com');        expect(inputElm).toBeValid(); -      expect(widget.error.URL).toBeUndefined(); +      expect(widget.$error.URL).toBeUndefined();        changeInputValueTo('invalid.com');        expect(scope.url).toBeUndefined();        expect(inputElm).toBeInvalid(); -      expect(widget.error.URL).toBeTruthy(); +      expect(widget.$error.URL).toBeTruthy();      }); diff --git a/test/directive/selectSpec.js b/test/directive/selectSpec.js index 3b4f992e..c6cfa377 100644 --- a/test/directive/selectSpec.js +++ b/test/directive/selectSpec.js @@ -55,7 +55,7 @@ describe('select', function() {          scope.selection = 'c';        }); -      expect(scope.form.select.error.REQUIRED).toBeFalsy(); +      expect(scope.form.select.$error.REQUIRED).toBeFalsy();        expect(element).toBeValid();        expect(element).toBePristine(); @@ -63,7 +63,7 @@ describe('select', function() {          scope.selection = '';        }); -      expect(scope.form.select.error.REQUIRED).toBeTruthy(); +      expect(scope.form.select.$error.REQUIRED).toBeTruthy();        expect(element).toBeInvalid();        expect(element).toBePristine();        expect(scope.log).toEqual(''); @@ -117,7 +117,7 @@ describe('select', function() {          scope.selection = [];        }); -      expect(scope.form.select.error.REQUIRED).toBeTruthy(); +      expect(scope.form.select.$error.REQUIRED).toBeTruthy();        expect(element).toBeInvalid();        expect(element).toBePristine();  | 
