| OLD | NEW |
| 1 library html_extractor_spec; | 1 library html_extractor_spec; |
| 2 | 2 |
| 3 import 'package:angular/tools/common.dart'; | 3 import 'package:angular/tools/common.dart'; |
| 4 import 'package:angular/tools/html_extractor.dart'; | 4 import 'package:angular/tools/html_extractor.dart'; |
| 5 import 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
| 6 | 6 |
| 7 import '../jasmine_syntax.dart'; | 7 import '../jasmine_syntax.dart'; |
| 8 import 'mock_io_service.dart'; | 8 import 'mock_io_service.dart'; |
| 9 | 9 |
| 10 main() => describe('html_extractor', () { | 10 main() => describe('html_extractor', () { |
| 11 | 11 |
| 12 it('should extract text mustache expressions', () { | 12 it('should extract text mustache expressions', () { |
| 13 var ioService = new MockIoService({ | 13 var ioService = new MockIoService({ |
| 14 'foo.html': r''' | 14 'foo.html': r''' |
| 15 <div>foo {{ctrl.bar}} baz {{aux}}</div> | 15 <div>foo {{ctrl.bar}} baz {{aux}}</div> |
| 16 ''' | 16 ''' |
| 17 }); | 17 }); |
| 18 | 18 |
| 19 var extractor = new HtmlExpressionExtractor([]); | 19 var extractor = new HtmlExpressionExtractor([], ioService); |
| 20 extractor.crawl('/', ioService); | 20 extractor.crawl('/'); |
| 21 expect(extractor.expressions.toList()..sort(), | 21 expect(extractor.expressions.toList()..sort(), |
| 22 equals(['aux', 'ctrl.bar'])); | 22 equals(['aux', 'ctrl.bar'])); |
| 23 }); | 23 }); |
| 24 | 24 |
| 25 it('should extract attribute mustache expressions', () { | 25 it('should extract attribute mustache expressions', () { |
| 26 var ioService = new MockIoService({ | 26 var ioService = new MockIoService({ |
| 27 'foo.html': r''' | 27 'foo.html': r''' |
| 28 <div foo="foo-{{ctrl.bar}}" baz="{{aux}}-baz"></div> | 28 <div foo="foo-{{ctrl.bar}}" baz="{{aux}}-baz"></div> |
| 29 ''' | 29 ''' |
| 30 }); | 30 }); |
| 31 | 31 |
| 32 var extractor = new HtmlExpressionExtractor([]); | 32 var extractor = new HtmlExpressionExtractor([], ioService); |
| 33 extractor.crawl('/', ioService); | 33 extractor.crawl('/'); |
| 34 expect(extractor.expressions.toList()..sort(), | 34 expect(extractor.expressions.toList()..sort(), |
| 35 equals(['aux', 'ctrl.bar'])); | 35 equals(['aux', 'ctrl.bar'])); |
| 36 }); | 36 }); |
| 37 | 37 |
| 38 it('should extract ng-repeat expressions', () { | 38 it('should extract ng-repeat expressions', () { |
| 39 var ioService = new MockIoService({ | 39 var ioService = new MockIoService({ |
| 40 'foo.html': r''' | 40 'foo.html': r''' |
| 41 <div ng-repeat="foo in ctrl.bar"></div> | 41 <div ng-repeat="foo in ctrl.bar"></div> |
| 42 ''' | 42 ''' |
| 43 }); | 43 }); |
| 44 | 44 |
| 45 var extractor = new HtmlExpressionExtractor([]); | 45 var extractor = new HtmlExpressionExtractor([], ioService); |
| 46 extractor.crawl('/', ioService); | 46 extractor.crawl('/'); |
| 47 expect(extractor.expressions.toList()..sort(), | 47 expect(extractor.expressions.toList()..sort(), |
| 48 equals(['ctrl.bar'])); | 48 equals(['ctrl.bar'])); |
| 49 }); | 49 }); |
| 50 | 50 |
| 51 it('should extract expressions provided in the directive info', () { | 51 it('should extract expressions provided in the directive info', () { |
| 52 var ioService = new MockIoService({}); | 52 var ioService = new MockIoService({}); |
| 53 | 53 |
| 54 var extractor = new HtmlExpressionExtractor([ | 54 var extractor = new HtmlExpressionExtractor([ |
| 55 new DirectiveInfo('', [], ['foo', 'bar']) | 55 new DirectiveInfo('', [], ['foo', 'bar']) |
| 56 ]); | 56 ], ioService); |
| 57 extractor.crawl('/', ioService); | 57 extractor.crawl('/'); |
| 58 expect(extractor.expressions.toList()..sort(), | 58 expect(extractor.expressions.toList()..sort(), |
| 59 equals(['bar', 'foo'])); | 59 equals(['bar', 'foo'])); |
| 60 }); | 60 }); |
| 61 | 61 |
| 62 it('should extract expressions from expression attributes', () { | 62 it('should extract expressions from expression attributes', () { |
| 63 var ioService = new MockIoService({ | 63 var ioService = new MockIoService({ |
| 64 'foo.html': r''' | 64 'foo.html': r''' |
| 65 <foo bar="ctrl.baz"></foo> | 65 <foo bar="ctrl.baz"></foo> |
| 66 ''' | 66 ''' |
| 67 }); | 67 }); |
| 68 | 68 |
| 69 var extractor = new HtmlExpressionExtractor([ | 69 var extractor = new HtmlExpressionExtractor([ |
| 70 new DirectiveInfo('foo', ['bar']) | 70 new DirectiveInfo('foo', ['bar']) |
| 71 ]); | 71 ], ioService); |
| 72 extractor.crawl('/', ioService); | 72 extractor.crawl('/'); |
| 73 expect(extractor.expressions.toList()..sort(), | 73 expect(extractor.expressions.toList()..sort(), |
| 74 equals(['ctrl.baz'])); | 74 equals(['ctrl.baz'])); |
| 75 }); | 75 }); |
| 76 | 76 |
| 77 it('should ignore ng-repeat while extracting attribute expressions', () { | 77 it('should ignore ng-repeat while extracting attribute expressions', () { |
| 78 var ioService = new MockIoService({ | 78 var ioService = new MockIoService({ |
| 79 'foo.html': r''' | 79 'foo.html': r''' |
| 80 <div ng-repeat="foo in ctrl.bar"></div> | 80 <div ng-repeat="foo in ctrl.bar"></div> |
| 81 ''' | 81 ''' |
| 82 }); | 82 }); |
| 83 | 83 |
| 84 var extractor = new HtmlExpressionExtractor([ | 84 var extractor = new HtmlExpressionExtractor([ |
| 85 new DirectiveInfo('[ng-repeat]', ['ng-repeat']) | 85 new DirectiveInfo('[ng-repeat]', ['ng-repeat']) |
| 86 ]); | 86 ], ioService); |
| 87 extractor.crawl('/', ioService); | 87 extractor.crawl('/'); |
| 88 // Basically we don't want to extract "foo in ctrl.bar". | 88 // Basically we don't want to extract "foo in ctrl.bar". |
| 89 expect(extractor.expressions.toList()..sort(), | 89 expect(extractor.expressions.toList()..sort(), |
| 90 equals(['ctrl.bar'])); | 90 equals(['ctrl.bar'])); |
| 91 }); | 91 }); |
| 92 }); | 92 }); |
| OLD | NEW |