From 75f11f1fc46c35a28c0905f7316ea6779145e2fb Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Tue, 16 Aug 2011 23:08:13 -0700
Subject: feat(ng:repeat) collection items and DOM elements affinity /
stability
---
test/ApiSpecs.js | 105 +++++++++--------
test/BinderSpec.js | 40 +++----
test/scenario/dslSpec.js | 4 +-
test/widgetsSpec.js | 285 +++++++++++++++++++++++++++++++----------------
4 files changed, 269 insertions(+), 165 deletions(-)
(limited to 'test')
diff --git a/test/ApiSpecs.js b/test/ApiSpecs.js
index ef25bb41..9683a7b7 100644
--- a/test/ApiSpecs.js
+++ b/test/ApiSpecs.js
@@ -1,26 +1,39 @@
'use strict';
-describe('api', function(){
+describe('api', function() {
- describe('HashMap', function(){
- it('should do basic crud', function(){
+ describe('HashMap', function() {
+ it('should do basic crud', function() {
var map = new HashMap();
var key = {};
var value1 = {};
var value2 = {};
- expect(map.put(key, value1)).toEqual(undefined);
- expect(map.put(key, value2)).toEqual(value1);
- expect(map.get(key)).toEqual(value2);
- expect(map.get({})).toEqual(undefined);
- expect(map.remove(key)).toEqual(value2);
- expect(map.get(key)).toEqual(undefined);
+ map.put(key, value1);
+ map.put(key, value2);
+ expect(map.get(key)).toBe(value2);
+ expect(map.get({})).toBe(undefined);
+ expect(map.remove(key)).toBe(value2);
+ expect(map.get(key)).toBe(undefined);
});
});
- describe('Object', function(){
+ describe('HashQueueMap', function() {
+ it('should do basic crud with collections', function() {
+ var map = new HashQueueMap();
+ map.push('key', 'a');
+ map.push('key', 'b');
+ expect(map[hashKey('key')]).toEqual(['a', 'b']);
+ expect(map.shift('key')).toEqual('a');
+ expect(map.shift('key')).toEqual('b');
+ expect(map.shift('key')).toEqual(undefined);
+ expect(map[hashKey('key')]).toEqual(undefined);
+ });
+ });
+
- it('should return type of', function(){
+ describe('Object', function() {
+ it('should return type of', function() {
assertEquals("undefined", angular.Object.typeOf(undefined));
assertEquals("null", angular.Object.typeOf(null));
assertEquals("object", angular.Collection.typeOf({}));
@@ -28,46 +41,45 @@ describe('api', function(){
assertEquals("string", angular.Object.typeOf(""));
assertEquals("date", angular.Object.typeOf(new Date()));
assertEquals("element", angular.Object.typeOf(document.body));
- assertEquals('function', angular.Object.typeOf(function(){}));
+ assertEquals('function', angular.Object.typeOf(function() {}));
});
- it('should extend object', function(){
+ it('should extend object', function() {
assertEquals({a:1, b:2}, angular.Object.extend({a:1}, {b:2}));
});
-
});
- it('should return size', function(){
+ it('should return size', function() {
assertEquals(0, angular.Collection.size({}));
assertEquals(1, angular.Collection.size({a:"b"}));
assertEquals(0, angular.Object.size({}));
assertEquals(1, angular.Array.size([0]));
});
- describe('Array', function(){
- describe('sum', function(){
+ describe('Array', function() {
- it('should sum', function(){
+ describe('sum', function() {
+ it('should sum', function() {
assertEquals(3, angular.Array.sum([{a:"1"}, {a:"2"}], 'a'));
});
- it('should sum containing NaN', function(){
+ it('should sum containing NaN', function() {
assertEquals(1, angular.Array.sum([{a:1}, {a:Number.NaN}], 'a'));
- assertEquals(1, angular.Array.sum([{a:1}, {a:Number.NaN}], function($){return $.a;}));
+ assertEquals(1, angular.Array.sum([{a:1}, {a:Number.NaN}], function($) {return $.a;}));
});
-
});
- it('should find indexOf', function(){
+
+ it('should find indexOf', function() {
assertEquals(angular.Array.indexOf(['a'], 'a'), 0);
assertEquals(angular.Array.indexOf(['a', 'b'], 'a'), 0);
assertEquals(angular.Array.indexOf(['b', 'a'], 'a'), 1);
assertEquals(angular.Array.indexOf(['b', 'b'],'x'), -1);
});
- it('should remove item from array', function(){
+ it('should remove item from array', function() {
var items = ['a', 'b', 'c'];
assertEquals(angular.Array.remove(items, 'q'), 'q');
assertEquals(items.length, 3);
@@ -85,8 +97,8 @@ describe('api', function(){
assertEquals(items.length, 0);
});
- describe('filter', function(){
+ describe('filter', function() {
it('should filter by string', function() {
var items = ["MIsKO", {name:"shyam"}, ["adam"], 1234];
assertEquals(4, angular.Array.filter(items, "").length);
@@ -113,7 +125,7 @@ describe('api', function(){
assertEquals(0, angular.Array.filter(items, "misko").length);
});
- it('should filter on specific property', function(){
+ it('should filter on specific property', function() {
var items = [{ignore:"a", name:"a"}, {ignore:"a", name:"abc"}];
assertEquals(2, angular.Array.filter(items, {}).length);
@@ -123,12 +135,12 @@ describe('api', function(){
assertEquals("abc", angular.Array.filter(items, {name:'b'})[0].name);
});
- it('should take function as predicate', function(){
+ it('should take function as predicate', function() {
var items = [{name:"a"}, {name:"abc", done:true}];
- assertEquals(1, angular.Array.filter(items, function(i){return i.done;}).length);
+ assertEquals(1, angular.Array.filter(items, function(i) {return i.done;}).length);
});
- it('should take object as perdicate', function(){
+ it('should take object as perdicate', function() {
var items = [{first:"misko", last:"hevery"},
{first:"adam", last:"abrons"}];
@@ -139,7 +151,7 @@ describe('api', function(){
assertEquals(items[0], angular.Array.filter(items, {first:'misko', last:'hevery'})[0]);
});
- it('should support negation operator', function(){
+ it('should support negation operator', function() {
var items = ["misko", "adam"];
assertEquals(1, angular.Array.filter(items, '!isk').length);
@@ -198,12 +210,12 @@ describe('api', function(){
});
- it('add', function(){
+ it('add', function() {
var add = angular.Array.add;
assertJsonEquals([{}, "a"], add(add([]),"a"));
});
- it('count', function(){
+ it('count', function() {
var array = [{name:'a'},{name:'b'},{name:''}];
var obj = {};
@@ -212,24 +224,25 @@ describe('api', function(){
assertEquals(1, angular.Array.count(array, 'name=="a"'));
});
- describe('orderBy', function(){
+
+ describe('orderBy', function() {
var orderBy;
- beforeEach(function(){
+ beforeEach(function() {
orderBy = angular.Array.orderBy;
});
- it('should return same array if predicate is falsy', function(){
+ it('should return same array if predicate is falsy', function() {
var array = [1, 2, 3];
expect(orderBy(array)).toBe(array);
});
- it('shouldSortArrayInReverse', function(){
+ it('shouldSortArrayInReverse', function() {
assertJsonEquals([{a:15},{a:2}], angular.Array.orderBy([{a:15},{a:2}], 'a', true));
assertJsonEquals([{a:15},{a:2}], angular.Array.orderBy([{a:15},{a:2}], 'a', "T"));
assertJsonEquals([{a:15},{a:2}], angular.Array.orderBy([{a:15},{a:2}], 'a', "reverse"));
});
- it('should sort array by predicate', function(){
+ it('should sort array by predicate', function() {
assertJsonEquals([{a:2, b:1},{a:15, b:1}],
angular.Array.orderBy([{a:15, b:1},{a:2, b:1}], ['a', 'b']));
assertJsonEquals([{a:2, b:1},{a:15, b:1}],
@@ -238,11 +251,11 @@ describe('api', function(){
angular.Array.orderBy([{a:15, b:1},{a:2, b:1}], ['+b', '-a']));
});
- it('should use function', function(){
+ it('should use function', function() {
expect(
orderBy(
[{a:15, b:1},{a:2, b:1}],
- function(value){ return value.a; })).
+ function(value) { return value.a; })).
toEqual([{a:2, b:1},{a:15, b:1}]);
});
@@ -250,9 +263,9 @@ describe('api', function(){
});
- describe('string', function(){
- it('should quote', function(){
+ describe('string', function() {
+ it('should quote', function() {
assertEquals(angular.String.quote('a'), '"a"');
assertEquals(angular.String.quote('\\'), '"\\\\"');
assertEquals(angular.String.quote("'a'"), '"\'a\'"');
@@ -260,22 +273,22 @@ describe('api', function(){
assertEquals(angular.String.quote('\n\f\r\t'), '"\\n\\f\\r\\t"');
});
- it('should quote slashes', function(){
+ it('should quote slashes', function() {
assertEquals('"7\\\\\\\"7"', angular.String.quote("7\\\"7"));
});
- it('should quote unicode', function(){
+ it('should quote unicode', function() {
assertEquals('"abc\\u00a0def"', angular.String.quoteUnicode('abc\u00A0def'));
});
- it('should read/write to date', function(){
+ it('should read/write to date', function() {
var date = new Date("Sep 10 2003 13:02:03 GMT");
assertEquals("date", angular.Object.typeOf(date));
assertEquals("2003-09-10T13:02:03.000Z", angular.Date.toString(date));
assertEquals(date.getTime(), angular.String.toDate(angular.Date.toString(date)).getTime());
});
- it('should convert to date', function(){
+ it('should convert to date', function() {
//full ISO8061
expect(angular.String.toDate("2003-09-10T13:02:03.000Z")).
toEqual(new Date("Sep 10 2003 13:02:03 GMT"));
@@ -297,14 +310,12 @@ describe('api', function(){
toEqual(new Date("Sep 10 2003 00:00:00 GMT"));
});
- it('should parse date', function(){
+ it('should parse date', function() {
var date = angular.String.toDate("2003-09-10T13:02:03.000Z");
assertEquals("date", angular.Object.typeOf(date));
assertEquals("2003-09-10T13:02:03.000Z", angular.Date.toString(date));
assertEquals("str", angular.String.toDate("str"));
});
-
});
-
});
diff --git a/test/BinderSpec.js b/test/BinderSpec.js
index 68513f62..93f23eef 100644
--- a/test/BinderSpec.js
+++ b/test/BinderSpec.js
@@ -194,25 +194,25 @@ describe('Binder', function(){
scope.$apply();
assertEquals('
' +
'<#comment>#comment>' +
- '- A
' +
- '- B
' +
+ '- A
' +
+ '- B
' +
'
', sortedHtml(form));
items.unshift({a:'C'});
scope.$apply();
assertEquals('' +
'<#comment>#comment>' +
- '- C
' +
- '- A
' +
- '- B
' +
+ '- C
' +
+ '- A
' +
+ '- B
' +
'
', sortedHtml(form));
items.shift();
scope.$apply();
assertEquals('' +
'<#comment>#comment>' +
- '- A
' +
- '- B
' +
+ '- A
' +
+ '- B
' +
'
', sortedHtml(form));
items.shift();
@@ -226,7 +226,7 @@ describe('Binder', function(){
scope.$apply();
assertEquals('' +
'<#comment>#comment>' +
- '- A
' +
+ '- A
' +
'
', sortedHtml(scope.$element));
});
@@ -329,15 +329,15 @@ describe('Binder', function(){
assertEquals(''+
'<#comment>#comment>'+
- '
'+
+ '
'+
'<#comment>#comment>'+
- '
'+
- '
'+
+ '
'+
+ '
'+
'
'+
- '
'+
+ '
'+
'<#comment>#comment>'+
- '
'+
- '
'+
+ '
'+
+ '
'+
'
', sortedHtml(scope.$element));
});
@@ -417,8 +417,8 @@ describe('Binder', function(){
expect(d2.hasClass('e')).toBeTruthy();
assertEquals(
'
<#comment>#comment>' +
- '
' +
- '
',
+ '
' +
+ '
',
sortedHtml(scope.$element));
});
@@ -459,8 +459,8 @@ describe('Binder', function(){
scope.items = [{}, {name:'misko'}];
scope.$apply();
- assertEquals("123", scope.$eval('items[0].name'));
- assertEquals("misko", scope.$eval('items[1].name'));
+ expect(scope.$eval('items[0].name')).toEqual("123");
+ expect(scope.$eval('items[1].name')).toEqual("misko");
});
it('ShouldTemplateBindPreElements', function () {
@@ -593,8 +593,8 @@ describe('Binder', function(){
scope.$apply();
assertEquals('
' +
'<#comment>#comment>' +
- '- a0
' +
- '- b1
' +
+ '- a0
' +
+ '- b1
' +
'
',
sortedHtml(scope.$element));
});
diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js
index 3160da8d..c5d0a29d 100644
--- a/test/scenario/dslSpec.js
+++ b/test/scenario/dslSpec.js
@@ -378,9 +378,9 @@ describe("angular.scenario.dsl", function() {
beforeEach(function() {
doc.append(
'
' +
- ' - misko' +
+ '
- misko' +
' male
' +
- ' - felisa' +
+ '
- felisa' +
' female
' +
'
'
);
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index 6fccaa48..02d0ef71 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -1,6 +1,6 @@
'use strict';
-describe("widget", function(){
+describe("widget", function() {
var compile, element, scope;
beforeEach(function() {
@@ -19,14 +19,15 @@ describe("widget", function(){
};
});
- afterEach(function(){
+ afterEach(function() {
dealoc(element);
});
- describe("input", function(){
- describe("text", function(){
- it('should input-text auto init and handle keydown/change events', function(){
+ describe("input", function() {
+
+ describe("text", function() {
+ it('should input-text auto init and handle keydown/change events', function() {
compile('
');
expect(scope.name).toEqual("Misko");
expect(scope.count).toEqual(0);
@@ -49,7 +50,7 @@ describe("widget", function(){
expect(scope.count).toEqual(2);
});
- it('should not trigger eval if value does not change', function(){
+ it('should not trigger eval if value does not change', function() {
compile('
');
expect(scope.name).toEqual("Misko");
expect(scope.count).toEqual(0);
@@ -58,16 +59,16 @@ describe("widget", function(){
expect(scope.count).toEqual(0);
});
- it('should allow complex refernce binding', function(){
+ it('should allow complex refernce binding', function() {
compile('
'+
''+
'
');
expect(scope.obj['abc'].name).toEqual('Misko');
});
- describe("ng:format", function(){
- it("should format text", function(){
+ describe("ng:format", function() {
+ it("should format text", function() {
compile('
');
expect(scope.list).toEqual(['a', 'b', 'c']);
@@ -80,13 +81,13 @@ describe("widget", function(){
expect(scope.list).toEqual(['1', '2', '3']);
});
- it("should come up blank if null", function(){
+ it("should come up blank if null", function() {
compile('
');
expect(scope.age).toBeNull();
expect(scope.$element[0].value).toEqual('');
});
- it("should show incorect text while number does not parse", function(){
+ it("should show incorect text while number does not parse", function() {
compile('
');
scope.age = 123;
scope.$digest();
@@ -97,14 +98,14 @@ describe("widget", function(){
expect(scope.$element).toBeInvalid();
});
- it("should clober incorect text if model changes", function(){
+ it("should clober incorect text if model changes", function() {
compile('
');
scope.age = 456;
scope.$digest();
expect(scope.$element.val()).toEqual('456');
});
- it("should not clober text if model changes due to itself", function(){
+ it("should not clober text if model changes due to itself", function() {
compile('
');
scope.$element.val('a ');
@@ -128,23 +129,23 @@ describe("widget", function(){
expect(scope.list).toEqual(['a', 'b']);
});
- it("should come up blank when no value specifiend", function(){
+ it("should come up blank when no value specifiend", function() {
compile('
');
scope.$digest();
expect(scope.$element.val()).toEqual('');
expect(scope.age).toEqual(null);
});
-
});
- describe("checkbox", function(){
- it("should format booleans", function(){
+
+ describe("checkbox", function() {
+ it("should format booleans", function() {
compile('
');
expect(scope.name).toEqual(false);
expect(scope.$element[0].checked).toEqual(false);
});
- it('should support type="checkbox"', function(){
+ it('should support type="checkbox"', function() {
compile('
');
expect(scope.checkbox).toEqual(true);
browserTrigger(element);
@@ -154,9 +155,9 @@ describe("widget", function(){
expect(scope.checkbox).toEqual(true);
});
- it("should use ng:format", function(){
+ it("should use ng:format", function() {
angularFormatter('testFormat', {
- parse: function(value){
+ parse: function(value) {
return value ? "Worked" : "Failed";
},
@@ -181,8 +182,9 @@ describe("widget", function(){
});
});
- describe("ng:validate", function(){
- it("should process ng:validate", function(){
+
+ describe("ng:validate", function() {
+ it("should process ng:validate", function() {
compile('
',
jqLite(document.body));
expect(element.hasClass('ng-validation-error')).toBeTruthy();
@@ -210,9 +212,9 @@ describe("widget", function(){
expect(element.attr('ng-validation-error')).toBeFalsy();
});
- it("should not call validator if undefined/empty", function(){
+ it("should not call validator if undefined/empty", function() {
var lastValue = "NOT_CALLED";
- angularValidator.myValidator = function(value){lastValue = value;};
+ angularValidator.myValidator = function(value) {lastValue = value;};
compile('
');
expect(lastValue).toEqual("NOT_CALLED");
@@ -225,19 +227,20 @@ describe("widget", function(){
});
});
- it("should ignore disabled widgets", function(){
+
+ it("should ignore disabled widgets", function() {
compile('
');
expect(element.hasClass('ng-validation-error')).toBeFalsy();
expect(element.attr('ng-validation-error')).toBeFalsy();
});
- it("should ignore readonly widgets", function(){
+ it("should ignore readonly widgets", function() {
compile('
');
expect(element.hasClass('ng-validation-error')).toBeFalsy();
expect(element.attr('ng-validation-error')).toBeFalsy();
});
- it("should process ng:required", function(){
+ it("should process ng:required", function() {
compile('
', jqLite(document.body));
expect(element.hasClass('ng-validation-error')).toBeTruthy();
expect(element.attr('ng-validation-error')).toEqual('Required');
@@ -296,9 +299,8 @@ describe("widget", function(){
});
- describe('radio', function(){
-
- it('should support type="radio"', function(){
+ describe('radio', function() {
+ it('should support type="radio"', function() {
compile('
' +
'
' +
'
' +
@@ -323,7 +325,7 @@ describe("widget", function(){
expect(scope.clicked).toEqual(1);
});
- it('should honor model over html checked keyword after', function(){
+ it('should honor model over html checked keyword after', function() {
compile('
' +
'
' +
'
' +
@@ -333,7 +335,7 @@ describe("widget", function(){
expect(scope.choose).toEqual('C');
});
- it('should honor model over html checked keyword before', function(){
+ it('should honor model over html checked keyword before', function() {
compile('
' +
'
' +
'
' +
@@ -345,8 +347,9 @@ describe("widget", function(){
});
- describe('select-one', function(){
- it('should initialize to selected', function(){
+
+ describe('select-one', function() {
+ it('should initialize to selected', function() {
compile(
'