From 4f78fd692c0ec51241476e6be9a4df06cd62fdd6 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 8 Sep 2011 13:56:29 -0700 Subject: feat(forms): new and improved forms --- test/AngularSpec.js | 39 +- test/ApiSpecs.js | 7 + test/BinderSpec.js | 135 +----- test/BrowserSpecs.js | 10 - test/FormattersSpec.js | 45 -- test/JsonSpec.js | 4 + test/ParserSpec.js | 19 - test/ScopeSpec.js | 19 +- test/ValidatorsSpec.js | 172 -------- test/directivesSpec.js | 11 + test/jQueryPatchSpec.js | 57 +++ test/jqLiteSpec.js | 32 +- test/markupSpec.js | 20 +- test/scenario/dslSpec.js | 63 +-- test/scenario/e2e/widgets.html | 18 +- test/service/formFactorySpec.js | 218 ++++++++++ test/service/invalidWidgetsSpec.js | 41 -- test/service/routeSpec.js | 20 +- test/testabilityPatch.js | 70 +++- test/widget/formSpec.js | 97 +++++ test/widget/inputSpec.js | 547 +++++++++++++++++++++++++ test/widget/selectSpec.js | 510 +++++++++++++++++++++++ test/widgetsSpec.js | 820 +------------------------------------ 23 files changed, 1645 insertions(+), 1329 deletions(-) delete mode 100644 test/FormattersSpec.js delete mode 100644 test/ValidatorsSpec.js create mode 100644 test/jQueryPatchSpec.js create mode 100644 test/service/formFactorySpec.js delete mode 100644 test/service/invalidWidgetsSpec.js create mode 100644 test/widget/formSpec.js create mode 100644 test/widget/inputSpec.js create mode 100644 test/widget/selectSpec.js (limited to 'test') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 9a1a20c7..0332c01b 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -112,7 +112,6 @@ describe('angular', function(){ }); }); - describe('size', function() { it('should return the number of items in an array', function() { expect(size([])).toBe(0); @@ -170,6 +169,12 @@ describe('angular', function(){ }); }); + describe('sortedKeys', function(){ + it('should collect keys from object', function(){ + expect(sortedKeys({c:0, b:0, a:0})).toEqual(['a', 'b', 'c']); + }); + }); + describe('encodeUriSegment', function() { it('should correctly encode uri segment and not encode chars defined as pchar set in rfc3986', @@ -322,9 +327,7 @@ describe('angular', function(){ } }; - expect(angularJsConfig(doc)).toEqual({base_url: '', - ie_compat: 'angular-ie-compat.js', - ie_compat_id: 'ng-ie-compat'}); + expect(angularJsConfig(doc)).toEqual({base_url: ''}); }); @@ -335,16 +338,12 @@ describe('angular', function(){ return [{nodeName: 'SCRIPT', src: 'angularjs/angular.js', attributes: [{name: 'ng:autobind', value:'elementIdToCompile'}, - {name: 'ng:css', value: 'css/my_custom_angular.css'}, - {name: 'ng:ie-compat', value: 'myjs/angular-ie-compat.js'}, - {name: 'ng:ie-compat-id', value: 'ngcompat'}] }]; + {name: 'ng:css', value: 'css/my_custom_angular.css'}] }]; }}; expect(angularJsConfig(doc)).toEqual({base_url: 'angularjs/', autobind: 'elementIdToCompile', - css: 'css/my_custom_angular.css', - ie_compat: 'myjs/angular-ie-compat.js', - ie_compat_id: 'ngcompat'}); + css: 'css/my_custom_angular.css'}); }); @@ -357,9 +356,7 @@ describe('angular', function(){ }}; expect(angularJsConfig(doc)).toEqual({autobind: true, - base_url: 'angularjs/', - ie_compat_id: 'ng-ie-compat', - ie_compat: 'angularjs/angular-ie-compat.js'}); + base_url: 'angularjs/'}); }); @@ -371,9 +368,7 @@ describe('angular', function(){ }}; expect(angularJsConfig(doc)).toEqual({base_url: 'angularjs/', - autobind: true, - ie_compat: 'angularjs/angular-ie-compat.js', - ie_compat_id: 'ng-ie-compat'}); + autobind: true}); }); @@ -385,9 +380,7 @@ describe('angular', function(){ }}; expect(angularJsConfig(doc)).toEqual({base_url: 'angularjs/', - autobind: 'foo', - ie_compat: 'angularjs/angular-ie-compat.js', - ie_compat_id: 'ng-ie-compat'}); + autobind: 'foo'}); }); @@ -398,9 +391,7 @@ describe('angular', function(){ src: 'js/angular-0.9.0.js'}]; }}; - expect(angularJsConfig(doc)).toEqual({base_url: 'js/', - ie_compat: 'js/angular-ie-compat-0.9.0.js', - ie_compat_id: 'ng-ie-compat'}); + expect(angularJsConfig(doc)).toEqual({base_url: 'js/'}); }); @@ -411,9 +402,7 @@ describe('angular', function(){ src: 'js/angular-0.9.0-cba23f00.min.js'}]; }}; - expect(angularJsConfig(doc)).toEqual({base_url: 'js/', - ie_compat: 'js/angular-ie-compat-0.9.0-cba23f00.js', - ie_compat_id: 'ng-ie-compat'}); + expect(angularJsConfig(doc)).toEqual({base_url: 'js/'}); }); }); diff --git a/test/ApiSpecs.js b/test/ApiSpecs.js index 9683a7b7..bd77d734 100644 --- a/test/ApiSpecs.js +++ b/test/ApiSpecs.js @@ -15,6 +15,13 @@ describe('api', function() { expect(map.remove(key)).toBe(value2); expect(map.get(key)).toBe(undefined); }); + + it('should init from an array', function(){ + var map = new HashMap(['a','b']); + expect(map.get('a')).toBe(0); + expect(map.get('b')).toBe(1); + expect(map.get('c')).toBe(undefined); + }); }); diff --git a/test/BinderSpec.js b/test/BinderSpec.js index 224c449f..fa7fde60 100644 --- a/test/BinderSpec.js +++ b/test/BinderSpec.js @@ -28,56 +28,12 @@ describe('Binder', function(){ } }); - - it('text-field should default to value attribute', function(){ - var scope = this.compile(''); - scope.$apply(); - assertEquals('abc', scope.model.price); - }); - - it('ChangingTextareaUpdatesModel', function(){ - var scope = this.compile(''); - scope.$apply(); - assertEquals(scope.model.note, 'abc'); - }); - - it('ChangingRadioUpdatesModel', function(){ - var scope = this.compile('
Hello {{name}}!');
scope.name = "World";
@@ -459,7 +405,11 @@ describe('Binder', function(){
it('FillInOptionValueWhenMissing', function(){
var scope = this.compile(
- '');
+ '');
scope.a = 'A';
scope.b = 'B';
scope.$apply();
@@ -477,52 +427,14 @@ describe('Binder', function(){
expect(optionC.text()).toEqual('C');
});
- it('ValidateForm', function(){
- var scope = this.compile('{{ {key:"value", $$key:"hide"} }}');
+ scope.$digest();
+ expect(fromJson(scope.$element.text())).toEqual({key:'value'});
+ });
+
});
describe('ng:bind-attr', function() {
diff --git a/test/jQueryPatchSpec.js b/test/jQueryPatchSpec.js
new file mode 100644
index 00000000..0953bdac
--- /dev/null
+++ b/test/jQueryPatchSpec.js
@@ -0,0 +1,57 @@
+'use strict';
+
+if (window.jQuery) {
+
+ describe('jQuery patch', function(){
+
+ var doc = null;
+ var divSpy = null;
+ var spy1 = null;
+ var spy2 = null;
+
+ beforeEach(function(){
+ divSpy = jasmine.createSpy('div.$destroy');
+ spy1 = jasmine.createSpy('span1.$destroy');
+ spy2 = jasmine.createSpy('span2.$destroy');
+ doc = $('