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