| Index: third_party/pkg/angular/test/introspection_spec.dart
|
| diff --git a/third_party/pkg/angular/test/introspection_spec.dart b/third_party/pkg/angular/test/introspection_spec.dart
|
| index df8892b14599b060ae93c22e4f980e45e178966b..a4ea5811ea160dce5d447b7a88079dba96c118fe 100644
|
| --- a/third_party/pkg/angular/test/introspection_spec.dart
|
| +++ b/third_party/pkg/angular/test/introspection_spec.dart
|
| @@ -1,37 +1,60 @@
|
| library introspection_spec;
|
|
|
| import '_specs.dart';
|
| +import 'dart:js' as js;
|
| +import 'package:angular/application_factory.dart';
|
| +
|
| +void main() {
|
| + describe('introspection', () {
|
| + it('should retrieve ElementProbe', (TestBed _) {
|
| + _.compile('<div ng-bind="true"></div>');
|
| + ElementProbe probe = ngProbe(_.rootElement);
|
| + expect(probe.injector.parent).toBe(_.injector);
|
| + expect(ngInjector(_.rootElement).parent).toBe(_.injector);
|
| + expect(probe.directives[0] is NgBind).toBe(true);
|
| + expect(ngDirectives(_.rootElement)[0] is NgBind).toBe(true);
|
| + expect(probe.scope).toBe(_.rootScope);
|
| + expect(ngScope(_.rootElement)).toBe(_.rootScope);
|
| + });
|
| +
|
| + toHtml(List list) => list.map((e) => e.outerHtml).join('');
|
| +
|
| + it('should select elements using CSS selector', () {
|
| + var div = new Element.html('<div><p><span></span></p></div>');
|
| + var span = div.querySelector('span');
|
| + var shadowRoot = span.createShadowRoot();
|
| + shadowRoot.innerHtml = '<ul><li>stash</li><li>secret</li><ul>';
|
| +
|
| + expect(toHtml(ngQuery(div, 'li'))).toEqual('<li>stash</li><li>secret</li>');
|
| + expect(toHtml(ngQuery(div, 'li', 'stash'))).toEqual('<li>stash</li>');
|
| + expect(toHtml(ngQuery(div, 'li', 'secret'))).toEqual('<li>secret</li>');
|
| + expect(toHtml(ngQuery(div, 'li', 'xxx'))).toEqual('');
|
| + });
|
| +
|
| + it('should select elements in the root shadow root', () {
|
| + var div = new Element.html('<div></div>');
|
| + var shadowRoot = div.createShadowRoot();
|
| + shadowRoot.innerHtml = '<ul><li>stash</li><li>secret</li><ul>';
|
| + expect(toHtml(ngQuery(div, 'li'))).toEqual('<li>stash</li><li>secret</li>');
|
| + });
|
| +
|
| + // Does not work in dart2js. deboer is investigating.
|
| + it('should be available from Javascript', () {
|
| + // The probe only works if there is a directive.
|
| + var elt = e('<div ng-app id=ngtop ng-bind="\'introspection FTW\'"></div>');
|
| + // Make it possible to find the element from JS
|
| + document.body.append(elt);
|
| + (applicationFactory()..element = elt).run();
|
| +
|
| + expect(js.context['ngProbe']).toBeDefined();
|
| + expect(js.context['ngScope']).toBeDefined();
|
| + expect(js.context['ngInjector']).toBeDefined();
|
| + expect(js.context['ngQuery']).toBeDefined();
|
|
|
| -main() => describe('introspection', () {
|
| - it('should retrieve ElementProbe', inject((TestBed _) {
|
| - _.compile('<div ng-bind="true"></div>');
|
| - ElementProbe probe = ngProbe(_.rootElement);
|
| - expect(probe.injector.parent).toBe(_.injector);
|
| - expect(ngInjector(_.rootElement).parent).toBe(_.injector);
|
| - expect(probe.directives[0] is NgBindDirective).toBe(true);
|
| - expect(ngDirectives(_.rootElement)[0] is NgBindDirective).toBe(true);
|
| - expect(probe.scope).toBe(_.rootScope);
|
| - expect(ngScope(_.rootElement)).toBe(_.rootScope);
|
| - }));
|
| -
|
| - toHtml(List list) => list.map((e) => e.outerHtml).join('');
|
| -
|
| - it('should select elements using CSS selector', () {
|
| - var div = new Element.html('<div><p><span></span></p></div>');
|
| - var span = div.querySelector('span');
|
| - var shadowRoot = span.createShadowRoot();
|
| - shadowRoot.innerHtml = '<ul><li>stash</li><li>secret</li><ul>';
|
| -
|
| - expect(toHtml(ngQuery(div, 'li'))).toEqual('<li>stash</li><li>secret</li>');
|
| - expect(toHtml(ngQuery(div, 'li', 'stash'))).toEqual('<li>stash</li>');
|
| - expect(toHtml(ngQuery(div, 'li', 'secret'))).toEqual('<li>secret</li>');
|
| - expect(toHtml(ngQuery(div, 'li', 'xxx'))).toEqual('');
|
| - });
|
|
|
| - it('should select elements in the root shadow root', () {
|
| - var div = new Element.html('<div></div>');
|
| - var shadowRoot = div.createShadowRoot();
|
| - shadowRoot.innerHtml = '<ul><li>stash</li><li>secret</li><ul>';
|
| - expect(toHtml(ngQuery(div, 'li'))).toEqual('<li>stash</li><li>secret</li>');
|
| + // Polymer does not support accessing named elements directly (e.g. window.ngtop)
|
| + // so we need to use getElementById to support Polymer's shadow DOM polyfill.
|
| + expect(js.context['ngProbe'].apply([document.getElementById('ngtop')])).toBeDefined();
|
| + });
|
| });
|
| -});
|
| +}
|
|
|