aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMisko Hevery2010-03-25 13:01:08 -0700
committerMisko Hevery2010-03-25 13:01:08 -0700
commitb814c79b58deeeeaa12b03261399ef80c0d6cc9f (patch)
treebf28a86070d6c598161bdc9f8937fda51ec5049a /test
parentf29f6a47c4d81c5b8e365a3dae307159f1b12968 (diff)
downloadangular.js-b814c79b58deeeeaa12b03261399ef80c0d6cc9f.tar.bz2
checkbox and radio now working
Diffstat (limited to 'test')
-rw-r--r--test/ParserTest.js17
-rw-r--r--test/directivesSpec.js2
-rw-r--r--test/widgetsSpec.js60
3 files changed, 76 insertions, 3 deletions
diff --git a/test/ParserTest.js b/test/ParserTest.js
index c8d323f2..d3813812 100644
--- a/test/ParserTest.js
+++ b/test/ParserTest.js
@@ -52,6 +52,16 @@ LexerTest.prototype.testTokenizeAString = function(){
assertEquals(tokens[i].string, 'd"e');
};
+LexerTest.prototype.testTokenizeUndefined = function(){
+ var lexer = new Lexer("undefined");
+ var tokens = lexer.parse();
+ var i = 0;
+ assertEquals(tokens[i].index, 0);
+ assertEquals(tokens[i].text, 'undefined');
+ assertEquals(undefined, tokens[i].fn());
+};
+
+
LexerTest.prototype.testTokenizeRegExp = function(){
var lexer = new Lexer("/r 1/");
@@ -486,3 +496,10 @@ ParserTest.prototype.testParsingBug = function () {
var scope = new Scope();
assertEquals({a: "-"}, scope.eval("{a:'-'}"));
};
+
+ParserTest.prototype.testUndefined = function () {
+ var scope = new Scope();
+ assertEquals(undefined, scope.eval("undefined"));
+ assertEquals(undefined, scope.eval("a=undefined"));
+ assertEquals(undefined, scope.get("a"));
+};
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 18bedb64..83a270c1 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -12,7 +12,7 @@ describe("directives", function(){
};
});
- afterEach(function(){
+ afterEach(function() {
element.remove();
expect(_(jqCache).size()).toEqual(0);
});
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index aeb7a613..44a3d225 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -1,6 +1,6 @@
describe("input widget", function(){
- var compile, element, scope;
+ var compile, element, scope, model;
beforeEach(function() {
scope = null;
@@ -11,6 +11,7 @@ describe("input widget", function(){
var view = compiler.compile(element)(element);
view.init();
scope = view.scope;
+ model = scope.state;
};
});
@@ -20,8 +21,9 @@ describe("input widget", function(){
});
it('should input-text auto init and handle keyup/change events', function(){
- compile('<input type="Text" name="name" value="Misko"/>');
+ compile('<input type="Text" name="name" value="Misko" ng-action="count = count + 1" ng-init="count=0"/>');
expect(scope.get('name')).toEqual("Misko");
+ expect(scope.get('count')).toEqual(0);
scope.set('name', 'Adam');
scope.updateView();
@@ -30,10 +32,12 @@ describe("input widget", function(){
element.val('Shyam');
element.trigger('keyup');
expect(scope.get('name')).toEqual('Shyam');
+ expect(scope.get('count')).toEqual(1);
element.val('Kai');
element.trigger('change');
expect(scope.get('name')).toEqual('Kai');
+ expect(scope.get('count')).toEqual(2);
});
it("should process ng-format", function(){
@@ -98,5 +102,57 @@ describe("input widget", function(){
expect(scope.get('name')).toEqual('Kai');
});
+ it('should call ng-action on button click', function(){
+ compile('<input type="button" value="Click Me" ng-action="clicked = true"/>');
+ element.click();
+ expect(scope.get('clicked')).toEqual(true);
+ });
+
+ it('should type="checkbox"', function(){
+ compile('<input type="checkbox" name="checkbox" checked ng-action="action = true"/>');
+ expect(scope.get('checkbox')).toEqual(true);
+ element.click();
+ expect(scope.get('checkbox')).toEqual(false);
+ expect(scope.get('action')).toEqual(true);
+ element.click();
+ expect(scope.get('checkbox')).toEqual(true);
+ });
+
+ it('should type="radio"', function(){
+ compile('<div>' +
+ '<input type="radio" name="chose" value="A" ng-action="clicked = 1"/>' +
+ '<input type="radio" name="chose" value="B" checked ng-action="clicked = 2"/>' +
+ '</div>');
+ var a = element[0].childNodes[0];
+ var b = element[0].childNodes[1];
+ expect(model.chose).toEqual('B');
+ expect(model.clicked).not.toBeDefined();
+ model.chose = 'A';
+ model.$updateView();
+ expect(a.checked).toEqual(true);
+
+ model.chose = 'B';
+ model.$updateView();
+ expect(a.checked).toEqual(false);
+ expect(b.checked).toEqual(true);
+ expect(model.clicked).not.toBeDefined();
+
+ jqLite(a).click();
+ expect(model.chose).toEqual('A');
+ expect(model.clicked).toEqual(1);
+ });
+
+ it('should report error on missing field', function(){
+
+ });
+
+ it('should report error on assignment error', function(){
+
+ });
+
+ it('should report error on ng-action exception', function(){
+
+ });
+
});