| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   AsyncTestCompleter, | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |   TestComponentBuilder, | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  |   beforeEach, | 
					
						
							|  |  |  |   beforeEachBindings, | 
					
						
							|  |  |  |   ddescribe, | 
					
						
							|  |  |  |   xdescribe, | 
					
						
							|  |  |  |   describe, | 
					
						
							|  |  |  |   el, | 
					
						
							|  |  |  |   expect, | 
					
						
							|  |  |  |   iit, | 
					
						
							|  |  |  |   inject, | 
					
						
							|  |  |  |   it, | 
					
						
							|  |  |  |   xit, | 
					
						
							|  |  |  | } from 'angular2/test_lib'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | import {List, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection'; | 
					
						
							| 
									
										
										
										
											2015-07-23 16:22:14 -07:00
										 |  |  | import {Component, View, NgFor, bind} from 'angular2/angular2'; | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  | import {NgClass} from 'angular2/src/directives/ng_class'; | 
					
						
							| 
									
										
										
										
											2015-07-23 16:22:14 -07:00
										 |  |  | import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  | function detectChangesAndCheck(rootTC, classes: string, elIndex: number = 0) { | 
					
						
							|  |  |  |   rootTC.detectChanges(); | 
					
						
							|  |  |  |   expect(rootTC.componentViewChildren[elIndex].nativeElement.className).toEqual(classes); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | export function main() { | 
					
						
							|  |  |  |   describe('binding to CSS class list', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:22:14 -07:00
										 |  |  |     describe('viewpool support', () => { | 
					
						
							|  |  |  |       beforeEachBindings(() => { return [bind(APP_VIEW_POOL_CAPACITY).toValue(100)]; }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should clean up when the directive is destroyed', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = '<div *ng-for="var item of items" [ng-class]="item"></div>'; | 
					
						
							| 
									
										
										
										
											2015-07-23 16:22:14 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  rootTC.componentInstance.items = [['0']]; | 
					
						
							|  |  |  |                  rootTC.detectChanges(); | 
					
						
							|  |  |  |                  rootTC.componentInstance.items = [['1']]; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding 1', 1); | 
					
						
							| 
									
										
										
										
											2015-07-23 16:22:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |     describe('expressions evaluating to objects', () => { | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |       it('should add classes specified in an object literal', | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = '<div [ng-class]="{foo: true, bar: false}"></div>'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-24 10:49:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should add classes specified in an object literal without change in class names', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = `<div [ng-class]="{'foo-bar': true, 'fooBar': true}"></div>`; | 
					
						
							| 
									
										
										
										
											2015-07-24 10:49:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo-bar fooBar'); | 
					
						
							| 
									
										
										
										
											2015-07-24 10:49:47 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |       it('should add and remove classes based on changes in object literal values', | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = '<div [ng-class]="{foo: condition, bar: !condition}"></div>'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  rootTC.componentInstance.condition = false; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes based on changes to the expression object', | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = '<div [ng-class]="objExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'baz', true); | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo bar baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  StringMapWrapper.delete(rootTC.componentInstance.objExpr, 'bar'); | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes based on reference changes to the expression object', | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = '<div [ng-class]="objExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  rootTC.componentInstance.objExpr = {foo: true, bar: true}; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  rootTC.componentInstance.objExpr = {baz: true}; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should remove active classes when expression evaluates to null', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							|  |  |  |            var template = '<div [ng-class]="objExpr"></div>'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  rootTC.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  rootTC.componentInstance.objExpr = {'foo': false, 'bar': true}; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding bar'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |     describe('expressions evaluating to lists', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add classes specified in a list literal', | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = `<div [ng-class]="['foo', 'bar', 'foo-bar', 'fooBar']"></div>`; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo bar foo-bar fooBar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes based on changes to the expression', | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = '<div [ng-class]="arrExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  var arrExpr: List<string> = rootTC.componentInstance.arrExpr; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  arrExpr.push('bar'); | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  arrExpr[1] = 'baz'; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  ListWrapper.remove(rootTC.componentInstance.arrExpr, 'baz'); | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes when a reference changes', | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = '<div [ng-class]="arrExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  rootTC.componentInstance.arrExpr = ['bar']; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should take initial classes into account when a reference changes', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							|  |  |  |            var template = '<div class="foo" [ng-class]="arrExpr"></div>'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'foo ng-binding'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  rootTC.componentInstance.arrExpr = ['bar']; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo bar'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe('expressions evaluating to string', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add classes specified in a string literal', | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = `<div [ng-class]="'foo bar foo-bar fooBar'"></div>`; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo bar foo-bar fooBar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes based on changes to the expression', | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = '<div [ng-class]="strExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  rootTC.componentInstance.strExpr = 'foo bar'; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo bar'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  |                  rootTC.componentInstance.strExpr = 'baz'; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-07-08 17:41:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should remove active classes when switching from string to null', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  |            var template = `<div [ng-class]="strExpr"></div>`; | 
					
						
							| 
									
										
										
										
											2015-07-08 17:41:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-07-08 17:41:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  rootTC.componentInstance.strExpr = null; | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding'); | 
					
						
							| 
									
										
										
										
											2015-07-08 17:41:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should take initial classes into account when switching from string to null', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							|  |  |  |            var template = `<div class="foo" [ng-class]="strExpr"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'foo ng-binding'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  rootTC.componentInstance.strExpr = null; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'ng-binding foo'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |     describe('cooperation with other class-changing constructs', () => { | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |       it('should co-operate with the class attribute', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							|  |  |  |            var template = '<div [ng-class]="objExpr" class="init foo"></div>'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init foo ng-binding bar'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'foo', false); | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init ng-binding bar'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  rootTC.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init ng-binding foo'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should co-operate with the interpolated class attribute', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							|  |  |  |            var template = `<div [ng-class]="objExpr" class="{{'init foo'}}"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, `{{'init foo'}} ng-binding init foo bar`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'foo', false); | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, `{{'init foo'}} ng-binding init bar`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  rootTC.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, `{{'init foo'}} ng-binding init foo`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should co-operate with the class attribute and binding to it', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							|  |  |  |            var template = `<div [ng-class]="objExpr" class="init" [class]="'foo'"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, `init ng-binding foo bar`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'foo', false); | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, `init ng-binding bar`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  rootTC.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, `init ng-binding foo`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |       it('should co-operate with the class attribute and class.name binding', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							|  |  |  |            var template = | 
					
						
							|  |  |  |                '<div class="init foo" [ng-class]="objExpr" [class.baz]="condition"></div>'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init foo ng-binding baz'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init foo ng-binding baz bar'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'foo', false); | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init ng-binding baz bar'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  rootTC.componentInstance.condition = false; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init ng-binding bar'); | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |       it('should co-operate with initial class and class attribute binding when binding changes', | 
					
						
							|  |  |  |          inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { | 
					
						
							|  |  |  |            var template = '<div class="init" [ng-class]="objExpr" [class]="strExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |            tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                .createAsync(TestComponent) | 
					
						
							|  |  |  |                .then((rootTC) => { | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init ng-binding foo'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init ng-binding foo bar'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  rootTC.componentInstance.strExpr = 'baz'; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init ng-binding bar baz foo'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  |                  rootTC.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                  detectChangesAndCheck(rootTC, 'init ng-binding baz'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |          })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'test-cmp'}) | 
					
						
							| 
									
										
										
										
											2015-08-06 10:38:40 +02:00
										 |  |  | @View({directives: [NgClass, NgFor]}) | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | class TestComponent { | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |   condition: boolean = true; | 
					
						
							| 
									
										
										
										
											2015-07-23 16:22:14 -07:00
										 |  |  |   items: any[]; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |   arrExpr: List<string> = ['foo']; | 
					
						
							|  |  |  |   objExpr = {'foo': true, 'bar': false}; | 
					
						
							|  |  |  |   strExpr = 'foo'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | } |