diff options
| author | Igor Minar | 2012-03-12 15:54:48 -0700 |
|---|---|---|
| committer | Igor Minar | 2012-03-12 23:04:11 -0700 |
| commit | 5e6ba2520174218d26defbe9488a1073da882072 (patch) | |
| tree | 3dd5af2029420e9c647056c24001249cd35da175 /test/directive/formSpec.js | |
| parent | 9134f5ce5a402bb76ba9bc5627ade282552898fe (diff) | |
| download | angular.js-5e6ba2520174218d26defbe9488a1073da882072.tar.bz2 | |
fix(forms): remove the need for extra form scope
the forms/controls code refactored not to depend on events which forced
us to create new scope for each form element.
Diffstat (limited to 'test/directive/formSpec.js')
| -rw-r--r-- | test/directive/formSpec.js | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/test/directive/formSpec.js b/test/directive/formSpec.js index 45af04a4..c5e305d3 100644 --- a/test/directive/formSpec.js +++ b/test/directive/formSpec.js @@ -26,8 +26,8 @@ describe('form', function() { it('should instantiate form and attach it to DOM', function() { doc = $compile('<form>')(scope); - expect(doc.data('$form')).toBeTruthy(); - expect(doc.data('$form') instanceof FormController).toBe(true); + expect(doc.data('$formController')).toBeTruthy(); + expect(doc.data('$formController') instanceof FormController).toBe(true); }); @@ -78,15 +78,15 @@ describe('form', function() { }); - it('should publish form to scope', function() { + it('should publish form to scope when name attr is defined', function() { doc = $compile('<form name="myForm"></form>')(scope); expect(scope.myForm).toBeTruthy(); - expect(doc.data('$form')).toBeTruthy(); - expect(doc.data('$form')).toEqual(scope.myForm); + expect(doc.data('$formController')).toBeTruthy(); + expect(doc.data('$formController')).toEqual(scope.myForm); }); - it('should allow name to be an expression', function() { + it('should allow form name to be an expression', function() { doc = $compile('<form name="obj.myForm"></form>')(scope); expect(scope.obj).toBeDefined(); @@ -108,7 +108,7 @@ describe('form', function() { var input = child.text; input.setValidity('MyError', false); - expect(parent.error.MyError).toEqual([input]); + expect(parent.error.MyError).toEqual([child]); expect(child.error.MyError).toEqual([input]); input.setValidity('MyError', true); @@ -117,6 +117,41 @@ describe('form', function() { }); + it('should support two forms on a single scope', function() { + doc = $compile( + '<div>' + + '<form name="formA">' + + '<input name="firstName" ng-model="firstName" required>' + + '</form>' + + '<form name="formB">' + + '<input name="lastName" ng-model="lastName" required>' + + '</form>' + + '</div>' + )(scope); + + 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]); + + var inputA = doc.find('input').eq(0), + inputB = doc.find('input').eq(1); + + inputA.val('val1'); + browserTrigger(inputA, 'blur'); + inputB.val('val2'); + browserTrigger(inputB, 'blur'); + + expect(scope.firstName).toBe('val1'); + expect(scope.lastName).toBe('val2'); + + expect(scope.formA.error.REQUIRED).toBeUndefined(); + expect(scope.formB.error.REQUIRED).toBeUndefined(); + }); + + it('should chain nested forms in repeater', function() { doc = jqLite( '<ng:form name=parent>' + @@ -141,7 +176,7 @@ describe('form', function() { input.setValidity('myRule', false); expect(input.error.myRule).toEqual(true); expect(child.error.myRule).toEqual([input]); - expect(parent.error.myRule).toEqual([input]); + expect(parent.error.myRule).toEqual([child]); input.setValidity('myRule', true); expect(parent.error.myRule).toBeUndefined(); |
