| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | import {beforeEach, beforeEachProviders, ddescribe, xdescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'; | 
					
						
							|  |  |  | import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {StringMapWrapper} from '../../src/facade/collection'; | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {Component} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; | 
					
						
							|  |  |  | import {NgStyle} from '@angular/common/src/directives/ng_style'; | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('binding to CSS styles', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should add styles specified in an object literal', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |              var template = `<div [ngStyle]="{'max-width': '40px'}"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                  .createAsync(TestComponent) | 
					
						
							|  |  |  |                  .then((fixture) => { | 
					
						
							|  |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'max-width')) | 
					
						
							|  |  |  |                        .toEqual('40px'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should add and change styles specified in an object expression', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |              var template = `<div [ngStyle]="expr"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                  .createAsync(TestComponent) | 
					
						
							|  |  |  |                  .then((fixture) => { | 
					
						
							|  |  |  |                    var expr: Map<string, any>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    fixture.debugElement.componentInstance.expr = {'max-width': '40px'}; | 
					
						
							|  |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'max-width')) | 
					
						
							|  |  |  |                        .toEqual('40px'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    expr = fixture.debugElement.componentInstance.expr; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:23:37 -07:00
										 |  |  |                    (expr as any)['max-width'] = '30%'; | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'max-width')) | 
					
						
							|  |  |  |                        .toEqual('30%'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should remove styles when deleting a key in an object expression', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |              var template = `<div [ngStyle]="expr"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                  .createAsync(TestComponent) | 
					
						
							|  |  |  |                  .then((fixture) => { | 
					
						
							|  |  |  |                    fixture.debugElement.componentInstance.expr = {'max-width': '40px'}; | 
					
						
							|  |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'max-width')) | 
					
						
							|  |  |  |                        .toEqual('40px'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    StringMapWrapper.delete( | 
					
						
							|  |  |  |                        fixture.debugElement.componentInstance.expr, 'max-width'); | 
					
						
							|  |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'max-width')) | 
					
						
							|  |  |  |                        .toEqual(''); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should co-operate with the style attribute', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |              var template = `<div style="font-size: 12px" [ngStyle]="expr"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                  .createAsync(TestComponent) | 
					
						
							|  |  |  |                  .then((fixture) => { | 
					
						
							|  |  |  |                    fixture.debugElement.componentInstance.expr = {'max-width': '40px'}; | 
					
						
							|  |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'max-width')) | 
					
						
							|  |  |  |                        .toEqual('40px'); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'font-size')) | 
					
						
							|  |  |  |                        .toEqual('12px'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    StringMapWrapper.delete( | 
					
						
							|  |  |  |                        fixture.debugElement.componentInstance.expr, 'max-width'); | 
					
						
							|  |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'max-width')) | 
					
						
							|  |  |  |                        .toEqual(''); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'font-size')) | 
					
						
							|  |  |  |                        .toEqual('12px'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should co-operate with the style.[styleName]="expr" special-case in the compiler', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |              var template = `<div [style.font-size.px]="12" [ngStyle]="expr"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                  .createAsync(TestComponent) | 
					
						
							|  |  |  |                  .then((fixture) => { | 
					
						
							|  |  |  |                    fixture.debugElement.componentInstance.expr = {'max-width': '40px'}; | 
					
						
							|  |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'max-width')) | 
					
						
							|  |  |  |                        .toEqual('40px'); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'font-size')) | 
					
						
							|  |  |  |                        .toEqual('12px'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    StringMapWrapper.delete( | 
					
						
							|  |  |  |                        fixture.debugElement.componentInstance.expr, 'max-width'); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'font-size')) | 
					
						
							|  |  |  |                        .toEqual('12px'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(getDOM().getStyle( | 
					
						
							|  |  |  |                               fixture.debugElement.children[0].nativeElement, 'max-width')) | 
					
						
							|  |  |  |                        .toEqual(''); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({selector: 'test-cmp', directives: [NgStyle], template: ''}) | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | class TestComponent { | 
					
						
							| 
									
										
										
										
											2016-06-11 21:23:37 -07:00
										 |  |  |   expr: any; | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | } |