Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2156)

Unified Diff: third_party/pkg/angular/test/directive/ng_repeat_spec.dart

Issue 180873006: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review feedback Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/test/directive/ng_repeat_spec.dart
diff --git a/third_party/pkg/angular/test/directive/ng_repeat_spec.dart b/third_party/pkg/angular/test/directive/ng_repeat_spec.dart
index dc03a9ae2a7112881d241330d837f634a03505ad..eb0fa376c7ebd428c0673ee72a75599e1ca2c776 100644
--- a/third_party/pkg/angular/test/directive/ng_repeat_spec.dart
+++ b/third_party/pkg/angular/test/directive/ng_repeat_spec.dart
@@ -4,25 +4,26 @@ import '../_specs.dart';
main() {
describe('NgRepeater', () {
- var element, $compile, scope, $exceptionHandler;
+ var element, $compile, scope, $exceptionHandler, directives;
- beforeEach(inject((Injector injector, Scope $rootScope, Compiler compiler) {
+ beforeEach(inject((Injector injector, Scope $rootScope, Compiler compiler, DirectiveMap _directives) {
$exceptionHandler = injector.get(ExceptionHandler);
scope = $rootScope;
$compile = (html) {
element = $(html);
- var blockFactory = compiler(element);
+ var blockFactory = compiler(element, _directives);
var block = blockFactory(injector, element);
return element;
};
+ directives = _directives;
}));
it(r'should set create a list of items', inject((Scope scope, Compiler compiler, Injector injector) {
var element = $('<div><div ng-repeat="item in items">{{item}}</div></div>');
- BlockFactory blockFactory = compiler(element);
+ BlockFactory blockFactory = compiler(element, directives);
Block block = blockFactory(injector, element);
- scope.items = ['a', 'b'];
- scope.$apply();
+ scope.context['items'] = ['a', 'b'];
+ scope.apply();
expect(element.text()).toEqual('ab');
}));
@@ -30,10 +31,10 @@ main() {
it(r'should set create a list of items from iterable',
inject((Scope scope, Compiler compiler, Injector injector) {
var element = $('<div><div ng-repeat="item in items">{{item}}</div></div>');
- BlockFactory blockFactory = compiler(element);
+ BlockFactory blockFactory = compiler(element, directives);
Block block = blockFactory(injector, element);
- scope.items = ['a', 'b'].map((i) => i); // makes an iterable
- scope.$apply();
+ scope.context['items'] = ['a', 'b'].map((i) => i); // makes an iterable
+ scope.apply();
expect(element.text()).toEqual('ab');
}));
@@ -45,21 +46,21 @@ main() {
'</ul>');
// INIT
- scope.items = [{"name": 'misko'}, {"name":'shyam'}];
- scope.$digest();
+ scope.context['items'] = [{"name": 'misko'}, {"name":'shyam'}];
+ scope.apply();
expect(element.find('li').length).toEqual(2);
expect(element.text()).toEqual('misko;shyam;');
// GROW
- scope.items.add({"name": 'adam'});
- scope.$digest();
+ scope.context['items'].add({"name": 'adam'});
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('misko;shyam;adam;');
// SHRINK
- scope.items.removeLast();
- scope.items.removeAt(0);
- scope.$digest();
+ scope.context['items'].removeLast();
+ scope.context['items'].removeAt(0);
+ scope.apply();
expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('shyam;');
});
@@ -72,7 +73,7 @@ main() {
'<li ng-repeat="item in null">{{item.name}};</li>' +
'</ul>' +
'</div>');
- scope.$digest();
+ scope.apply();
expect(element.find('ul').length).toEqual(1);
expect(element.find('li').length).toEqual(0);
});
@@ -84,13 +85,13 @@ main() {
'<ul>' +
'<li ng-repeat="item in items track by item.id">{{item.name}};</li>' +
'</ul>');
- scope.items = [{"id": 'misko'}, {"id": 'igor'}];
- scope.$digest();
+ scope.context['items'] = [{"id": 'misko'}, {"id": 'igor'}];
+ scope.apply();
var li0 = element.find('li')[0];
var li1 = element.find('li')[1];
- scope.items.add(scope.items.removeAt(0));
- scope.$digest();
+ scope.context['items'].add(scope.context['items'].removeAt(0));
+ scope.apply();
expect(element.find('li')[0]).toBe(li1);
expect(element.find('li')[1]).toBe(li0);
});
@@ -101,94 +102,94 @@ main() {
'<ul>' +
r'<li ng-repeat="item in items track by $id(item)">{{item.name}};</li>' +
'</ul>');
- scope.items = [{"name": 'misko'}, {"name": 'igor'}];
- scope.$digest();
+ scope.context['items'] = [{"name": 'misko'}, {"name": 'igor'}];
+ scope.apply();
var li0 = element.find('li')[0];
var li1 = element.find('li')[1];
- scope.items.add(scope.items.removeAt(0));
- scope.$digest();
+ scope.context['items'].add(scope.context['items'].removeAt(0));
+ scope.apply();
expect(element.find('li')[0]).toBe(li1);
expect(element.find('li')[1]).toBe(li0);
});
- xit(r'should iterate over an array of primitives', () {
+ it(r'should iterate over an array of primitives', () {
element = $compile(
r'<ul>' +
r'<li ng-repeat="item in items track by $index">{{item}};</li>' +
r'</ul>');
// INIT
- scope.items = [true, true, true];
- scope.$digest();
+ scope.context['items'] = [true, true, true];
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('true;true;true;');
-
- scope.items = [false, true, true];
- scope.$digest();
+
+ scope.context['items'] = [false, true, true];
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('false;true;true;');
- scope.items = [false, true, false];
- scope.$digest();
+ scope.context['items'] = [false, true, false];
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('false;true;false;');
- scope.items = [true];
- scope.$digest();
+ scope.context['items'] = [true];
+ scope.apply();
expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('true;');
- scope.items = [true, true, false];
- scope.$digest();
+ scope.context['items'] = [true, true, false];
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('true;true;false;');
- scope.items = [true, false, false];
- scope.$digest();
+ scope.context['items'] = [true, false, false];
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('true;false;false;');
// string
- scope.items = ['a', 'a', 'a'];
- scope.$digest();
+ scope.context['items'] = ['a', 'a', 'a'];
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('a;a;a;');
- scope.items = ['ab', 'a', 'a'];
- scope.$digest();
+ scope.context['items'] = ['ab', 'a', 'a'];
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('ab;a;a;');
- scope.items = ['test'];
- scope.$digest();
+ scope.context['items'] = ['test'];
+ scope.apply();
expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('test;');
- scope.items = ['same', 'value'];
- scope.$digest();
+ scope.context['items'] = ['same', 'value'];
+ scope.apply();
expect(element.find('li').length).toEqual(2);
expect(element.text()).toEqual('same;value;');
// number
- scope.items = [12, 12, 12];
- scope.$digest();
+ scope.context['items'] = [12, 12, 12];
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('12;12;12;');
- scope.items = [53, 12, 27];
- scope.$digest();
+ scope.context['items'] = [53, 12, 27];
+ scope.apply();
expect(element.find('li').length).toEqual(3);
expect(element.text()).toEqual('53;12;27;');
- scope.items = [89];
- scope.$digest();
+ scope.context['items'] = [89];
+ scope.apply();
expect(element.find('li').length).toEqual(1);
expect(element.text()).toEqual('89;');
- scope.items = [89, 23];
- scope.$digest();
+ scope.context['items'] = [89, 23];
+ scope.apply();
expect(element.find('li').length).toEqual(2);
expect(element.text()).toEqual('89;23;');
});
@@ -218,8 +219,8 @@ main() {
'<ul>' +
'<li ng-repeat="item in items">{{item}}:{{\$index}}|</li>' +
'</ul>');
- scope.items = ['misko', 'shyam', 'frodo'];
- scope.$digest();
+ scope.context['items'] = ['misko', 'shyam', 'frodo'];
+ scope.apply();
expect(element.text()).toEqual('misko:0|shyam:1|frodo:2|');
});
@@ -230,26 +231,26 @@ main() {
'<ul>' +
'<li ng-repeat="item in items">{{item}}:{{\$first}}-{{\$middle}}-{{\$last}}|</li>' +
'</ul>');
- scope.items = ['misko', 'shyam', 'doug'];
- scope.$digest();
+ scope.context['items'] = ['misko', 'shyam', 'doug'];
+ scope.apply();
expect(element.text()).
toEqual('misko:true-false-false|shyam:false-true-false|doug:false-false-true|');
- scope.items.add('frodo');
- scope.$digest();
+ scope.context['items'].add('frodo');
+ scope.apply();
expect(element.text()).
toEqual('misko:true-false-false|' +
'shyam:false-true-false|' +
'doug:false-true-false|' +
'frodo:false-false-true|');
- scope.items.removeLast();
- scope.items.removeLast();
- scope.$digest();
+ scope.context['items'].removeLast();
+ scope.context['items'].removeLast();
+ scope.apply();
expect(element.text()).toEqual('misko:true-false-false|shyam:false-false-true|');
- scope.items.removeLast();
- scope.$digest();
+ scope.context['items'].removeLast();
+ scope.apply();
expect(element.text()).toEqual('misko:true-false-true|');
});
@@ -258,21 +259,21 @@ main() {
'<ul>' +
'<li ng-repeat="item in items">{{item}}:{{\$odd}}-{{\$even}}|</li>' +
'</ul>');
- scope.items = ['misko', 'shyam', 'doug'];
- scope.$digest();
+ scope.context['items'] = ['misko', 'shyam', 'doug'];
+ scope.apply();
expect(element.text()).toEqual('misko:false-true|shyam:true-false|doug:false-true|');
- scope.items.add('frodo');
- scope.$digest();
+ scope.context['items'].add('frodo');
+ scope.apply();
expect(element.text()).toEqual('misko:false-true|shyam:true-false|doug:false-true|frodo:true-false|');
- scope.items.removeLast();
- scope.items.removeLast();
- scope.$digest();
+ scope.context['items'].removeLast();
+ scope.context['items'].removeLast();
+ scope.apply();
expect(element.text()).toEqual('misko:false-true|shyam:true-false|');
- scope.items.removeLast();
- scope.$digest();
+ scope.context['items'].removeLast();
+ scope.apply();
expect(element.text()).toEqual('misko:false-true|');
});
@@ -283,8 +284,8 @@ main() {
'<div ng-repeat="group in subgroup">{{group}}|</div>X' +
'</li>' +
'</ul>');
- scope.groups = [['a', 'b'], ['c','d']];
- scope.$digest();
+ scope.context['groups'] = [['a', 'b'], ['c','d']];
+ scope.apply();
expect(element.text()).toEqual('a|b|Xc|d|X');
});
@@ -303,15 +304,15 @@ main() {
c = {};
d = {};
- scope.items = [a, b, c];
- scope.$digest();
+ scope.context['items'] = [a, b, c];
+ scope.apply();
lis = element.find('li');
});
it(r'should preserve the order of elements', () {
- scope.items = [a, c, d];
- scope.$digest();
+ scope.context['items'] = [a, c, d];
+ scope.apply();
var newElements = element.find('li');
expect(newElements[0]).toEqual(lis[0]);
expect(newElements[1]).toEqual(lis[2]);
@@ -320,52 +321,52 @@ main() {
it(r'should throw error on adding existing duplicates and recover', () {
- scope.items = [a, a, a];
+ scope.context['items'] = [a, a, a];
expect(() {
- scope.$digest();
+ scope.apply();
}).toThrow("[NgErr50] ngRepeat error! Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in items, Duplicate key: {}");
// recover
- scope.items = [a];
- scope.$digest();
+ scope.context['items'] = [a];
+ scope.apply();
var newElements = element.find('li');
expect(newElements.length).toEqual(1);
expect(newElements[0]).toEqual(lis[0]);
- scope.items = [];
- scope.$digest();
+ scope.context['items'] = [];
+ scope.apply();
newElements = element.find('li');
expect(newElements.length).toEqual(0);
});
it(r'should throw error on new duplicates and recover', () {
- scope.items = [d, d, d];
+ scope.context['items'] = [d, d, d];
expect(() {
- scope.$digest();
+ scope.apply();
}).toThrow("[NgErr50] ngRepeat error! Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in items, Duplicate key: {}");
// recover
- scope.items = [a];
- scope.$digest();
+ scope.context['items'] = [a];
+ scope.apply();
var newElements = element.find('li');
expect(newElements.length).toEqual(1);
expect(newElements[0]).toEqual(lis[0]);
- scope.items = [];
- scope.$digest();
+ scope.context['items'] = [];
+ scope.apply();
newElements = element.find('li');
expect(newElements.length).toEqual(0);
});
it(r'should reverse items when the collection is reversed', () {
- scope.items = [a, b, c];
- scope.$digest();
+ scope.context['items'] = [a, b, c];
+ scope.apply();
lis = element.find('li');
- scope.items = [c, b, a];
- scope.$digest();
+ scope.context['items'] = [c, b, a];
+ scope.apply();
var newElements = element.find('li');
expect(newElements.length).toEqual(3);
expect(newElements[0]).toEqual(lis[2]);
@@ -378,13 +379,13 @@ main() {
// rebuilding repeater from scratch can be expensive, we should try to avoid it even for
// model that is composed of primitives.
- scope.items = ['hello', 'cau', 'ahoj'];
- scope.$digest();
+ scope.context['items'] = ['hello', 'cau', 'ahoj'];
+ scope.apply();
lis = element.find('li');
lis[2].id = 'yes';
- scope.items = ['ahoj', 'hello', 'cau'];
- scope.$digest();
+ scope.context['items'] = ['ahoj', 'hello', 'cau'];
+ scope.apply();
var newLis = element.find('li');
expect(newLis.length).toEqual(3);
expect(newLis[0]).toEqual(lis[2]);
@@ -393,32 +394,5 @@ main() {
});
});
- describe('shalow', () {
- TestBed _;
- beforeEach(inject((TestBed tb) => _ = tb));
-
- it('should x', () {
- _.compile('<ul><li ng-shallow-repeat="i in items">{{i.name}}</li></ul>');
- _.rootScope.items = [{'name': 'a'}, {'name':'b'}];
- _.rootScope.$digest();
- expect(_.rootElement.text).toEqual('ab');
-
- // Should not see this.
- _.rootScope.items[0]['name'] = 'x';
- _.rootScope.$digest();
- expect(_.rootElement.text).toEqual('ab');
-
- // We see additions but not changse
- _.rootScope.items.add({'name': 'C'});
- _.rootScope.$digest();
- expect(_.rootElement.text).toEqual('abC');
-
-
- // Cloning list does a full update
- _.rootScope.items = new List.from(_.rootScope.items);
- _.rootScope.$digest();
- expect(_.rootElement.text).toEqual('xbC');
- });
- });
});
}

Powered by Google App Engine
This is Rietveld 408576698