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