| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | import { | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |   TestComponentBuilder, | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  |   beforeEach, | 
					
						
							|  |  |  |   beforeEachBindings, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   xdescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   el, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   xit, | 
					
						
							| 
									
										
										
										
											2015-10-13 00:29:13 -07:00
										 |  |  | } from 'angular2/testing_internal'; | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-06 17:34:07 -08:00
										 |  |  | import {StringMapWrapper} from 'angular2/src/facade/collection'; | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import {Component, View} from 'angular2/angular2'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-20 14:28:25 -07:00
										 |  |  | import {DOM} from 'angular2/src/core/dom/dom_adapter'; | 
					
						
							| 
									
										
										
										
											2015-11-05 14:58:24 -08:00
										 |  |  | import {NgStyle} from 'angular2/src/common/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', | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-07-29 18:34:02 +02:00
										 |  |  |          var template = `<div [ng-style]="{'max-width': '40px'}"></div>`; | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |          tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |              .createAsync(TestComponent) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((fixture) => { | 
					
						
							|  |  |  |                fixture.detectChanges(); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'max-width')) | 
					
						
							| 
									
										
										
										
											2015-07-29 18:34:02 +02:00
										 |  |  |                    .toEqual('40px'); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should add and change styles specified in an object expression', | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  |          var template = `<div [ng-style]="expr"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |          tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |              .createAsync(TestComponent) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((fixture) => { | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  |                var expr: Map<string, any>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                fixture.debugElement.componentInstance.expr = {'max-width': '40px'}; | 
					
						
							|  |  |  |                fixture.detectChanges(); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'max-width')) | 
					
						
							| 
									
										
										
										
											2015-07-29 18:34:02 +02:00
										 |  |  |                    .toEqual('40px'); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                expr = fixture.debugElement.componentInstance.expr; | 
					
						
							| 
									
										
										
										
											2015-07-29 18:34:02 +02:00
										 |  |  |                expr['max-width'] = '30%'; | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                fixture.detectChanges(); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'max-width')) | 
					
						
							| 
									
										
										
										
											2015-07-29 18:34:02 +02:00
										 |  |  |                    .toEqual('30%'); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should remove styles when deleting a key in an object expression', | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  |          var template = `<div [ng-style]="expr"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |          tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |              .createAsync(TestComponent) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((fixture) => { | 
					
						
							|  |  |  |                fixture.debugElement.componentInstance.expr = {'max-width': '40px'}; | 
					
						
							|  |  |  |                fixture.detectChanges(); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'max-width')) | 
					
						
							| 
									
										
										
										
											2015-07-29 18:34:02 +02:00
										 |  |  |                    .toEqual('40px'); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                StringMapWrapper.delete(fixture.debugElement.componentInstance.expr, 'max-width'); | 
					
						
							|  |  |  |                fixture.detectChanges(); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'max-width')) | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |                    .toEqual(''); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should co-operate with the style attribute', | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  |          var template = `<div style="font-size: 12px" [ng-style]="expr"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |          tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |              .createAsync(TestComponent) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((fixture) => { | 
					
						
							|  |  |  |                fixture.debugElement.componentInstance.expr = {'max-width': '40px'}; | 
					
						
							|  |  |  |                fixture.detectChanges(); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'max-width')) | 
					
						
							| 
									
										
										
										
											2015-07-29 18:34:02 +02:00
										 |  |  |                    .toEqual('40px'); | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'font-size')) | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |                    .toEqual('12px'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                StringMapWrapper.delete(fixture.debugElement.componentInstance.expr, 'max-width'); | 
					
						
							|  |  |  |                fixture.detectChanges(); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'max-width')) | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |                    .toEqual(''); | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'font-size')) | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |                    .toEqual('12px'); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should co-operate with the style.[styleName]="expr" special-case in the compiler', | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |        inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  |          var template = `<div [style.font-size.px]="12" [ng-style]="expr"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |          tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |              .createAsync(TestComponent) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((fixture) => { | 
					
						
							|  |  |  |                fixture.debugElement.componentInstance.expr = {'max-width': '40px'}; | 
					
						
							|  |  |  |                fixture.detectChanges(); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'max-width')) | 
					
						
							| 
									
										
										
										
											2015-07-29 18:34:02 +02:00
										 |  |  |                    .toEqual('40px'); | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'font-size')) | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |                    .toEqual('12px'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                StringMapWrapper.delete(fixture.debugElement.componentInstance.expr, 'max-width'); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'font-size')) | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |                    .toEqual('12px'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                fixture.detectChanges(); | 
					
						
							|  |  |  |                expect(DOM.getStyle(fixture.debugElement.componentViewChildren[0].nativeElement, | 
					
						
							| 
									
										
										
										
											2015-09-11 13:45:31 -07:00
										 |  |  |                                    'max-width')) | 
					
						
							| 
									
										
										
										
											2015-06-26 16:16:19 -07:00
										 |  |  |                    .toEqual(''); | 
					
						
							| 
									
										
										
										
											2015-06-21 14:18:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'test-cmp'}) | 
					
						
							|  |  |  | @View({directives: [NgStyle]}) | 
					
						
							|  |  |  | class TestComponent { | 
					
						
							|  |  |  |   expr; | 
					
						
							|  |  |  | } |