| OLD | NEW |
| 1 library introspection_spec; | 1 library introspection_spec; |
| 2 | 2 |
| 3 import '_specs.dart'; | 3 import '_specs.dart'; |
| 4 import 'dart:js' as js; | |
| 5 import 'package:angular/application_factory.dart'; | |
| 6 | 4 |
| 7 void main() { | 5 main() => describe('introspection', () { |
| 8 describe('introspection', () { | 6 it('should retrieve ElementProbe', inject((TestBed _) { |
| 9 it('should retrieve ElementProbe', (TestBed _) { | 7 _.compile('<div ng-bind="true"></div>'); |
| 10 _.compile('<div ng-bind="true"></div>'); | 8 ElementProbe probe = ngProbe(_.rootElement); |
| 11 ElementProbe probe = ngProbe(_.rootElement); | 9 expect(probe.injector.parent).toBe(_.injector); |
| 12 expect(probe.injector.parent).toBe(_.injector); | 10 expect(ngInjector(_.rootElement).parent).toBe(_.injector); |
| 13 expect(ngInjector(_.rootElement).parent).toBe(_.injector); | 11 expect(probe.directives[0] is NgBindDirective).toBe(true); |
| 14 expect(probe.directives[0] is NgBind).toBe(true); | 12 expect(ngDirectives(_.rootElement)[0] is NgBindDirective).toBe(true); |
| 15 expect(ngDirectives(_.rootElement)[0] is NgBind).toBe(true); | 13 expect(probe.scope).toBe(_.rootScope); |
| 16 expect(probe.scope).toBe(_.rootScope); | 14 expect(ngScope(_.rootElement)).toBe(_.rootScope); |
| 17 expect(ngScope(_.rootElement)).toBe(_.rootScope); | 15 })); |
| 18 }); | |
| 19 | 16 |
| 20 toHtml(List list) => list.map((e) => e.outerHtml).join(''); | 17 toHtml(List list) => list.map((e) => e.outerHtml).join(''); |
| 21 | 18 |
| 22 it('should select elements using CSS selector', () { | 19 it('should select elements using CSS selector', () { |
| 23 var div = new Element.html('<div><p><span></span></p></div>'); | 20 var div = new Element.html('<div><p><span></span></p></div>'); |
| 24 var span = div.querySelector('span'); | 21 var span = div.querySelector('span'); |
| 25 var shadowRoot = span.createShadowRoot(); | 22 var shadowRoot = span.createShadowRoot(); |
| 26 shadowRoot.innerHtml = '<ul><li>stash</li><li>secret</li><ul>'; | 23 shadowRoot.innerHtml = '<ul><li>stash</li><li>secret</li><ul>'; |
| 27 | 24 |
| 28 expect(toHtml(ngQuery(div, 'li'))).toEqual('<li>stash</li><li>secret</li>'
); | 25 expect(toHtml(ngQuery(div, 'li'))).toEqual('<li>stash</li><li>secret</li>'); |
| 29 expect(toHtml(ngQuery(div, 'li', 'stash'))).toEqual('<li>stash</li>'); | 26 expect(toHtml(ngQuery(div, 'li', 'stash'))).toEqual('<li>stash</li>'); |
| 30 expect(toHtml(ngQuery(div, 'li', 'secret'))).toEqual('<li>secret</li>'); | 27 expect(toHtml(ngQuery(div, 'li', 'secret'))).toEqual('<li>secret</li>'); |
| 31 expect(toHtml(ngQuery(div, 'li', 'xxx'))).toEqual(''); | 28 expect(toHtml(ngQuery(div, 'li', 'xxx'))).toEqual(''); |
| 32 }); | 29 }); |
| 33 | 30 |
| 34 it('should select elements in the root shadow root', () { | 31 it('should select elements in the root shadow root', () { |
| 35 var div = new Element.html('<div></div>'); | 32 var div = new Element.html('<div></div>'); |
| 36 var shadowRoot = div.createShadowRoot(); | 33 var shadowRoot = div.createShadowRoot(); |
| 37 shadowRoot.innerHtml = '<ul><li>stash</li><li>secret</li><ul>'; | 34 shadowRoot.innerHtml = '<ul><li>stash</li><li>secret</li><ul>'; |
| 38 expect(toHtml(ngQuery(div, 'li'))).toEqual('<li>stash</li><li>secret</li>'
); | 35 expect(toHtml(ngQuery(div, 'li'))).toEqual('<li>stash</li><li>secret</li>'); |
| 39 }); | |
| 40 | |
| 41 // Does not work in dart2js. deboer is investigating. | |
| 42 it('should be available from Javascript', () { | |
| 43 // The probe only works if there is a directive. | |
| 44 var elt = e('<div ng-app id=ngtop ng-bind="\'introspection FTW\'"></div>')
; | |
| 45 // Make it possible to find the element from JS | |
| 46 document.body.append(elt); | |
| 47 (applicationFactory()..element = elt).run(); | |
| 48 | |
| 49 expect(js.context['ngProbe']).toBeDefined(); | |
| 50 expect(js.context['ngScope']).toBeDefined(); | |
| 51 expect(js.context['ngInjector']).toBeDefined(); | |
| 52 expect(js.context['ngQuery']).toBeDefined(); | |
| 53 | |
| 54 | |
| 55 // Polymer does not support accessing named elements directly (e.g. window
.ngtop) | |
| 56 // so we need to use getElementById to support Polymer's shadow DOM polyfi
ll. | |
| 57 expect(js.context['ngProbe'].apply([document.getElementById('ngtop')])).to
BeDefined(); | |
| 58 }); | |
| 59 }); | 36 }); |
| 60 } | 37 }); |
| OLD | NEW |