From 9efa46ae640cde17487c341daa9a75c0bd79da02 Mon Sep 17 00:00:00 2001
From: jankuca
Date: Mon, 23 Sep 2013 11:24:42 -0700
Subject: feat(ngRepeat): use block separator comments
Issue: multi-elements ng-repeat (ng-repeat-start, ng-repeat-end) can contain elements with a trancluding directive. This directive changes content of the row (template) and ng-repeat does not work correctly (when removing/moving rows), because ng-repeat works with the original template (elements).
This changes ng-repeat behavior to traverse the DOM to find current elements everytime we are moving/removing rows (if the template has multiple elements).
Closes #3104
---
test/BinderSpec.js | 27 ++++++-
test/helpers/testabilityPatch.js | 11 +++
test/ng/directive/ngClassSpec.js | 10 +--
test/ng/directive/ngRepeatSpec.js | 163 ++++++++++++++++++++++++++++++++++----
4 files changed, 186 insertions(+), 25 deletions(-)
(limited to 'test')
diff --git a/test/BinderSpec.js b/test/BinderSpec.js
index 3c204b64..b553c68d 100644
--- a/test/BinderSpec.js
+++ b/test/BinderSpec.js
@@ -96,7 +96,9 @@ describe('Binder', function() {
'
' +
'' +
'- A
' +
+ '' +
'- B
' +
+ '' +
'
');
items.unshift({a: 'C'});
@@ -105,8 +107,11 @@ describe('Binder', function() {
'' +
'' +
'- C
' +
+ '' +
'- A
' +
+ '' +
'- B
' +
+ '' +
'
');
items.shift();
@@ -115,7 +120,9 @@ describe('Binder', function() {
'' +
'' +
'- A
' +
+ '' +
'- B
' +
+ '' +
'
');
items.shift();
@@ -134,6 +141,7 @@ describe('Binder', function() {
'');
}));
@@ -148,15 +156,15 @@ describe('Binder', function() {
$rootScope.items = items;
$rootScope.$apply();
- expect(element[0].childNodes.length - 1).toEqual(0);
+ expect(element[0].childNodes.length).toEqual(1);
items.name = 'misko';
$rootScope.$apply();
- expect(element[0].childNodes.length - 1).toEqual(1);
+ expect(element[0].childNodes.length).toEqual(3);
delete items.name;
$rootScope.$apply();
- expect(element[0].childNodes.length - 1).toEqual(0);
+ expect(element[0].childNodes.length).toEqual(1);
}));
it('IfTextBindingThrowsErrorDecorateTheSpan', function() {
@@ -223,13 +231,19 @@ describe('Binder', function() {
''+
'' +
'
'+
+ '' +
'
'+
+ '' +
'
'+
+ '' +
''+
'' +
'
'+
+ '' +
'
'+
+ '' +
'
' +
+ '' +
'');
}));
@@ -306,15 +320,18 @@ describe('Binder', function() {
'' +
'')($rootScope);
$rootScope.$apply();
+
var d1 = jqLite(element[0].childNodes[1]);
- var d2 = jqLite(element[0].childNodes[2]);
+ var d2 = jqLite(element[0].childNodes[3]);
expect(d1.hasClass('o')).toBeTruthy();
expect(d2.hasClass('e')).toBeTruthy();
expect(sortedHtml(element)).toBe(
'' +
'' +
'
' +
+ '' +
'
' +
+ '' +
'
');
}));
@@ -420,7 +437,9 @@ describe('Binder', function() {
'' +
'' +
'- a0
' +
+ '' +
'- b1
' +
+ '' +
'
');
}));
diff --git a/test/helpers/testabilityPatch.js b/test/helpers/testabilityPatch.js
index 514a5fdb..41b5042a 100644
--- a/test/helpers/testabilityPatch.js
+++ b/test/helpers/testabilityPatch.js
@@ -226,6 +226,17 @@ function sortedHtml(element, showNgClass) {
}
+function childrenTagsOf(element) {
+ var tags = [];
+
+ forEach(jqLite(element).children(), function(child) {
+ tags.push(child.nodeName.toLowerCase());
+ });
+
+ return tags;
+}
+
+
// TODO(vojta): migrate these helpers into jasmine matchers
/**a
* This method is a cheap way of testing if css for a given node is not set to 'none'. It doesn't
diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js
index f0989f4a..a788e452 100644
--- a/test/ng/directive/ngClassSpec.js
+++ b/test/ng/directive/ngClassSpec.js
@@ -166,7 +166,7 @@ describe('ngClass', function() {
element = $compile('')($rootScope);
$rootScope.$digest();
var e1 = jqLite(element[0].childNodes[1]);
- var e2 = jqLite(element[0].childNodes[2]);
+ var e2 = jqLite(element[0].childNodes[3]);
expect(e1.hasClass('existing')).toBeTruthy();
expect(e1.hasClass('odd')).toBeTruthy();
expect(e2.hasClass('existing')).toBeTruthy();
@@ -181,7 +181,7 @@ describe('ngClass', function() {
'