| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   xdescribe, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   beforeEach, | 
					
						
							|  |  |  |   afterEach, | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |   inject, | 
					
						
							|  |  |  |   beforeEachBindings | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | } from 'angular2/test_lib'; | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | import {bind} from 'angular2/src/core/di'; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | import {SpyXHR} from '../core/spies'; | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | import {XHR} from 'angular2/src/core/render/xhr'; | 
					
						
							| 
									
										
										
										
											2015-09-10 15:25:36 -07:00
										 |  |  | import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions'; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  | import {CONST_EXPR, isPresent, isBlank, StringWrapper} from 'angular2/src/core/facade/lang'; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | import {PromiseWrapper, Promise} from 'angular2/src/core/facade/async'; | 
					
						
							|  |  |  | import {evalModule} from './eval_module'; | 
					
						
							|  |  |  | import {StyleCompiler} from 'angular2/src/compiler/style_compiler'; | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |   CompileDirectiveMetadata, | 
					
						
							|  |  |  |   CompileTemplateMetadata, | 
					
						
							|  |  |  |   CompileTypeMetadata | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | } from 'angular2/src/compiler/directive_metadata'; | 
					
						
							|  |  |  | import {SourceExpression, SourceModule} from 'angular2/src/compiler/source_module'; | 
					
						
							| 
									
										
										
										
											2015-09-11 13:37:05 -07:00
										 |  |  | import {ViewEncapsulation} from 'angular2/src/core/render/api'; | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | import {TEST_BINDINGS} from './test_bindings'; | 
					
						
							|  |  |  | import {codeGenValueFn, codeGenExportVariable} from 'angular2/src/compiler/util'; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Attention: These module names have to correspond to real modules!
 | 
					
						
							|  |  |  | const MODULE_NAME = 'angular2/test/compiler/style_compiler_spec'; | 
					
						
							|  |  |  | const IMPORT_ABS_MODULE_NAME = 'angular2/test/compiler/style_compiler_import'; | 
					
						
							|  |  |  | const IMPORT_REL_MODULE_NAME = './style_compiler_import'; | 
					
						
							|  |  |  | // Note: Not a real module, only used via mocks.
 | 
					
						
							|  |  |  | const IMPORT_ABS_MODULE_NAME_WITH_IMPORT = | 
					
						
							|  |  |  |     'angular2/test/compiler/style_compiler_transitive_import'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('StyleCompiler', () => { | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |     var xhr: SpyXHR; | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |     var templateId; | 
					
						
							|  |  |  |     var appId; | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |     beforeEachBindings(() => { | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |       xhr = <any>new SpyXHR(); | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |       return [TEST_BINDINGS, bind(XHR).toValue(xhr)]; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |     var compiler: StyleCompiler; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |     beforeEach(inject([StyleCompiler], (_compiler) => { | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |       templateId = 23; | 
					
						
							|  |  |  |       appId = 'app1'; | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       compiler = _compiler; | 
					
						
							|  |  |  |     })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe('compileComponentRuntime', () => { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       var xhrUrlResults; | 
					
						
							|  |  |  |       var xhrCount; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       beforeEach(() => { | 
					
						
							|  |  |  |         xhrCount = 0; | 
					
						
							|  |  |  |         xhrUrlResults = {}; | 
					
						
							|  |  |  |         xhrUrlResults[IMPORT_ABS_MODULE_NAME] = 'span {color: blue}'; | 
					
						
							|  |  |  |         xhrUrlResults[IMPORT_ABS_MODULE_NAME_WITH_IMPORT] = | 
					
						
							|  |  |  |             `a {color: green}@import ${IMPORT_REL_MODULE_NAME};`; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       function compile(styles: string[], styleAbsUrls: string[], encapsulation: ViewEncapsulation): | 
					
						
							|  |  |  |           Promise<string[]> { | 
					
						
							|  |  |  |         // Note: Can't use MockXHR as the xhr is called recursively,
 | 
					
						
							|  |  |  |         // so we can't trigger flush.
 | 
					
						
							|  |  |  |         xhr.spy('get').andCallFake((url) => { | 
					
						
							|  |  |  |           var response = xhrUrlResults[url]; | 
					
						
							|  |  |  |           xhrCount++; | 
					
						
							|  |  |  |           if (isBlank(response)) { | 
					
						
							|  |  |  |             throw new BaseException(`Unexpected url ${url}`); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           return PromiseWrapper.resolve(response); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         return compiler.compileComponentRuntime( | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |             appId, templateId, | 
					
						
							|  |  |  |             new CompileTemplateMetadata( | 
					
						
							|  |  |  |                 {styles: styles, styleUrls: styleAbsUrls, encapsulation: encapsulation})); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe('no shim', () => { | 
					
						
							|  |  |  |         var encapsulation = ViewEncapsulation.None; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         it('should compile plain css rules', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div {color: red}', 'span {color: blue}'], [], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							|  |  |  |                    expect(styles).toEqual(['div {color: red}', 'span {color: blue}']); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         it('should allow to import rules', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div {color: red}'], [IMPORT_ABS_MODULE_NAME], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							|  |  |  |                    expect(styles).toEqual(['div {color: red}', 'span {color: blue}']); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         it('should allow to import rules transitively', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div {color: red}'], [IMPORT_ABS_MODULE_NAME_WITH_IMPORT], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							|  |  |  |                    expect(styles) | 
					
						
							|  |  |  |                        .toEqual(['div {color: red}', 'a {color: green}', 'span {color: blue}']); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe('with shim', () => { | 
					
						
							|  |  |  |         var encapsulation = ViewEncapsulation.Emulated; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         it('should compile plain css rules', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div {\ncolor: red;\n}', 'span {\ncolor: blue;\n}'], [], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |                    compareStyles(styles, [ | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |                      'div[_ngcontent-app1-23] {\ncolor: red;\n}', | 
					
						
							|  |  |  |                      'span[_ngcontent-app1-23] {\ncolor: blue;\n}' | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                    ]); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('should allow to import rules', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div {\ncolor: red;\n}'], [IMPORT_ABS_MODULE_NAME], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |                    compareStyles(styles, [ | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |                      'div[_ngcontent-app1-23] {\ncolor: red;\n}', | 
					
						
							|  |  |  |                      'span[_ngcontent-app1-23] {\ncolor: blue;\n}' | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                    ]); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('should allow to import rules transitively', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div {\ncolor: red;\n}'], [IMPORT_ABS_MODULE_NAME_WITH_IMPORT], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |                    compareStyles(styles, [ | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |                      'div[_ngcontent-app1-23] {\ncolor: red;\n}', | 
					
						
							|  |  |  |                      'a[_ngcontent-app1-23] {\ncolor: green;\n}', | 
					
						
							|  |  |  |                      'span[_ngcontent-app1-23] {\ncolor: blue;\n}' | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                    ]); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should cache stylesheets for parallel requests', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |            PromiseWrapper.all([ | 
					
						
							|  |  |  |                            compile([], [IMPORT_ABS_MODULE_NAME], ViewEncapsulation.None), | 
					
						
							|  |  |  |                            compile([], [IMPORT_ABS_MODULE_NAME], ViewEncapsulation.None) | 
					
						
							|  |  |  |                          ]) | 
					
						
							|  |  |  |                .then((styleArrays) => { | 
					
						
							|  |  |  |                  expect(styleArrays[0]).toEqual(['span {color: blue}']); | 
					
						
							|  |  |  |                  expect(styleArrays[1]).toEqual(['span {color: blue}']); | 
					
						
							|  |  |  |                  expect(xhrCount).toBe(1); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should cache stylesheets for serial requests', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |            compile([], [IMPORT_ABS_MODULE_NAME], ViewEncapsulation.None) | 
					
						
							|  |  |  |                .then((styles0) => { | 
					
						
							|  |  |  |                  xhrUrlResults[IMPORT_ABS_MODULE_NAME] = 'span {color: black}'; | 
					
						
							|  |  |  |                  return compile([], [IMPORT_ABS_MODULE_NAME], ViewEncapsulation.None) | 
					
						
							|  |  |  |                      .then((styles1) => { | 
					
						
							|  |  |  |                        expect(styles0).toEqual(['span {color: blue}']); | 
					
						
							|  |  |  |                        expect(styles1).toEqual(['span {color: blue}']); | 
					
						
							|  |  |  |                        expect(xhrCount).toBe(1); | 
					
						
							|  |  |  |                        async.done(); | 
					
						
							|  |  |  |                      }); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should allow to clear the cache', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |            compile([], [IMPORT_ABS_MODULE_NAME], ViewEncapsulation.None) | 
					
						
							|  |  |  |                .then((_) => { | 
					
						
							|  |  |  |                  compiler.clearCache(); | 
					
						
							|  |  |  |                  xhrUrlResults[IMPORT_ABS_MODULE_NAME] = 'span {color: black}'; | 
					
						
							|  |  |  |                  return compile([], [IMPORT_ABS_MODULE_NAME], ViewEncapsulation.None); | 
					
						
							|  |  |  |                }) | 
					
						
							|  |  |  |                .then((styles) => { | 
					
						
							|  |  |  |                  expect(xhrCount).toBe(2); | 
					
						
							|  |  |  |                  expect(styles).toEqual(['span {color: black}']); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('compileComponentCodeGen', () => { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       function compile(styles: string[], styleAbsUrls: string[], encapsulation: ViewEncapsulation): | 
					
						
							|  |  |  |           Promise<string[]> { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         var sourceExpression = compiler.compileComponentCodeGen( | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |             `'${appId}'`, `${templateId}`, | 
					
						
							|  |  |  |             new CompileTemplateMetadata( | 
					
						
							|  |  |  |                 {styles: styles, styleUrls: styleAbsUrls, encapsulation: encapsulation})); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         var sourceWithImports = testableExpression(sourceExpression).getSourceWithImports(); | 
					
						
							|  |  |  |         return evalModule(sourceWithImports.source, sourceWithImports.imports, null); | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       describe('no shim', () => { | 
					
						
							|  |  |  |         var encapsulation = ViewEncapsulation.None; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |         it('should compile plain css rules', inject([AsyncTestCompleter], (async) => { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |              compile(['div {color: red}', 'span {color: blue}'], [], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							|  |  |  |                    expect(styles).toEqual(['div {color: red}', 'span {color: blue}']); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         it('should compile css rules with newlines and quotes', | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |            inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div\n{"color": \'red\'}'], [], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							|  |  |  |                    expect(styles).toEqual(['div\n{"color": \'red\'}']); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         it('should allow to import rules', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div {color: red}'], [IMPORT_ABS_MODULE_NAME], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							|  |  |  |                    expect(styles).toEqual(['div {color: red}', 'span {color: blue}']); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |            }), 1000); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe('with shim', () => { | 
					
						
							|  |  |  |         var encapsulation = ViewEncapsulation.Emulated; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         it('should compile plain css ruless', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div {\ncolor: red;\n}', 'span {\ncolor: blue;\n}'], [], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |                    compareStyles(styles, [ | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |                      'div[_ngcontent-app1-23] {\ncolor: red;\n}', | 
					
						
							|  |  |  |                      'span[_ngcontent-app1-23] {\ncolor: blue;\n}' | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                    ]); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         it('should allow to import rules', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |              compile(['div {color: red}'], [IMPORT_ABS_MODULE_NAME], encapsulation) | 
					
						
							|  |  |  |                  .then(styles => { | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |                    compareStyles(styles, [ | 
					
						
							| 
									
										
										
										
											2015-09-28 10:30:33 -07:00
										 |  |  |                      'div[_ngcontent-app1-23] {\ncolor: red;\n}', | 
					
						
							|  |  |  |                      'span[_ngcontent-app1-23] {\ncolor: blue;\n}' | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                    ]); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |            }), 1000); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('compileStylesheetCodeGen', () => { | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |       function compile(style: string): Promise<string[][]> { | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |         var sourceModules = compiler.compileStylesheetCodeGen(MODULE_NAME, style); | 
					
						
							|  |  |  |         return PromiseWrapper.all(sourceModules.map(sourceModule => { | 
					
						
							|  |  |  |           var sourceWithImports = testableModule(sourceModule).getSourceWithImports(); | 
					
						
							|  |  |  |           return evalModule(sourceWithImports.source, sourceWithImports.imports, null); | 
					
						
							|  |  |  |         })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |       it('should compile plain css rules', inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |            compile('div {color: red;}') | 
					
						
							|  |  |  |                .then(stylesAndShimStyles => { | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |                  var expected = | 
					
						
							|  |  |  |                      [['div {color: red;}'], ['div[_ngcontent-%COMP%] {\ncolor: red;\n}']]; | 
					
						
							|  |  |  |                  compareStyles(stylesAndShimStyles[0], expected[0]); | 
					
						
							|  |  |  |                  compareStyles(stylesAndShimStyles[1], expected[1]); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should allow to import rules with relative paths', | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |          inject([AsyncTestCompleter], (async) => { | 
					
						
							|  |  |  |            compile(`div {color: red}@import ${IMPORT_REL_MODULE_NAME};`) | 
					
						
							|  |  |  |                .then(stylesAndShimStyles => { | 
					
						
							| 
									
										
										
										
											2015-09-24 14:34:40 +02:00
										 |  |  |                  var expected = [ | 
					
						
							|  |  |  |                    ['div {color: red}', 'span {color: blue}'], | 
					
						
							|  |  |  |                    [ | 
					
						
							|  |  |  |                      'div[_ngcontent-%COMP%] {\ncolor: red;\n}', | 
					
						
							|  |  |  |                      'span[_ngcontent-%COMP%] {\ncolor: blue;\n}' | 
					
						
							|  |  |  |                    ] | 
					
						
							|  |  |  |                  ]; | 
					
						
							|  |  |  |                  compareStyles(stylesAndShimStyles[0], expected[0]); | 
					
						
							|  |  |  |                  compareStyles(stylesAndShimStyles[1], expected[1]); | 
					
						
							| 
									
										
										
										
											2015-09-18 10:33:23 -07:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | function testableExpression(source: SourceExpression): SourceModule { | 
					
						
							|  |  |  |   var testableSource = `${source.declarations.join('\n')}
 | 
					
						
							|  |  |  |   ${codeGenExportVariable('run')}${codeGenValueFn(['_'], source.expression)};`;
 | 
					
						
							|  |  |  |   return new SourceModule(null, testableSource); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function testableModule(sourceModule: SourceModule): SourceModule { | 
					
						
							| 
									
										
										
										
											2015-09-17 09:58:18 -07:00
										 |  |  |   var testableSource = `${sourceModule.sourceWithModuleRefs}
 | 
					
						
							| 
									
										
										
										
											2015-09-14 15:59:09 -07:00
										 |  |  |   ${codeGenExportVariable('run')}${codeGenValueFn(['_'], 'STYLES')};`;
 | 
					
						
							|  |  |  |   return new SourceModule(sourceModule.moduleId, testableSource); | 
					
						
							| 
									
										
										
										
											2015-09-02 15:07:31 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-09-08 17:36:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Needed for Android browsers which add an extra space at the end of some lines
 | 
					
						
							|  |  |  | function compareStyles(styles: string[], expectedStyles: string[]) { | 
					
						
							|  |  |  |   expect(styles.length).toEqual(expectedStyles.length); | 
					
						
							|  |  |  |   for (var i = 0; i < styles.length; i++) { | 
					
						
							|  |  |  |     expect(StringWrapper.replaceAll(styles[i], /\s+\n/g, '\n')).toEqual(expectedStyles[i]); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |