aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMisko Hevery2010-03-24 16:13:42 -0700
committerMisko Hevery2010-03-24 16:13:42 -0700
commit0c42eb9909d554807549cd3394e0ea0c715cc2d1 (patch)
tree331c637a5c86b87970166a0936874fec9c6920a6 /test
parent3d3694240034b6841c9fdf2e38a2a7955cb592c7 (diff)
downloadangular.js-0c42eb9909d554807549cd3394e0ea0c715cc2d1.tar.bz2
input[type=text] now works with binding, validation, formatter, required
Diffstat (limited to 'test')
-rw-r--r--test/ValidatorsTest.js34
-rw-r--r--test/widgetsSpec.js68
2 files changed, 79 insertions, 23 deletions
diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js
index 5449ebb0..6b61c273 100644
--- a/test/ValidatorsTest.js
+++ b/test/ValidatorsTest.js
@@ -26,7 +26,7 @@ ValidatorTest.prototype.testRegexp = function() {
};
ValidatorTest.prototype.testNumber = function() {
- assertEquals(angular.validator.number("ab"), "Value is not a number.");
+ assertEquals(angular.validator.number("ab"), "Not a number");
assertEquals(angular.validator.number("-0.1",0), "Value can not be less than 0.");
assertEquals(angular.validator.number("10.1",0,10), "Value can not be greater than 10.");
assertEquals(angular.validator.number("1.2"), null);
@@ -34,10 +34,10 @@ ValidatorTest.prototype.testNumber = function() {
};
ValidatorTest.prototype.testInteger = function() {
- assertEquals(angular.validator.integer("ab"), "Value is not a number.");
- assertEquals(angular.validator.integer("1.1"), "Value is not a whole number.");
- assertEquals(angular.validator.integer("1.0"), "Value is not a whole number.");
- assertEquals(angular.validator.integer("1."), "Value is not a whole number.");
+ assertEquals(angular.validator.integer("ab"), "Not a number");
+ assertEquals(angular.validator.integer("1.1"), "Not a whole number");
+ assertEquals(angular.validator.integer("1.0"), "Not a whole number");
+ assertEquals(angular.validator.integer("1."), "Not a whole number");
assertEquals(angular.validator.integer("-1",0), "Value can not be less than 0.");
assertEquals(angular.validator.integer("11",0,10), "Value can not be greater than 10.");
assertEquals(angular.validator.integer("1"), null);
@@ -86,7 +86,7 @@ describe('Validator:asynchronous', function(){
var asynchronous = angular.validator.asynchronous;
var self;
var value, fn;
-
+
beforeEach(function(){
value = null;
fn = null;
@@ -96,10 +96,10 @@ describe('Validator:asynchronous', function(){
$updateView: noop
};
});
-
+
it('should make a request and show spinner', function(){
- var x = compile('<input name="name" ng-validate="asynchronous:asyncFn"/>')
- var asyncFn = function(v,f){value=v; fn=f};
+ var x = compile('<input name="name" ng-validate="asynchronous:asyncFn"/>');
+ var asyncFn = function(v,f){value=v; fn=f;};
var input = x.node.find(":input");
x.scope.set("asyncFn", asyncFn);
x.scope.set("name", "misko");
@@ -110,29 +110,29 @@ describe('Validator:asynchronous', function(){
expect(input.hasClass('ng-input-indicator-wait')).toBeFalsy();
expect(input.attr('ng-error')).toEqual("myError");
});
-
+
it("should not make second request to same value", function(){
asynchronous.call(self, "kai", function(v,f){value=v; fn=f;});
expect(value).toEqual('kai');
expect(self.$invalidWidgets).toEqual([self.$element]);
-
+
var spy = jasmine.createSpy();
asynchronous.call(self, "kai", spy);
expect(spy).wasNotCalled();
-
+
asynchronous.call(self, "misko", spy);
- expect(spy).wasCalled();
+ expect(spy).wasCalled();
});
-
+
it("should ignore old callbacks, and not remove spinner", function(){
var firstCb, secondCb;
asynchronous.call(self, "first", function(v,f){value=v; firstCb=f;});
asynchronous.call(self, "second", function(v,f){value=v; secondCb=f;});
-
+
firstCb();
expect($(self.$element).hasClass('ng-input-indicator-wait')).toBeTruthy();
-
+
secondCb();
expect($(self.$element).hasClass('ng-input-indicator-wait')).toBeFalsy();
});
-}); \ No newline at end of file
+});
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index 3b6be8ec..da9d5f9b 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -1,4 +1,4 @@
-describe("widgets", function(){
+describe("input widget", function(){
var compile, element, scope;
@@ -15,14 +15,70 @@ describe("widgets", function(){
});
afterEach(function(){
- if (element) {
- element.remove();
- }
+ if (element) element.remove();
expect(_(jqCache).size()).toEqual(0);
});
- it('should fail', function(){
- fail('iueoi');
+ it('should input-text auto init and handle keyup/change events', function(){
+ compile('<input type="Text" name="name" value="Misko"/>');
+ expect(scope.get('name')).toEqual("Misko");
+
+ scope.set('name', 'Adam');
+ scope.updateView();
+ expect(element.attr('value')).toEqual("Adam");
+
+ element.attr('value', 'Shyam');
+ element.trigger('keyup');
+ expect(scope.get('name')).toEqual('Shyam');
+
+ element.attr('value', 'Kai');
+ element.trigger('change');
+ expect(scope.get('name')).toEqual('Kai');
+ });
+
+ it("should process ng-format", function(){
+ compile('<input type="Text" name="list" value="a,b,c" ng-format="list"/>');
+ expect(scope.get('list')).toEqual(['a', 'b', 'c']);
+
+ scope.set('list', ['x', 'y', 'z']);
+ scope.updateView();
+ expect(element.attr('value')).toEqual("x, y, z");
+
+ element.attr('value', '1, 2, 3');
+ element.trigger('keyup');
+ expect(scope.get('list')).toEqual(['1', '2', '3']);
+ });
+
+ it("should process ng-validation", function(){
+ compile('<input type="text" name="price" value="abc" ng-validate="number"/>');
+ expect(element.hasClass('ng-validation-error')).toBeTruthy();
+ expect(element.attr('ng-error')).toEqual('Not a number');
+
+ scope.set('price', '123');
+ scope.updateView();
+ expect(element.hasClass('ng-validation-error')).toBeFalsy();
+ expect(element.attr('ng-error')).toBeFalsy();
+
+ element.attr('value', 'x');
+ element.trigger('keyup');
+ expect(element.hasClass('ng-validation-error')).toBeTruthy();
+ expect(element.attr('ng-error')).toEqual('Not a number');
+ });
+
+ it("should process ng-required", function(){
+ compile('<input type="text" name="price" ng-required/>');
+ expect(element.hasClass('ng-validation-error')).toBeTruthy();
+ expect(element.attr('ng-error')).toEqual('Required');
+
+ scope.set('price', 'xxx');
+ scope.updateView();
+ expect(element.hasClass('ng-validation-error')).toBeFalsy();
+ expect(element.attr('ng-error')).toBeFalsy();
+
+ element.attr('value', '');
+ element.trigger('keyup');
+ expect(element.hasClass('ng-validation-error')).toBeTruthy();
+ expect(element.attr('ng-error')).toEqual('Required');
});
});