From e78405f6ed82fcd2e9a1cdffb7f1103d52752623 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Wed, 21 Apr 2010 12:50:05 -0700
Subject: more if tests pass
---
test/FiltersTest.js | 6 +-
test/ValidatorsTest.js | 2 +-
test/directivesSpec.js | 38 ++--
test/markupSpec.js | 7 +-
test/testabilityPatch.js | 10 +-
test/widgetsSpec.js | 447 ++++++++++++++++++++++++-----------------------
6 files changed, 260 insertions(+), 250 deletions(-)
(limited to 'test')
diff --git a/test/FiltersTest.js b/test/FiltersTest.js
index ad38b94d..0fd80056 100644
--- a/test/FiltersTest.js
+++ b/test/FiltersTest.js
@@ -135,7 +135,7 @@ FiltersTest.prototype.testGoogleChartApiEncode = function() {
FiltersTest.prototype.testHtml = function() {
var div = jqLite('
');
div.append(angular.filter.html("acd"));
- assertEquals("acd", div.html());
+ assertEquals("acd", lowercase(div.html()));
};
FiltersTest.prototype.testLinky = function() {
@@ -143,9 +143,9 @@ FiltersTest.prototype.testLinky = function() {
assertEquals(
'http://ab ' +
'(http://a) ' +
- '<http://a> \n ' +
+ '<http://a> ' +
'http://1.2/v:~-123. c',
- sortedHtml(linky("http://ab (http://a) \n http://1.2/v:~-123. c")));
+ sortedHtml(linky("http://ab (http://a) http://1.2/v:~-123. c")));
assertEquals(undefined, linky(undefined));
};
diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js
index b2403eab..573c340d 100644
--- a/test/ValidatorsTest.js
+++ b/test/ValidatorsTest.js
@@ -12,7 +12,7 @@ ValidatorTest.prototype.testItShouldHaveThisSet = function() {
scope.$init();
assertEquals('misko', validator.first);
assertEquals('hevery', validator.last);
- assertSame(scope, validator._this.__proto__);
+ expect(validator._this.$id).toEqual(scope.$id);
delete angular.validator.myValidator;
scope.$element.remove();
};
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index f7024bdb..d012fdd0 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -41,7 +41,7 @@ describe("directives", function(){
var scope = compile('');
scope.html = 'hello
';
scope.$eval();
- expect(element.html()).toEqual('hello
');
+ expect(lowercase(element.html())).toEqual('hello
');
});
it('should ng-bind-template', function() {
@@ -58,7 +58,7 @@ describe("directives", function(){
});
it('should remove special attributes on false', function(){
- var scope = compile('');
+ var scope = compile('');
expect(scope.$element.attr('disabled')).toEqual(null);
expect(scope.$element.attr('readonly')).toEqual(null);
expect(scope.$element.attr('checked')).toEqual(null);
@@ -180,22 +180,24 @@ describe("directives", function(){
expect(isCssVisible(scope.$element)).toEqual(true);
});
- it('should ng-controller', function(){
- window.Greeter = function(){
- this.greeting = 'hello';
- };
- window.Greeter.prototype = {
- init: function(){
- this.suffix = '!';
- },
- greet: function(name) {
- return this.greeting + ' ' + name + this.suffix;
- }
- };
- var scope = compile('');
- expect(scope.greeting).toEqual('hello');
- expect(scope.greet('misko')).toEqual('hello misko!');
- delete window.Greeter;
+ describe('ng-controller', function(){
+ it('should bind', function(){
+ window.Greeter = function(){
+ this.greeting = 'hello';
+ };
+ window.Greeter.prototype = {
+ init: function(){
+ this.suffix = '!';
+ },
+ greet: function(name) {
+ return this.greeting + ' ' + name + this.suffix;
+ }
+ };
+ var scope = compile('');
+ expect(scope.greeting).toEqual('hello');
+ expect(scope.greet('misko')).toEqual('hello misko!');
+ window.Greeter = undefined;
+ });
});
it('should eval things according to ng-eval-order', function(){
diff --git a/test/markupSpec.js b/test/markupSpec.js
index a1112490..cfc0f899 100644
--- a/test/markupSpec.js
+++ b/test/markupSpec.js
@@ -43,13 +43,14 @@ describe("markups", function(){
});
it('should populate value attribute on OPTION', function(){
- compile('');
- expect(element.html()).toEqual('');
+ compile('');
+ expect(sortedHtml(element)).toEqual('');
});
it('should process all bindings when we have leading space', function(){
compile(' {{a}}
{{b}}');
- expect(sortedHtml(scope.$element)).toEqual('
');
+ var space = msie ? '' + NBSP + '': ' ';
+ expect(sortedHtml(scope.$element)).toEqual('' + space + '
');
});
});
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js
index 17341575..a2d67923 100644
--- a/test/testabilityPatch.js
+++ b/test/testabilityPatch.js
@@ -1,6 +1,8 @@
jstd = jstestdriver;
dump = bind(jstd.console, jstd.console.log);
+var NBSP = jqLite(' ').text();
+
function nakedExpect(obj) {
return expect(angular.fromJson(angular.toJson(obj)));
}
@@ -46,6 +48,7 @@ function sortedHtml(element) {
attr.value !='inherit' &&
attr.value !='0' &&
attr.name !='loop' &&
+ attr.name !='complete' &&
attr.name !='maxLength' &&
attr.name !='size' &&
attr.name !='start' &&
@@ -53,7 +56,8 @@ function sortedHtml(element) {
attr.name !='style' &&
attr.name.substr(0, 6) != 'jQuery') {
// in IE we need to check for all of these.
- attrs.push(' ' + attr.name + '="' + attr.value + '"');
+ if (!/ng-\d+/.exec(attr.name))
+ attrs.push(' ' + attr.name + '="' + attr.value + '"');
}
}
attrs.sort();
@@ -64,14 +68,14 @@ function sortedHtml(element) {
foreach(node.style.cssText.split(';'), function(value){
value = trim(value);
if (value) {
- style.push(value);
+ style.push(lowercase(value));
}
});
}
for(var css in node.style){
var value = node.style[css];
if (isString(value) && isString(css) && css != 'cssText' && value && (1*css != css)) {
- var text = css + ': ' + value;
+ var text = lowercase(css + ': ' + value);
if (value != 'false' && indexOf(style, text) == -1) {
style.push(text);
}
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index 2cfe216c..c6c57557 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -1,5 +1,4 @@
-describe("input widget", function(){
-
+describe("widget", function(){
var compile, element, scope;
beforeEach(function() {
@@ -19,265 +18,269 @@ describe("input widget", function(){
expect(size(jqCache)).toEqual(0);
});
- it('should input-text auto init and handle keyup/change events', function(){
- compile('');
- expect(scope.$get('name')).toEqual("Misko");
- expect(scope.$get('count')).toEqual(0);
+ describe("input", function(){
- scope.$set('name', 'Adam');
- scope.$eval();
- expect(element.val()).toEqual("Adam");
+ it('should input-text auto init and handle keyup/change events', function(){
+ compile('');
+ expect(scope.$get('name')).toEqual("Misko");
+ expect(scope.$get('count')).toEqual(0);
- element.val('Shyam');
- element.trigger('keyup');
- expect(scope.$get('name')).toEqual('Shyam');
- expect(scope.$get('count')).toEqual(1);
+ scope.$set('name', 'Adam');
+ scope.$eval();
+ expect(element.val()).toEqual("Adam");
- element.val('Kai');
- element.trigger('change');
- expect(scope.$get('name')).toEqual('Kai');
- expect(scope.$get('count')).toEqual(2);
- });
+ element.val('Shyam');
+ element.trigger('keyup');
+ expect(scope.$get('name')).toEqual('Shyam');
+ expect(scope.$get('count')).toEqual(1);
- it("should process ng-format", function(){
- compile('');
- expect(scope.$get('list')).toEqual(['a', 'b', 'c']);
+ element.val('Kai');
+ element.trigger('change');
+ expect(scope.$get('name')).toEqual('Kai');
+ expect(scope.$get('count')).toEqual(2);
+ });
- scope.$set('list', ['x', 'y', 'z']);
- scope.$eval();
- expect(element.val()).toEqual("x, y, z");
+ it("should process ng-format", function(){
+ compile('');
+ expect(scope.$get('list')).toEqual(['a', 'b', 'c']);
- element.val('1, 2, 3');
- element.trigger('keyup');
- expect(scope.$get('list')).toEqual(['1', '2', '3']);
- });
+ scope.$set('list', ['x', 'y', 'z']);
+ scope.$eval();
+ expect(element.val()).toEqual("x, y, z");
- it("should process ng-format for booleans", function(){
- compile('', function(){
- scope.name = false;
+ element.val('1, 2, 3');
+ element.trigger('keyup');
+ expect(scope.$get('list')).toEqual(['1', '2', '3']);
});
- expect(scope.name).toEqual(false);
- expect(scope.$element[0].checked).toEqual(false);
- });
- it("should process ng-validate", function(){
- compile('');
- expect(element.hasClass('ng-validation-error')).toBeTruthy();
- expect(element.attr('ng-validation-error')).toEqual('Not a number');
+ it("should process ng-format for booleans", function(){
+ compile('', function(){
+ scope.name = false;
+ });
+ expect(scope.name).toEqual(false);
+ expect(scope.$element[0].checked).toEqual(false);
+ });
- scope.$set('price', '123');
- scope.$eval();
- expect(element.hasClass('ng-validation-error')).toBeFalsy();
- expect(element.attr('ng-validation-error')).toBeFalsy();
+ it("should process ng-validate", function(){
+ compile('');
+ expect(element.hasClass('ng-validation-error')).toBeTruthy();
+ expect(element.attr('ng-validation-error')).toEqual('Not a number');
- element.val('x');
- element.trigger('keyup');
- expect(element.hasClass('ng-validation-error')).toBeTruthy();
- expect(element.attr('ng-validation-error')).toEqual('Not a number');
- });
+ scope.$set('price', '123');
+ scope.$eval();
+ expect(element.hasClass('ng-validation-error')).toBeFalsy();
+ expect(element.attr('ng-validation-error')).toBeFalsy();
- it("should not call validator if undefinde/empty", function(){
- var lastValue = "NOT_CALLED";
- angularValidator.myValidator = function(value){lastValue = value;};
- compile('');
- expect(lastValue).toEqual("NOT_CALLED");
+ element.val('x');
+ element.trigger('keyup');
+ expect(element.hasClass('ng-validation-error')).toBeTruthy();
+ expect(element.attr('ng-validation-error')).toEqual('Not a number');
+ });
- scope.url = 'http://server';
- scope.$eval();
- expect(lastValue).toEqual("http://server");
+ it("should not call validator if undefinde/empty", function(){
+ var lastValue = "NOT_CALLED";
+ angularValidator.myValidator = function(value){lastValue = value;};
+ compile('');
+ expect(lastValue).toEqual("NOT_CALLED");
- delete angularValidator.myValidator;
- });
+ scope.url = 'http://server';
+ scope.$eval();
+ expect(lastValue).toEqual("http://server");
- it("should ignore disabled widgets", function(){
- compile('');
- expect(element.hasClass('ng-validation-error')).toBeFalsy();
- expect(element.attr('ng-validation-error')).toBeFalsy();
- });
+ delete angularValidator.myValidator;
+ });
- it("should ignore readonly widgets", function(){
- compile('');
- expect(element.hasClass('ng-validation-error')).toBeFalsy();
- expect(element.attr('ng-validation-error')).toBeFalsy();
- });
+ it("should ignore disabled widgets", function(){
+ compile('');
+ expect(element.hasClass('ng-validation-error')).toBeFalsy();
+ expect(element.attr('ng-validation-error')).toBeFalsy();
+ });
- it("should process ng-required", function(){
- compile('');
- expect(element.hasClass('ng-validation-error')).toBeTruthy();
- expect(element.attr('ng-validation-error')).toEqual('Required');
+ it("should ignore readonly widgets", function(){
+ compile('');
+ expect(element.hasClass('ng-validation-error')).toBeFalsy();
+ expect(element.attr('ng-validation-error')).toBeFalsy();
+ });
- scope.$set('price', 'xxx');
- scope.$eval();
- expect(element.hasClass('ng-validation-error')).toBeFalsy();
- expect(element.attr('ng-validation-error')).toBeFalsy();
+ it("should process ng-required", function(){
+ compile('');
+ expect(element.hasClass('ng-validation-error')).toBeTruthy();
+ expect(element.attr('ng-validation-error')).toEqual('Required');
- element.val('');
- element.trigger('keyup');
- expect(element.hasClass('ng-validation-error')).toBeTruthy();
- expect(element.attr('ng-validation-error')).toEqual('Required');
- });
+ scope.$set('price', 'xxx');
+ scope.$eval();
+ expect(element.hasClass('ng-validation-error')).toBeFalsy();
+ expect(element.attr('ng-validation-error')).toBeFalsy();
- it("should process ng-required2", function() {
- compile('');
- expect(scope.$get('name')).toEqual("Misko");
+ element.val('');
+ element.trigger('keyup');
+ expect(element.hasClass('ng-validation-error')).toBeTruthy();
+ expect(element.attr('ng-validation-error')).toEqual('Required');
+ });
- scope.$set('name', 'Adam');
- scope.$eval();
- expect(element.val()).toEqual("Adam");
+ it("should process ng-required2", function() {
+ compile('');
+ expect(scope.$get('name')).toEqual("Misko");
- element.val('Shyam');
- element.trigger('keyup');
- expect(scope.$get('name')).toEqual('Shyam');
+ scope.$set('name', 'Adam');
+ scope.$eval();
+ expect(element.val()).toEqual("Adam");
- element.val('Kai');
- element.trigger('change');
- expect(scope.$get('name')).toEqual('Kai');
- });
+ element.val('Shyam');
+ element.trigger('keyup');
+ expect(scope.$get('name')).toEqual('Shyam');
- it('should call ng-change on button click', function(){
- compile('');
- element.trigger('click');
- expect(scope.$get('clicked')).toEqual(true);
- });
+ element.val('Kai');
+ element.trigger('change');
+ expect(scope.$get('name')).toEqual('Kai');
+ });
- it('should support button alias', function(){
- compile('');
- element.trigger('click');
- expect(scope.$get('clicked')).toEqual(true);
- });
+ it('should call ng-change on button click', function(){
+ compile('');
+ element.trigger('click');
+ expect(scope.$get('clicked')).toEqual(true);
+ });
- it('should type="checkbox"', function(){
- compile('');
- expect(scope.checkbox).toEqual(true);
- element.trigger('click');
- expect(scope.checkbox).toEqual(false);
- expect(scope.action).toEqual(true);
- element.trigger('click');
- expect(scope.checkbox).toEqual(true);
- });
+ it('should support button alias', function(){
+ compile('');
+ element.trigger('click');
+ expect(scope.$get('clicked')).toEqual(true);
+ });
- it('should type="radio"', function(){
- compile('' +
- '' +
- '' +
- '' +
- '
');
- var a = element[0].childNodes[0];
- var b = element[0].childNodes[1];
- expect(b.name.split('@')[1]).toEqual('chose');
- expect(scope.chose).toEqual('B');
- scope.chose = 'A';
- scope.$eval();
- expect(a.checked).toEqual(true);
-
- scope.chose = 'B';
- scope.$eval();
- expect(a.checked).toEqual(false);
- expect(b.checked).toEqual(true);
- expect(scope.clicked).not.toBeDefined();
-
- jqLite(a).trigger('click');
- expect(scope.chose).toEqual('A');
- expect(scope.clicked).toEqual(1);
- });
+ it('should support type="checkbox"', function(){
+ compile('');
+ expect(scope.checkbox).toEqual(true);
+ element.trigger('click');
+ expect(scope.checkbox).toEqual(false);
+ expect(scope.action).toEqual(true);
+ element.trigger('click');
+ expect(scope.checkbox).toEqual(true);
+ });
- it('should type="select-one"', function(){
- compile(
- '');
- expect(scope.selection).toEqual('B');
- scope.selection = 'A';
- scope.$eval();
- expect(scope.selection).toEqual('A');
- expect(element[0].childNodes[0].selected).toEqual(true);
- });
+ it('should support type="radio"', function(){
+ compile('' +
+ '' +
+ '' +
+ '' +
+ '
');
+ var a = element[0].childNodes[0];
+ var b = element[0].childNodes[1];
+ expect(b.name.split('@')[1]).toEqual('chose');
+ expect(scope.chose).toEqual('B');
+ scope.chose = 'A';
+ scope.$eval();
+ expect(a.checked).toEqual(true);
+
+ scope.chose = 'B';
+ scope.$eval();
+ expect(a.checked).toEqual(false);
+ expect(b.checked).toEqual(true);
+ expect(scope.clicked).not.toBeDefined();
+
+ jqLite(a).trigger('click');
+ expect(scope.chose).toEqual('A');
+ expect(scope.clicked).toEqual(1);
+ });
- it('should type="select-multiple"', function(){
- compile(
- '');
- expect(scope.selection).toEqual(['B']);
- scope.selection = ['A'];
- scope.$eval();
- expect(element[0].childNodes[0].selected).toEqual(true);
- });
+ it('should support type="select-one"', function(){
+ compile(
+ '');
+ expect(scope.selection).toEqual('B');
+ scope.selection = 'A';
+ scope.$eval();
+ expect(scope.selection).toEqual('A');
+ expect(element[0].childNodes[0].selected).toEqual(true);
+ });
- it('should report error on missing field', function(){
- compile('');
- expect(element.hasClass('ng-exception')).toBeTruthy();
- });
+ it('should support type="select-multiple"', function(){
+ compile(
+ '');
+ expect(scope.selection).toEqual(['B']);
+ scope.selection = ['A'];
+ scope.$eval();
+ expect(element[0].childNodes[0].selected).toEqual(true);
+ });
- it('should report error on assignment error', function(){
- compile('');
- expect(element.hasClass('ng-exception')).toBeTruthy();
- });
+ it('should report error on missing field', function(){
+ compile('');
+ expect(element.hasClass('ng-exception')).toBeTruthy();
+ });
- it('should report error on ng-change exception', function(){
- compile('');
- element.trigger('click');
- expect(element.hasClass('ng-exception')).toBeTruthy();
- });
+ it('should report error on assignment error', function(){
+ compile('');
+ expect(element.hasClass('ng-exception')).toBeTruthy();
+ });
- it('should switch on value change', function(){
- compile('first:{{name}}
second:{{name}}
');
- expect(element.html()).toEqual('');
- scope.select = 1;
- scope.$eval();
- expect(element.text()).toEqual('first:');
- scope.name="shyam";
- scope.$eval();
- expect(element.text()).toEqual('first:shyam');
- scope.select = 2;
- scope.$eval();
- scope.name = 'misko';
- scope.$eval();
- expect(element.text()).toEqual('second:misko');
+ it('should report error on ng-change exception', function(){
+ compile('');
+ element.trigger('click');
+ expect(element.hasClass('ng-exception')).toBeTruthy();
+ });
});
-});
-describe('ng:switch', function(){
- it("should match urls", function(){
- var scope = compile('{{params.name}}
');
- scope.url = '/Book/Moby';
- scope.$init();
- expect(scope.$element.text()).toEqual('Moby');
- });
+ describe('ng:switch', function(){
+ it('should switch on value change', function(){
+ compile('first:{{name}}
second:{{name}}
');
+ expect(element.html()).toEqual('');
+ scope.select = 1;
+ scope.$eval();
+ expect(element.text()).toEqual('first:');
+ scope.name="shyam";
+ scope.$eval();
+ expect(element.text()).toEqual('first:shyam');
+ scope.select = 2;
+ scope.$eval();
+ expect(element.text()).toEqual('second:shyam');
+ scope.name = 'misko';
+ scope.$eval();
+ expect(element.text()).toEqual('second:misko');
+ });
- it("should match sandwich ids", function(){
- var scope = {};
- var match = angular.widget['NG:SWITCH'].route.call(scope, '/a/123/b', '/a/:id');
- expect(match).toBeFalsy();
- });
+ it("should match urls", function(){
+ var scope = angular.compile('{{params.name}}
');
+ scope.url = '/Book/Moby';
+ scope.$init();
+ expect(scope.$element.text()).toEqual('Moby');
+ });
+
+ it("should match sandwich ids", function(){
+ var scope = {};
+ var match = angular.widget['NG:SWITCH'].route.call(scope, '/a/123/b', '/a/:id');
+ expect(match).toBeFalsy();
+ });
- it('should call init on switch', function(){
- var scope = compile('{{name}}
');
- var cleared = false;
- scope.url = 'a';
- scope.$invalidWidgets = {clearOrphans: function(){
- cleared = true;
- }};
- scope.$init();
- expect(scope.name).toEqual(undefined);
- expect(scope.$element.text()).toEqual('works');
- expect(cleared).toEqual(true);
+ it('should call init on switch', function(){
+ var scope = angular.compile('{{name}}
');
+ var cleared = false;
+ scope.url = 'a';
+ scope.$invalidWidgets = {clearOrphans: function(){
+ cleared = true;
+ }};
+ scope.$init();
+ expect(scope.name).toEqual(undefined);
+ expect(scope.$element.text()).toEqual('works');
+ expect(cleared).toEqual(true);
+ });
});
-});
-describe('ng:include', function(){
- it('should include on external file', function() {
- var element = jqLite('');
- var scope = compile(element);
- scope.childScope = createScope();
- scope.childScope.name = 'misko';
- scope.url = 'myUrl';
- scope.$browser.xhr.expect('GET', 'myUrl').respond('{{name}}');
- scope.$init();
- scope.$browser.xhr.flush();
- expect(element.text()).toEqual('misko');
+ describe('ng:include', function(){
+ it('should include on external file', function() {
+ var element = jqLite('');
+ var scope = angular.compile(element);
+ scope.childScope = createScope();
+ scope.childScope.name = 'misko';
+ scope.url = 'myUrl';
+ scope.$browser.xhr.expect('GET', 'myUrl').respond('{{name}}');
+ scope.$init();
+ scope.$browser.xhr.flush();
+ expect(element.text()).toEqual('misko');
+ });
});
});
--
cgit v1.2.3