| OLD | NEW |
| (Empty) | |
| 1 library templateurl_spec; |
| 2 |
| 3 import '../_specs.dart'; |
| 4 |
| 5 @NgComponent( |
| 6 selector: 'simple-url', |
| 7 templateUrl: 'simple.html') |
| 8 class SimpleUrlComponent { |
| 9 } |
| 10 |
| 11 @NgComponent( |
| 12 selector: 'html-and-css', |
| 13 templateUrl: 'simple.html', |
| 14 cssUrl: 'simple.css') |
| 15 class HtmlAndCssComponent { |
| 16 } |
| 17 |
| 18 @NgComponent( |
| 19 selector: 'html-and-css', |
| 20 templateUrl: 'simple.html', |
| 21 cssUrls: const ['simple.css', 'another.css']) |
| 22 class HtmlAndMultipleCssComponent { |
| 23 } |
| 24 |
| 25 @NgComponent( |
| 26 selector: 'inline-with-css', |
| 27 template: '<div>inline!</div>', |
| 28 cssUrl: 'simple.css') |
| 29 class InlineWithCssComponent { |
| 30 } |
| 31 |
| 32 @NgComponent( |
| 33 selector: 'only-css', |
| 34 cssUrl: 'simple.css') |
| 35 class OnlyCssComponent { |
| 36 } |
| 37 |
| 38 class PrefixedUrlRewriter extends UrlRewriter { |
| 39 call(url) => "PREFIX:$url"; |
| 40 } |
| 41 |
| 42 main() => describe('template url', () { |
| 43 afterEach(inject((MockHttpBackend backend) { |
| 44 backend.verifyNoOutstandingRequest(); |
| 45 })); |
| 46 |
| 47 describe('loading with http rewriting', () { |
| 48 beforeEach(module((Module module) { |
| 49 module |
| 50 ..type(HtmlAndCssComponent) |
| 51 ..type(UrlRewriter, implementedBy: PrefixedUrlRewriter); |
| 52 })); |
| 53 |
| 54 it('should use the UrlRewriter for both HTML and CSS URLs', async(inject((Ht
tp $http, |
| 55 Compiler $compile, Scope $rootScope, Logger log, Injector injector, Ng
Zone zone, |
| 56 MockHttpBackend backend) { |
| 57 |
| 58 backend.whenGET('PREFIX:simple.html').respond('<div log="SIMPLE">Simple!</
div>'); |
| 59 backend.whenGET('PREFIX:simple.css').respond('.hello{}'); |
| 60 |
| 61 var element = $('<div><html-and-css log>ignore</html-and-css><div>'); |
| 62 zone.run(() { |
| 63 $compile(element)(injector, element); |
| 64 }); |
| 65 |
| 66 backend.flush(); |
| 67 microLeap(); |
| 68 |
| 69 expect(renderedText(element)).toEqual('.hello{}Simple!'); |
| 70 expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual( |
| 71 '<style>.hello{}</style><div log="SIMPLE">Simple!</div>' |
| 72 ); |
| 73 }))); |
| 74 }); |
| 75 |
| 76 |
| 77 describe('async template loading', () { |
| 78 beforeEach(module((Module module) { |
| 79 module.type(LogAttrDirective); |
| 80 module.type(SimpleUrlComponent); |
| 81 module.type(HtmlAndCssComponent); |
| 82 module.type(OnlyCssComponent); |
| 83 module.type(InlineWithCssComponent); |
| 84 })); |
| 85 |
| 86 it('should replace element with template from url', async(inject((Http $http
, |
| 87 Compiler $compile, Scope $rootScope, Logger log, Injector injector, |
| 88 MockHttpBackend backend) { |
| 89 backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>'
); |
| 90 |
| 91 var element = $('<div><simple-url log>ignore</simple-url><div>'); |
| 92 $compile(element)(injector, element); |
| 93 |
| 94 backend.flush(); |
| 95 microLeap(); |
| 96 |
| 97 expect(renderedText(element)).toEqual('Simple!'); |
| 98 $rootScope.$digest(); |
| 99 // Note: There is no ordering. It is who ever comes off the wire first! |
| 100 expect(log.result()).toEqual('LOG; SIMPLE'); |
| 101 }))); |
| 102 |
| 103 it('should load template from URL once', async(inject((Http $http, |
| 104 Compiler $compile, Scope $rootScope, Logger log, Injector injector, |
| 105 MockHttpBackend backend) { |
| 106 backend.whenGET('simple.html').respond('<div log="SIMPLE">Simple!</div>'); |
| 107 |
| 108 var element = $( |
| 109 '<div>' + |
| 110 '<simple-url log>ignore</simple-url>' + |
| 111 '<simple-url log>ignore</simple-url>' + |
| 112 '<div>'); |
| 113 $compile(element)(injector, element); |
| 114 |
| 115 backend.flush(); |
| 116 microLeap(); |
| 117 |
| 118 expect(renderedText(element)).toEqual('Simple!Simple!'); |
| 119 $rootScope.$digest(); |
| 120 // Note: There is no ordering. It is who ever comes off the wire first! |
| 121 expect(log.result()).toEqual('LOG; LOG; SIMPLE; SIMPLE'); |
| 122 }))); |
| 123 |
| 124 it('should load a CSS file into a style', async(inject((Http $http, |
| 125 Compiler $compile, Scope $rootScope, Logger log, Injector injector, |
| 126 MockHttpBackend backend) { |
| 127 backend.expectGET('simple.css').respond('.hello{}'); |
| 128 backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>'
); |
| 129 |
| 130 var element = $('<div><html-and-css log>ignore</html-and-css><div>'); |
| 131 $compile(element)(injector, element); |
| 132 |
| 133 backend.flush(); |
| 134 microLeap(); |
| 135 |
| 136 expect(renderedText(element)).toEqual('.hello{}Simple!'); |
| 137 expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual( |
| 138 '<style>.hello{}</style><div log="SIMPLE">Simple!</div>' |
| 139 ); |
| 140 $rootScope.$digest(); |
| 141 // Note: There is no ordering. It is who ever comes off the wire first! |
| 142 expect(log.result()).toEqual('LOG; SIMPLE'); |
| 143 }))); |
| 144 |
| 145 it('should load a CSS file with a \$template', async(inject((Http $http, |
| 146 Compiler $compile, Scope $rootScope, Injector injector, MockHttpBacke
nd backend) { |
| 147 var element = $('<div><inline-with-css log>ignore</inline-with-css><div>')
; |
| 148 backend.expectGET('simple.css').respond('.hello{}'); |
| 149 $compile(element)(injector, element); |
| 150 |
| 151 backend.flush(); |
| 152 microLeap(); |
| 153 expect(renderedText(element)).toEqual('.hello{}inline!'); |
| 154 }))); |
| 155 |
| 156 it('should load a CSS with no template', async(inject((Http $http, |
| 157 Compiler $compile, Scope $rootScope, Injector injector, MockHttpBacken
d backend) { |
| 158 var element = $('<div><only-css log>ignore</only-css><div>'); |
| 159 backend.expectGET('simple.css').respond('.hello{}'); |
| 160 $compile(element)(injector, element); |
| 161 |
| 162 backend.flush(); |
| 163 microLeap(); |
| 164 expect(renderedText(element)).toEqual('.hello{}'); |
| 165 }))); |
| 166 |
| 167 it('should load the CSS before the template is loaded', async(inject((Http $
http, |
| 168 Compiler $compile, Scope $rootScope, Injector injector, MockHttpBacken
d backend) { |
| 169 backend.expectGET('simple.css').respond('.hello{}'); |
| 170 backend.expectGET('simple.html').respond('<div>Simple!</div>'); |
| 171 |
| 172 var element = $('<html-and-css>ignore</html-and-css>'); |
| 173 $compile(element)(injector, element); |
| 174 |
| 175 backend.flush(); |
| 176 microLeap(); |
| 177 expect(renderedText(element)).toEqual('.hello{}Simple!'); |
| 178 }))); |
| 179 }); |
| 180 |
| 181 describe('multiple css loading', () { |
| 182 beforeEach(module((Module module) { |
| 183 module.type(LogAttrDirective); |
| 184 module.type(HtmlAndMultipleCssComponent); |
| 185 })); |
| 186 |
| 187 it('should load multiple CSS files into a style', async(inject((Http $http, |
| 188 Compiler $compile, Scope $rootScope, Logger log, Injector injector, |
| 189 MockHttpBackend backend) { |
| 190 backend.expectGET('simple.css').respond('.hello{}'); |
| 191 backend.expectGET('another.css').respond('.world{}'); |
| 192 backend.expectGET('simple.html').respond('<div log="SIMPLE">Simple!</div>'
); |
| 193 |
| 194 var element = $('<div><html-and-css log>ignore</html-and-css><div>'); |
| 195 $compile(element)(injector, element); |
| 196 |
| 197 backend.flush(); |
| 198 microLeap(); |
| 199 |
| 200 expect(renderedText(element)).toEqual('.hello{}.world{}Simple!'); |
| 201 expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual( |
| 202 '<style>.hello{}.world{}</style><div log="SIMPLE">Simple!</div>' |
| 203 ); |
| 204 $rootScope.$digest(); |
| 205 // Note: There is no ordering. It is who ever comes off the wire first! |
| 206 expect(log.result()).toEqual('LOG; SIMPLE'); |
| 207 }))); |
| 208 }); |
| 209 }); |
| OLD | NEW |