| Index: third_party/pkg/angular/test/core_dom/compiler_spec.dart
|
| ===================================================================
|
| --- third_party/pkg/angular/test/core_dom/compiler_spec.dart (revision 33054)
|
| +++ third_party/pkg/angular/test/core_dom/compiler_spec.dart (working copy)
|
| @@ -5,9 +5,8 @@
|
|
|
| main() => describe('dte.compiler', () {
|
| Compiler $compile;
|
| - DirectiveMap directives;
|
| Injector injector;
|
| - Scope rootScope;
|
| + Scope $rootScope;
|
|
|
| beforeEach(module((Module module) {
|
| module
|
| @@ -17,82 +16,77 @@
|
| ..type(SimpleTranscludeInAttachAttrDirective)
|
| ..type(IncludeTranscludeAttrDirective)
|
| ..type(LocalAttrDirective)
|
| - ..type(OneOfTwoDirectives)
|
| - ..type(TwoOfTwoDirectives)
|
| - ..type(MyController)
|
| - ..type(MyParentController)
|
| - ..type(MyChildController);
|
| + ..type(MyController);
|
| return (Injector _injector) {
|
| injector = _injector;
|
| $compile = injector.get(Compiler);
|
| - directives = injector.get(DirectiveMap);
|
| - rootScope = injector.get(Scope);
|
| + $rootScope = injector.get(Scope);
|
| };
|
| }));
|
|
|
| it('should compile basic hello world', inject(() {
|
| var element = $('<div ng-bind="name"></div>');
|
| - var template = $compile(element, directives);
|
| + var template = $compile(element);
|
|
|
| - rootScope.context['name'] = 'angular';
|
| + $rootScope['name'] = 'angular';
|
| template(injector, element);
|
|
|
| expect(element.text()).toEqual('');
|
| - rootScope.apply();
|
| + $rootScope.$digest();
|
| expect(element.text()).toEqual('angular');
|
| }));
|
|
|
| it('should not throw on an empty list', inject(() {
|
| - $compile([], directives);
|
| + $compile([]);
|
| }));
|
|
|
| it('should compile a directive in a child', inject(() {
|
| var element = $('<div><div ng-bind="name"></div></div>');
|
| - var template = $compile(element, directives);
|
| + var template = $compile(element);
|
|
|
| - rootScope.context['name'] = 'angular';
|
| + $rootScope['name'] = 'angular';
|
|
|
|
|
| template(injector, element);
|
|
|
| expect(element.text()).toEqual('');
|
| - rootScope.apply();
|
| + $rootScope.$digest();
|
| expect(element.text()).toEqual('angular');
|
| }));
|
|
|
| it('should compile repeater', inject(() {
|
| var element = $('<div><div ng-repeat="item in items" ng-bind="item"></div></div>');
|
| - var template = $compile(element, directives);
|
| + var template = $compile(element);
|
|
|
| - rootScope.context['items'] = ['A', 'b'];
|
| + $rootScope.items = ['A', 'b'];
|
| template(injector, element);
|
|
|
| expect(element.text()).toEqual('');
|
| // TODO(deboer): Digest twice until we have dirty checking in the scope.
|
| - rootScope.apply();
|
| - rootScope.apply();
|
| + $rootScope.$digest();
|
| + $rootScope.$digest();
|
| expect(element.text()).toEqual('Ab');
|
|
|
| - rootScope.context['items'] = [];
|
| - rootScope.apply();
|
| + $rootScope.items = [];
|
| + $rootScope.$digest();
|
| expect(element.html()).toEqual('<!--ANCHOR: [ng-repeat]=item in items-->');
|
| }));
|
|
|
| it('should compile repeater with children', inject((Compiler $compile) {
|
| var element = $('<div><div ng-repeat="item in items"><div ng-bind="item"></div></div></div>');
|
| - var template = $compile(element, directives);
|
| + var template = $compile(element);
|
|
|
| - rootScope.context['items'] = ['A', 'b'];
|
| + $rootScope.items = ['A', 'b'];
|
| template(injector, element);
|
|
|
| expect(element.text()).toEqual('');
|
| // TODO(deboer): Digest twice until we have dirty checking in the scope.
|
| - rootScope.apply();
|
| - rootScope.apply();
|
| + $rootScope.$digest();
|
| + $rootScope.$digest();
|
| expect(element.text()).toEqual('Ab');
|
|
|
| - rootScope.context['items'] = [];
|
| - rootScope.apply();
|
| + $rootScope.items = [];
|
| + $rootScope.$digest();
|
| expect(element.html()).toEqual('<!--ANCHOR: [ng-repeat]=item in items-->');
|
| }));
|
|
|
| @@ -100,14 +94,15 @@
|
| var element = $('<div>{{name}}<span>!</span></div>').contents();
|
| element.remove(null);
|
|
|
| - var template = $compile(element, directives);
|
| + var template = $compile(element);
|
|
|
| - rootScope.context['name'] = 'OK';
|
| + $rootScope.name = 'OK';
|
| var block = template(injector, element);
|
|
|
| element = $(block.elements);
|
|
|
| - rootScope.apply();
|
| + expect(element.text()).toEqual('!');
|
| + $rootScope.$digest();
|
| expect(element.text()).toEqual('OK!');
|
| }));
|
|
|
| @@ -118,47 +113,38 @@
|
| '<li ng-repeat="li in lis">{{li}}</li>' +
|
| '</ul>' +
|
| '</div>');
|
| - var template = $compile(element, directives);
|
| + var template = $compile(element);
|
|
|
| - rootScope.context['uls'] = [['A'], ['b']];
|
| + $rootScope.uls = [['A'], ['b']];
|
| template(injector, element);
|
|
|
| - rootScope.apply();
|
| + expect(element.text()).toEqual('');
|
| + $rootScope.$digest();
|
| expect(element.text()).toEqual('Ab');
|
| }));
|
|
|
| - it('should compile two directives with the same selector', inject((Logger log) {
|
| - var element = $('<div two-directives></div>');
|
| - var template = $compile(element, directives);
|
|
|
| - template(injector, element);
|
| - rootScope.apply();
|
| -
|
| - expect(log).toEqual(['OneOfTwo', 'TwoOfTwo']);
|
| - }));
|
| -
|
| -
|
| -
|
| describe("interpolation", () {
|
| it('should interpolate attribute nodes', inject(() {
|
| var element = $('<div test="{{name}}"></div>');
|
| - var template = $compile(element, directives);
|
| + var template = $compile(element);
|
|
|
| - rootScope.context['name'] = 'angular';
|
| + $rootScope.name = 'angular';
|
| template(injector, element);
|
|
|
| - rootScope.apply();
|
| + $rootScope.$digest();
|
| expect(element.attr('test')).toEqual('angular');
|
| }));
|
|
|
| it('should interpolate text nodes', inject(() {
|
| var element = $('<div>{{name}}</div>');
|
| - var template = $compile(element, directives);
|
| + var template = $compile(element);
|
|
|
| - rootScope.context['name'] = 'angular';
|
| + $rootScope.name = 'angular';
|
| template(injector, element);
|
|
|
| - rootScope.apply();
|
| + expect(element.text()).toEqual('');
|
| + $rootScope.$digest();
|
| expect(element.text()).toEqual('angular');
|
| }));
|
| });
|
| @@ -178,44 +164,42 @@
|
| module.type(PublishMeDirective);
|
| module.type(LogComponent);
|
| module.type(AttachDetachComponent);
|
| - module.type(SimpleAttachComponent);
|
| module.type(SimpleComponent);
|
| - module.type(ExprAttrComponent);
|
| - module.type(SayHelloFilter);
|
| }));
|
|
|
| it('should select on element', async(inject((NgZone zone) {
|
| var element = $(r'<div><simple></simple></div>');
|
|
|
| zone.run(() {
|
| - BlockFactory blockFactory = $compile(element, directives);
|
| + BlockFactory blockFactory = $compile(element);
|
| Block block = blockFactory(injector, element);
|
| });
|
|
|
| microLeap();
|
| - expect(element.textWithShadow()).toEqual('INNER()');
|
| + expect(element.textWithShadow()).toEqual('INNER_1()');
|
| })));
|
|
|
| it('should create a simple component', async(inject((NgZone zone) {
|
| - rootScope.context['name'] = 'OUTTER';
|
| - var element = $(r'<div>{{name}}:<simple>{{name}}</simple></div>');
|
| + $rootScope.name = 'OUTTER';
|
| + $rootScope.sep = '-';
|
| + var element = $(r'<div>{{name}}{{sep}}{{$id}}:<simple>{{name}}{{sep}}{{$id}}</simple></div>');
|
|
|
| zone.run(() {
|
| - BlockFactory blockFactory = $compile(element, directives);
|
| + BlockFactory blockFactory = $compile(element);
|
| Block block = blockFactory(injector, element);
|
| });
|
|
|
| microLeap();
|
| - expect(element.textWithShadow()).toEqual('OUTTER:INNER(OUTTER)');
|
| + expect(element.textWithShadow()).toEqual('OUTTER-_0:INNER_1(OUTTER-_0)');
|
| })));
|
|
|
| it('should create a component that can access parent scope', async(inject((NgZone zone) {
|
| - rootScope.context['fromParent'] = "should not be used";
|
| - rootScope.context['val'] = "poof";
|
| + $rootScope.fromParent = "should not be used";
|
| + $rootScope.val = "poof";
|
| var element = $('<parent-expression from-parent=val></parent-expression>');
|
|
|
| zone.run(() =>
|
| - $compile(element, directives)(injector, element));
|
| + $compile(element)(injector, element));
|
|
|
| microLeap();
|
| expect(renderedText(element)).toEqual('inside poof');
|
| @@ -224,17 +208,17 @@
|
| it('should behave nicely if a mapped attribute is missing', async(inject((NgZone zone) {
|
| var element = $('<parent-expression></parent-expression>');
|
| zone.run(() =>
|
| - $compile(element, directives)(injector, element));
|
| + $compile(element)(injector, element));
|
|
|
| microLeap();
|
| expect(renderedText(element)).toEqual('inside ');
|
| })));
|
|
|
| it('should behave nicely if a mapped attribute evals to null', async(inject((NgZone zone) {
|
| - rootScope.context['val'] = null;
|
| + $rootScope.val = null;
|
| var element = $('<parent-expression fromParent=val></parent-expression>');
|
| zone.run(() =>
|
| - $compile(element, directives)(injector, element));
|
| + $compile(element)(injector, element));
|
|
|
| microLeap();
|
| expect(renderedText(element)).toEqual('inside ');
|
| @@ -242,165 +226,149 @@
|
|
|
| it('should create a component with I/O', async(inject(() {
|
| var element = $(r'<div><io attr="A" expr="name" ondone="done=true"></io></div>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| microLeap();
|
|
|
| - rootScope.context['name'] = 'misko';
|
| - rootScope.apply();
|
| - var component = rootScope.context['ioComponent'];
|
| - expect(component.scope.context['name']).toEqual(null);
|
| - expect(component.scope.context['attr']).toEqual('A');
|
| - expect(component.scope.context['expr']).toEqual('misko');
|
| - component.scope.context['expr'] = 'angular';
|
| - rootScope.apply();
|
| - expect(rootScope.context['name']).toEqual('angular');
|
| - expect(rootScope.context['done']).toEqual(null);
|
| - component.scope.context['ondone']();
|
| - expect(rootScope.context['done']).toEqual(true);
|
| + $rootScope.name = 'misko';
|
| + $rootScope.$apply();
|
| + var component = $rootScope.ioComponent;
|
| + expect(component.scope.name).toEqual(null);
|
| + expect(component.scope.attr).toEqual('A');
|
| + expect(component.scope.expr).toEqual('misko');
|
| + component.scope.expr = 'angular';
|
| + $rootScope.$apply();
|
| + expect($rootScope.name).toEqual('angular');
|
| + expect($rootScope.done).toEqual(null);
|
| + component.scope.ondone();
|
| + expect($rootScope.done).toEqual(true);
|
| })));
|
|
|
| - xit('should should not create any watchers if no attributes are specified', async(inject((Profiler perf) {
|
| + it('should should not create any watchers if no attributes are specified', async(inject((Profiler perf) {
|
| var element = $(r'<div><io></io></div>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| microLeap();
|
| - injector.get(Scope).apply();
|
| - // Re-enable once we can publish these numbers
|
| - //expect(rootScope.watchGroup.totalFieldCost).toEqual(0);
|
| - //expect(rootScope.watchGroup.totalCollectionCost).toEqual(0);
|
| - //expect(rootScope.watchGroup.totalEvalCost).toEqual(0);
|
| - //expect(rootScope.observeGroup.totalFieldCost).toEqual(0);
|
| - //expect(rootScope.observeGroup.totalCollectionCost).toEqual(0);
|
| - //expect(rootScope.observeGroup.totalEvalCost).toEqual(0);
|
| + injector.get(Scope).$digest();
|
| + expect(perf.counters['ng.scope.watchers']).toEqual(0);
|
| })));
|
|
|
| it('should create a component with I/O and "=" binding value should be available', async(inject(() {
|
| - rootScope.context['name'] = 'misko';
|
| + $rootScope.name = 'misko';
|
| var element = $(r'<div><io attr="A" expr="name" ondone="done=true"></io></div>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| microLeap();
|
|
|
| - var component = rootScope.context['ioComponent'];
|
| - rootScope.apply();
|
| - expect(component.scope.context['expr']).toEqual('misko');
|
| - component.scope.context['expr'] = 'angular';
|
| - rootScope.apply();
|
| - expect(rootScope.context['name']).toEqual('angular');
|
| + var component = $rootScope.ioComponent;
|
| + $rootScope.$apply();
|
| + expect(component.scope.expr).toEqual('misko');
|
| + component.scope.expr = 'angular';
|
| + $rootScope.$apply();
|
| + expect($rootScope.name).toEqual('angular');
|
| })));
|
|
|
| it('should create a component with I/O bound to controller and "=" binding value should be available', async(inject(() {
|
| - rootScope.context['done'] = false;
|
| + $rootScope.done = false;
|
| var element = $(r'<div><io-controller attr="A" expr="name" once="name" ondone="done=true"></io-controller></div>');
|
|
|
|
|
| expect(injector).toBeDefined();
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| microLeap();
|
|
|
| - IoControllerComponent component = rootScope.context['ioComponent'];
|
| + IoControllerComponent component = $rootScope.ioComponent;
|
|
|
| expect(component.expr).toEqual(null);
|
| expect(component.exprOnce).toEqual(null);
|
| expect(component.attr).toEqual('A');
|
| - rootScope.apply();
|
| + $rootScope.$apply();
|
|
|
| - rootScope.context['name'] = 'misko';
|
| - rootScope.apply();
|
| + $rootScope.name = 'misko';
|
| + $rootScope.$apply();
|
| expect(component.expr).toEqual('misko');
|
| expect(component.exprOnce).toEqual('misko');
|
|
|
| - rootScope.context['name'] = 'igor';
|
| - rootScope.apply();
|
| + $rootScope.name = 'igor';
|
| + $rootScope.$apply();
|
| expect(component.expr).toEqual('igor');
|
| expect(component.exprOnce).toEqual('misko');
|
|
|
| component.expr = 'angular';
|
| - rootScope.apply();
|
| - expect(rootScope.context['name']).toEqual('angular');
|
| + $rootScope.$apply();
|
| + expect($rootScope.name).toEqual('angular');
|
|
|
| - expect(rootScope.context['done']).toEqual(false);
|
| + expect($rootScope.done).toEqual(false);
|
| component.onDone();
|
| - expect(rootScope.context['done']).toEqual(true);
|
| + expect($rootScope.done).toEqual(true);
|
|
|
| // Should be noop
|
| component.onOptional();
|
| })));
|
|
|
| - it('should create a map attribute to controller', async(inject(() {
|
| + it('should create a map attribute to controller', async(() {
|
| var element = $(r'<div><io-controller attr="{{name}}"></io-controller></div>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| microLeap();
|
|
|
| - IoControllerComponent component = rootScope.context['ioComponent'];
|
| + IoControllerComponent component = $rootScope.ioComponent;
|
|
|
| - rootScope.context['name'] = 'misko';
|
| - rootScope.apply();
|
| + $rootScope.name = 'misko';
|
| + $rootScope.$apply();
|
| expect(component.attr).toEqual('misko');
|
|
|
| - rootScope.context['name'] = 'james';
|
| - rootScope.apply();
|
| + $rootScope.name = 'james';
|
| + $rootScope.$apply();
|
| expect(component.attr).toEqual('james');
|
| - })));
|
| + }));
|
|
|
| - it('should create a unpublished component with I/O bound to controller and "=" binding value should be available', async(inject(() {
|
| - rootScope.context['name'] = 'misko';
|
| - rootScope.context['done'] = false;
|
| + it('should create a unpublished component with I/O bound to controller and "=" binding value should be available', async(() {
|
| + $rootScope.name = 'misko';
|
| + $rootScope.done = false;
|
| var element = $(r'<div><unpublished-io-controller attr="A" expr="name" ondone="done=true"></unpublished-io-controller></div>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| microLeap();
|
|
|
| - UnpublishedIoControllerComponent component = rootScope.context['ioComponent'];
|
| - rootScope.apply();
|
| + UnpublishedIoControllerComponent component = $rootScope.ioComponent;
|
| + $rootScope.$apply();
|
| expect(component.attr).toEqual('A');
|
| expect(component.expr).toEqual('misko');
|
| component.expr = 'angular';
|
| - rootScope.apply();
|
| - expect(rootScope.context['name']).toEqual('angular');
|
| + $rootScope.$apply();
|
| + expect($rootScope.name).toEqual('angular');
|
|
|
| - expect(rootScope.context['done']).toEqual(false);
|
| + expect($rootScope.done).toEqual(false);
|
| component.onDone();
|
| - expect(rootScope.context['done']).toEqual(true);
|
| + expect($rootScope.done).toEqual(true);
|
|
|
| // Should be noop
|
| component.onOptional();
|
| - })));
|
| + }));
|
|
|
| it('should error on incorrect mapping', async(inject(() {
|
| expect(() {
|
| var element = $(r'<div><incorrect-mapping></incorrect-mapping</div>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| }).toThrow("Unknown mapping 'foo\' for attribute 'attr'.");
|
| })));
|
|
|
| - it('should support filters in attribute expressions', async(inject(() {
|
| - var element = $(r'''<expr-attr-component expr="'Misko' | hello" one-way="'James' | hello" once="'Chirayu' | hello"></expr-attr-component>''');
|
| - $compile(element, directives)(injector, element);
|
| - ExprAttrComponent component = rootScope.context['exprAttrComponent'];
|
| - rootScope.apply();
|
| - expect(component.expr).toEqual('Hello, Misko!');
|
| - expect(component.oneWay).toEqual('Hello, James!');
|
| - expect(component.exprOnce).toEqual('Hello, Chirayu!');
|
| - })));
|
| -
|
| it('should error on non-asignable-mapping', async(inject(() {
|
| expect(() {
|
| var element = $(r'<div><non-assignable-mapping></non-assignable-mapping</div>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| }).toThrow("Expression '1+2' is not assignable in mapping '@1+2' for attribute 'attr'.");
|
| })));
|
|
|
| it('should expose mapped attributes as camel case', async(inject(() {
|
| var element = $('<camel-case-map camel-case=G></camel-case-map>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| microLeap();
|
| - rootScope.apply();
|
| - var componentScope = rootScope.context['camelCase'];
|
| - expect(componentScope.context['camelCase']).toEqual('G');
|
| + $rootScope.$apply();
|
| + var componentScope = $rootScope.camelCase;
|
| + expect(componentScope.camelCase).toEqual('G');
|
| })));
|
|
|
| - it('should throw an exception if required directive is missing', async(inject((Compiler $compile, Scope rootScope, Injector injector) {
|
| + it('should throw an exception if required directive is missing', async(inject((Compiler $compile, Scope $rootScope, Injector injector) {
|
| try {
|
| var element = $('<tab local><pane></pane><pane local></pane></tab>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| } catch (e) {
|
| var text = '$e';
|
| expect(text).toContain('No provider found for');
|
| @@ -412,7 +380,7 @@
|
| it('should publish component controller into the scope', async(inject((NgZone zone) {
|
| var element = $(r'<div><publish-me></publish-me></div>');
|
| zone.run(() =>
|
| - $compile(element, directives)(injector, element));
|
| + $compile(element)(injector, element));
|
|
|
| microLeap();
|
| expect(element.textWithShadow()).toEqual('WORKED');
|
| @@ -421,7 +389,7 @@
|
| it('should publish directive controller into the scope', async(inject((NgZone zone) {
|
| var element = $(r'<div><div publish-me>{{ctrlName.value}}</div></div>');
|
| zone.run(() =>
|
| - $compile(element, directives)(injector, element));
|
| + $compile(element)(injector, element));
|
|
|
| microLeap();
|
| expect(element.text()).toEqual('WORKED');
|
| @@ -429,15 +397,15 @@
|
|
|
| it('should "publish" controller to injector under provided publishTypes', inject(() {
|
| var element = $(r'<div publish-types></div>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| expect(PublishTypesAttrDirective._injector.get(PublishTypesAttrDirective)).
|
| toBe(PublishTypesAttrDirective._injector.get(PublishTypesDirectiveSuperType));
|
| }));
|
|
|
| it('should allow repeaters over controllers', async(inject((Logger logger) {
|
| var element = $(r'<log ng-repeat="i in [1, 2]"></log>');
|
| - $compile(element, directives)(injector, element);
|
| - rootScope.apply();
|
| + $compile(element)(injector, element);
|
| + $rootScope.$apply();
|
| microLeap();
|
|
|
| expect(logger.length).toEqual(2);
|
| @@ -454,51 +422,24 @@
|
|
|
| it('should fire onTemplate method', async(inject((Logger logger, MockHttpBackend backend) {
|
| backend.whenGET('some/template.url').respond('<div>WORKED</div>');
|
| - var scope = rootScope.createChild({});
|
| - scope.context['isReady'] = 'ready';
|
| - scope.context['logger'] = logger;
|
| - scope.context['once'] = null;
|
| - var element = $('<attach-detach attr-value="{{isReady}}" expr-value="isReady" once-value="once">{{logger("inner")}}</attach-detach>');
|
| - $compile(element, directives)(injector.createChild([new Module()..value(Scope, scope)]), element);
|
| + var scope = $rootScope.$new();
|
| + var element = $('<attach-detach></attach-detach>');
|
| + $compile(element)(injector.createChild([new Module()..value(Scope, scope)]), element);
|
| expect(logger).toEqual(['new']);
|
|
|
| expect(logger).toEqual(['new']);
|
|
|
| - rootScope.apply();
|
| - var expected = ['new', 'attach:@ready; =>ready; =>!null', 'inner'];
|
| - assert((() {
|
| - // there is an assertion in flush which double checks that
|
| - // flushes do not change model. This assertion creates one
|
| - // more 'inner';
|
| - expected.add('inner');
|
| - return true;
|
| - })());
|
| - expect(logger).toEqual(expected);
|
| - logger.clear();
|
| + $rootScope.$digest();
|
| + expect(logger).toEqual(['new', 'attach']);
|
|
|
| backend.flush();
|
| microLeap();
|
| - expect(logger).toEqual(['templateLoaded', rootScope.context['shadowRoot']]);
|
| - logger.clear();
|
| + expect(logger).toEqual(['new', 'attach', 'templateLoaded', scope.shadowRoot]);
|
|
|
| - scope.destroy();
|
| - expect(logger).toEqual(['detach']);
|
| + scope.$destroy();
|
| + expect(logger).toEqual(['new', 'attach', 'templateLoaded', scope.shadowRoot, 'detach']);
|
| expect(element.textWithShadow()).toEqual('WORKED');
|
| })));
|
| -
|
| - it('should should not call attach after scope is destroyed', async(inject((Logger logger, MockHttpBackend backend) {
|
| - backend.whenGET('foo.html').respond('<div>WORKED</div>');
|
| - var element = $('<simple-attach></simple-attach>');
|
| - var scope = rootScope.createChild({});
|
| - $compile(element, directives)(injector.createChild([new Module()..value(Scope, scope)]), element);
|
| - expect(logger).toEqual(['SimpleAttachComponent']);
|
| - scope.destroy();
|
| -
|
| - rootScope.apply();
|
| - microLeap();
|
| -
|
| - expect(logger).toEqual(['SimpleAttachComponent']);
|
| - })));
|
| });
|
|
|
| describe('invalid components', () {
|
| @@ -527,42 +468,31 @@
|
|
|
|
|
| describe('controller scoping', () {
|
| - it('should make controllers available to sibling and child controllers', async(inject((Compiler $compile, Scope rootScope, Logger log, Injector injector) {
|
| + it('should make controllers available to sibling and child controllers', async(inject((Compiler $compile, Scope $rootScope, Logger log, Injector injector) {
|
| var element = $('<tab local><pane local></pane><pane local></pane></tab>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| microLeap();
|
|
|
| expect(log.result()).toEqual('TabComponent-0; LocalAttrDirective-0; PaneComponent-1; LocalAttrDirective-0; PaneComponent-2; LocalAttrDirective-0');
|
| })));
|
|
|
| - it('should reuse controllers for transclusions', async(inject((Compiler $compile, Scope rootScope, Logger log, Injector injector) {
|
| + it('should reuse controllers for transclusions', async(inject((Compiler $compile, Scope $rootScope, Logger log, Injector injector) {
|
| var element = $('<div simple-transclude-in-attach include-transclude>block</div>');
|
| - $compile(element, directives)(injector, element);
|
| + $compile(element)(injector, element);
|
| microLeap();
|
|
|
| - rootScope.apply();
|
| + $rootScope.$apply();
|
| expect(log.result()).toEqual('IncludeTransclude; SimpleTransclude');
|
| })));
|
| -
|
| - it('should expose a parent controller to the scope of its children', inject((TestBed _) {
|
| -
|
| - var element = _.compile('<div my-parent-controller>' +
|
| - ' <div my-child-controller>{{ my_parent.data() }}</div>' +
|
| - '</div>');
|
| -
|
| - rootScope.apply();
|
| -
|
| - expect(element.text).toContain('my data');
|
| - }));
|
| });
|
|
|
|
|
| describe('NgDirective', () {
|
| it('should allow creation of a new scope', inject((TestBed _) {
|
| - _.rootScope.context['name'] = 'cover me';
|
| + _.rootScope.name = 'cover me';
|
| _.compile('<div><div my-controller>{{name}}</div></div>');
|
| - _.rootScope.apply();
|
| - expect(_.rootScope.context['name']).toEqual('cover me');
|
| + _.rootScope.$digest();
|
| + expect(_.rootScope.name).toEqual('cover me');
|
| expect(_.rootElement.text).toEqual('MyController');
|
| }));
|
| });
|
| @@ -570,22 +500,6 @@
|
| });
|
|
|
|
|
| -@NgController(
|
| - selector: '[my-parent-controller]',
|
| - publishAs: 'my_parent'
|
| -)
|
| -class MyParentController {
|
| - data() {
|
| - return "my data";
|
| - }
|
| -}
|
| -
|
| -@NgController(
|
| - selector: '[my-child-controller]',
|
| - publishAs: 'my_child'
|
| -)
|
| -class MyChildController {}
|
| -
|
| @NgComponent(
|
| selector: 'tab',
|
| visibility: NgDirective.DIRECT_CHILDREN_VISIBILITY)
|
| @@ -626,8 +540,8 @@
|
| selector: '[simple-transclude-in-attach]',
|
| visibility: NgDirective.CHILDREN_VISIBILITY, children: NgAnnotation.TRANSCLUDE_CHILDREN)
|
| class SimpleTranscludeInAttachAttrDirective {
|
| - SimpleTranscludeInAttachAttrDirective(BlockHole blockHole, BoundBlockFactory boundBlockFactory, Logger log, RootScope scope) {
|
| - scope.runAsync(() {
|
| + SimpleTranscludeInAttachAttrDirective(BlockHole blockHole, BoundBlockFactory boundBlockFactory, Logger log, Scope scope) {
|
| + scope.$evalAsync(() {
|
| var block = boundBlockFactory(scope);
|
| block.insertAfter(blockHole);
|
| log('SimpleTransclude');
|
| @@ -642,20 +556,6 @@
|
| }
|
| }
|
|
|
| -@NgDirective(selector: '[two-directives]')
|
| -class OneOfTwoDirectives {
|
| - OneOfTwoDirectives(Logger log) {
|
| - log('OneOfTwo');
|
| - }
|
| -}
|
| -
|
| -@NgDirective(selector: '[two-directives]')
|
| -class TwoOfTwoDirectives {
|
| - TwoOfTwoDirectives(Logger log) {
|
| - log('TwoOfTwo');
|
| - }
|
| -}
|
| -
|
| class PublishTypesDirectiveSuperType {
|
| }
|
|
|
| @@ -671,11 +571,11 @@
|
|
|
| @NgComponent(
|
| selector: 'simple',
|
| - template: r'{{name}}(<content>SHADOW-CONTENT</content>)'
|
| + template: r'{{name}}{{sep}}{{$id}}(<content>SHADOW-CONTENT</content>)'
|
| )
|
| class SimpleComponent {
|
| SimpleComponent(Scope scope) {
|
| - scope.context['name'] = 'INNER';
|
| + scope.name = 'INNER';
|
| }
|
| }
|
|
|
| @@ -683,17 +583,16 @@
|
| selector: 'io',
|
| template: r'<content></content>',
|
| map: const {
|
| - 'attr': '@scope.context.attr',
|
| - 'expr': '<=>scope.context.expr',
|
| - 'ondone': '&scope.context.ondone',
|
| + 'attr': '@scope.attr',
|
| + 'expr': '<=>scope.expr',
|
| + 'ondone': '&scope.ondone',
|
| }
|
| )
|
| class IoComponent {
|
| Scope scope;
|
| IoComponent(Scope scope) {
|
| this.scope = scope;
|
| - scope.rootScope.context['ioComponent'] = this;
|
| - scope.context['expr'] = 'initialExpr';
|
| + scope.$root.ioComponent = this;
|
| }
|
| }
|
|
|
| @@ -718,7 +617,7 @@
|
| var onOptional;
|
| IoControllerComponent(Scope scope) {
|
| this.scope = scope;
|
| - scope.rootScope.context['ioComponent'] = this;
|
| + scope.$root.ioComponent = this;
|
| }
|
| }
|
|
|
| @@ -741,7 +640,7 @@
|
| var onOptional;
|
| UnpublishedIoControllerComponent(Scope scope) {
|
| this.scope = scope;
|
| - scope.rootScope.context['ioComponent'] = this;
|
| + scope.$root.ioComponent = this;
|
| }
|
| }
|
|
|
| @@ -760,13 +659,13 @@
|
| @NgComponent(
|
| selector: 'camel-case-map',
|
| map: const {
|
| - 'camel-case': '@scope.context.camelCase',
|
| + 'camel-case': '@scope.camelCase',
|
| }
|
| )
|
| class CamelCaseMapComponent {
|
| Scope scope;
|
| CamelCaseMapComponent(Scope this.scope) {
|
| - scope.rootScope.context['camelCase'] = scope;
|
| + scope.$root.camelCase = scope;
|
| }
|
| }
|
|
|
| @@ -774,7 +673,7 @@
|
| selector: 'parent-expression',
|
| template: '<div>inside {{fromParent()}}</div>',
|
| map: const {
|
| - 'from-parent': '&scope.context.fromParent',
|
| + 'from-parent': '&scope.fromParent',
|
| }
|
| )
|
| class ParentExpressionComponent {
|
| @@ -792,7 +691,7 @@
|
| }
|
|
|
|
|
| -@NgController (
|
| +@NgDirective (
|
| selector: '[publish-me]',
|
| publishAs: 'ctrlName'
|
| )
|
| @@ -814,33 +713,21 @@
|
|
|
| @NgComponent(
|
| selector: 'attach-detach',
|
| - templateUrl: 'some/template.url',
|
| - map: const {
|
| - 'attr-value': '@attrValue',
|
| - 'expr-value': '<=>exprValue',
|
| - 'once-value': '=>!onceValue',
|
| - 'optional-one': '=>optional',
|
| - 'optional-two': '<=>optional',
|
| - 'optional-once': '=>!optional',
|
| - }
|
| + templateUrl: 'some/template.url'
|
| )
|
| class AttachDetachComponent implements NgAttachAware, NgDetachAware, NgShadowRootAware {
|
| Logger logger;
|
| Scope scope;
|
| - String attrValue = 'too early';
|
| - String exprValue = 'too early';
|
| - String onceValue = 'too early';
|
| - String optional;
|
|
|
| AttachDetachComponent(Logger this.logger, TemplateLoader templateLoader, Scope this.scope) {
|
| logger('new');
|
| templateLoader.template.then((_) => logger('templateLoaded'));
|
| }
|
|
|
| - attach() => logger('attach:@$attrValue; =>$exprValue; =>!$onceValue');
|
| + attach() => logger('attach');
|
| detach() => logger('detach');
|
| onShadowRoot(shadowRoot) {
|
| - scope.rootScope.context['shadowRoot'] = shadowRoot;
|
| + scope.$root.shadowRoot = shadowRoot;
|
| logger(shadowRoot);
|
| }
|
| }
|
| @@ -851,7 +738,7 @@
|
| )
|
| class MyController {
|
| MyController(Scope scope) {
|
| - scope.context['name'] = 'MyController';
|
| + scope.name = 'MyController';
|
| }
|
| }
|
|
|
| @@ -861,41 +748,3 @@
|
| @NgComponent(selector: 'buttonbar button')
|
| class InvalidSelector {}
|
|
|
| -@NgFilter(name:'hello')
|
| -class SayHelloFilter {
|
| - call(String str) {
|
| - return 'Hello, $str!';
|
| - }
|
| -}
|
| -
|
| -@NgComponent(
|
| - selector: 'expr-attr-component',
|
| - template: r'<content></content>',
|
| - publishAs: 'ctrl',
|
| - map: const {
|
| - 'expr': '<=>expr',
|
| - 'one-way': '=>oneWay',
|
| - 'once': '=>!exprOnce'
|
| - }
|
| -)
|
| -class ExprAttrComponent {
|
| - var expr;
|
| - var oneWay;
|
| - var exprOnce;
|
| -
|
| - ExprAttrComponent(Scope scope) {
|
| - scope.rootScope.context['exprAttrComponent'] = this;
|
| - }
|
| -}
|
| -
|
| -@NgComponent(
|
| - selector: 'simple-attach',
|
| - templateUrl: 'foo.html')
|
| -class SimpleAttachComponent implements NgAttachAware, NgShadowRootAware {
|
| - Logger logger;
|
| - SimpleAttachComponent(this.logger) {
|
| - logger('SimpleAttachComponent');
|
| - }
|
| - attach() => logger('attach');
|
| - onShadowRoot(_) => logger('onShadowRoot');
|
| -}
|
|
|