From 84552f7f8ac3f39c4dbd7d946ae2938d63302840 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 13:58:04 -0700 Subject: got few directives working --- test/directivesSpec.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 test/directivesSpec.js (limited to 'test/directivesSpec.js') diff --git a/test/directivesSpec.js b/test/directivesSpec.js new file mode 100644 index 00000000..176f9e70 --- /dev/null +++ b/test/directivesSpec.js @@ -0,0 +1,71 @@ +describe("directives", function(){ + + var compile, element; + + beforeEach(function() { + var compiler = new Compiler(angularMarkup, angularDirective, angularWidget); + compile = function(html) { + element = jqLite(html); + var view = compiler.compile(element.element)(element.element); + view.init(); + return view.scope; + }; + }); + + it("should ng-init", function() { + var scope = compile('
'); + expect(scope.get('a')).toEqual(123); + }); + + it("should ng-eval", function() { + var scope = compile('
'); + expect(scope.get('a')).toEqual(0); + scope.updateView(); + expect(scope.get('a')).toEqual(1); + scope.updateView(); + expect(scope.get('a')).toEqual(2); + }); + + it('should ng-bind', function() { + var scope = compile('
'); + expect(element.text()).toEqual(''); + scope.set('a', 'misko'); + scope.updateView(); + expect(element.text()).toEqual('misko'); + }); + + it('should ng-bind-attr', function(){ + var scope = compile(''); + expect(element.attr('src')).toEqual(null); + expect(element.attr('alt')).toEqual(null); + scope.updateView(); + expect(element.attr('src')).toEqual('mysrc'); + expect(element.attr('alt')).toEqual('myalt'); + }); + + it('should ng-non-bindable', function(){ + var scope = compile('
'); + scope.set('name', 'misko'); + scope.updateView(); + expect(element.text()).toEqual(''); + }); + + it('should ng-repeat over array', function(){ + var scope = compile(''); + + scope.set('items', ['misko', 'shyam']); + scope.updateView(); + expect(element.text()).toEqual('misko;shyam;'); + + scope.set('items', ['adam', 'kai', 'brad']); + scope.updateView(); + expect(element.text()).toEqual('adam;kai;brad;'); + + scope.set('items', ['brad']); + scope.updateView(); + expect(element.text()).toEqual('brad;'); + }); + + it('should ng-repeat over object', function(){}); + it('should error on wrong parsing of ng-repeat', function(){}); +}); -- cgit v1.2.3 From b4561ff951ff452e55e820f6f8344dc2668cfd90 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 15:46:34 -0700 Subject: ng-repeat works --- test/directivesSpec.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test/directivesSpec.js') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 176f9e70..2cee20d1 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -66,6 +66,20 @@ describe("directives", function(){ expect(element.text()).toEqual('brad;'); }); - it('should ng-repeat over object', function(){}); - it('should error on wrong parsing of ng-repeat', function(){}); + it('should ng-repeat over object', function(){ + var scope = compile(''); + scope.set('items', {misko:'swe', shyam:'set'}); + scope.updateView(); + expect(element.text()).toEqual('misko:swe;shyam:set;'); + }); + + it('should error on wrong parsing of ng-repeat', function(){ + var scope = compile(''); + var log = ""; + element.eachNode(function(li){ + log += li.attr('ng-error') + ';'; + log += li.hasClass('ng-exception') + ';'; + }); + expect(log).toEqual("\"Expected ng-repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); + }); }); -- cgit v1.2.3 From 6f8276a8e3735396999bd158005ca86bb1bb0978 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 16:07:42 -0700 Subject: ng-watch directive --- test/directivesSpec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/directivesSpec.js') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 2cee20d1..e0e53eeb 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -82,4 +82,16 @@ describe("directives", function(){ }); expect(log).toEqual("\"Expected ng-repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); }); + + it('should ng-watch', function(){ + var scope = compile('
'); + scope.updateView(); + scope.updateView(); + expect(scope.get('count')).toEqual(0); + + scope.set('i', 0); + scope.updateView(); + scope.updateView(); + expect(scope.get('count')).toEqual(1); + }); }); -- cgit v1.2.3 From 7c87c17d08dbba318af1a149c0bbedb696b03458 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 18:20:49 -0700 Subject: upgraded jquery to 1.4.2 and made ng-action work with jquery --- test/directivesSpec.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/directivesSpec.js') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index e0e53eeb..447698a3 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -94,4 +94,13 @@ describe("directives", function(){ scope.updateView(); expect(scope.get('count')).toEqual(1); }); + + it('should ng-action', function(){ + var scope = compile('
'); + scope.updateView(); + expect(scope.get('clicked')).toBeFalsy(); + + jQuery(element.element).click(); + expect(scope.get('clicked')).toEqual(true); + }); }); -- cgit v1.2.3 From a8227086748e37c31c1bb71dec50c96d63c45eef Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 20:20:05 -0700 Subject: rudementary event bind and trigger for jqlite --- test/directivesSpec.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test/directivesSpec.js') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 447698a3..7e0446ef 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -12,6 +12,11 @@ describe("directives", function(){ }; }); + afterEach(function(){ + element.remove(); + expect(_(jqCache).size()).toEqual(0); + }); + it("should ng-init", function() { var scope = compile('
'); expect(scope.get('a')).toEqual(123); @@ -100,7 +105,7 @@ describe("directives", function(){ scope.updateView(); expect(scope.get('clicked')).toBeFalsy(); - jQuery(element.element).click(); + element.click(); expect(scope.get('clicked')).toEqual(true); }); }); -- cgit v1.2.3 From 6ff550cfa9524bbb124d10caf1fc13c911ab3b4b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 21:29:57 -0700 Subject: all angular.js directives now work --- test/directivesSpec.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'test/directivesSpec.js') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 7e0446ef..d125d326 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -6,7 +6,7 @@ describe("directives", function(){ var compiler = new Compiler(angularMarkup, angularDirective, angularWidget); compile = function(html) { element = jqLite(html); - var view = compiler.compile(element.element)(element.element); + var view = compiler.compile(element)(element); view.init(); return view.scope; }; @@ -108,4 +108,47 @@ describe("directives", function(){ element.click(); expect(scope.get('clicked')).toEqual(true); }); + + it('should ng-class', function(){ + var scope = compile('
'); + scope.updateView(); + expect(element.hasClass('existing')).toBeTruthy(); + expect(element.hasClass('A')).toBeTruthy(); + expect(element.hasClass('B')).toBeTruthy(); + }); + + it('should ng-class odd/even', function(){ + var scope = compile('