| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 12:41:49 -07:00
										 |  |  | import {NgClass, NgFor} from '@angular/common'; | 
					
						
							| 
									
										
										
										
											2016-07-11 15:27:57 -07:00
										 |  |  | import {Component} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-07-11 16:04:32 -07:00
										 |  |  | import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing'; | 
					
						
							| 
									
										
										
										
											2016-07-11 15:27:57 -07:00
										 |  |  | import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; | 
					
						
							|  |  |  | import {ListWrapper, StringMapWrapper} from '../../src/facade/collection'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-30 10:52:04 -07:00
										 |  |  | function detectChangesAndCheck(fixture: ComponentFixture<any>, classes: string) { | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |   fixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2016-01-13 21:35:21 -08:00
										 |  |  |   expect(fixture.debugElement.children[0].nativeElement.className).toEqual(classes); | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | export function main() { | 
					
						
							|  |  |  |   describe('binding to CSS class list', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     it('should clean up when the directive is destroyed', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |              var template = '<div *ngFor="let item of items" [ngClass]="item"></div>'; | 
					
						
							|  |  |  |              tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                  .createAsync(TestComponent) | 
					
						
							| 
									
										
										
										
											2016-07-11 16:04:32 -07:00
										 |  |  |                  .then((fixture: ComponentFixture<TestComponent>) => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    fixture.debugElement.componentInstance.items = [['0']]; | 
					
						
							|  |  |  |                    fixture.detectChanges(); | 
					
						
							|  |  |  |                    fixture.debugElement.componentInstance.items = [['1']]; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    detectChangesAndCheck(fixture, '1'); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-07-23 16:22:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="{foo: true, bar: false}"></div>'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							|  |  |  |                      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', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = `<div [ngClass]="{'foo-bar': true, 'fooBar': true}"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo-bar fooBar'); | 
					
						
							|  |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-07-24 10:49:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |       it('should add and remove classes based on changes in object literal values', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="{foo: condition, bar: !condition}"></div>'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.condition = false; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes based on changes to the expression object', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="objExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'baz', true); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      StringMapWrapper.delete(fixture.debugElement.componentInstance.objExpr, 'bar'); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes based on reference changes to the expression object', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="objExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = {foo: true, bar: true}; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = {baz: true}; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should remove active classes when expression evaluates to null', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="objExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, ''); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = {'foo': false, 'bar': true}; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'bar'); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should allow multiple classes per expression', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="objExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = { | 
					
						
							|  |  |  |                        'bar baz': true, | 
					
						
							|  |  |  |                        'bar1 baz1': true | 
					
						
							|  |  |  |                      }; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'bar baz bar1 baz1'); | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = { | 
					
						
							|  |  |  |                        'bar baz': false, | 
					
						
							|  |  |  |                        'bar1 baz1': true | 
					
						
							|  |  |  |                      }; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'bar1 baz1'); | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should split by one or more spaces between classes', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="objExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = {'foo bar     baz': true}; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar baz'); | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											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', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = `<div [ngClass]="['foo', 'bar', 'foo-bar', 'fooBar']"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar'); | 
					
						
							|  |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes based on changes to the expression', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="arrExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      var arrExpr: string[] = fixture.debugElement.componentInstance.arrExpr; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      arrExpr.push('bar'); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      arrExpr[1] = 'baz'; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      ListWrapper.remove(fixture.debugElement.componentInstance.arrExpr, 'baz'); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes when a reference changes', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="arrExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.arrExpr = ['bar']; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'bar'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should take initial classes into account when a reference changes', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div class="foo" [ngClass]="arrExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.arrExpr = ['bar']; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar'); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should ignore empty or blank class names', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div class="foo" [ngClass]="arrExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.arrExpr = ['', '  ']; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should trim blanks from class names', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div class="foo" [ngClass]="arrExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.arrExpr = [' bar  ']; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar'); | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should allow multiple classes per item in arrays', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="arrExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.arrExpr = | 
					
						
							|  |  |  |                          ['foo bar baz', 'foo1 bar1   baz1']; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar baz foo1 bar1 baz1'); | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.arrExpr = ['foo bar   baz foobar']; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar baz foobar'); | 
					
						
							| 
									
										
										
										
											2015-11-10 13:30:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 09:50:51 -07:00
										 |  |  |     describe('expressions evaluating to sets', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes if the set instance changed', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="setExpr"></div>'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      var setExpr = new Set<string>(); | 
					
						
							|  |  |  |                      setExpr.add('bar'); | 
					
						
							|  |  |  |                      fixture.debugElement.componentInstance.setExpr = setExpr; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'bar'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                      setExpr = new Set<string>(); | 
					
						
							|  |  |  |                      setExpr.add('baz'); | 
					
						
							|  |  |  |                      fixture.debugElement.componentInstance.setExpr = setExpr; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'baz'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-10-26 09:50:51 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |     describe('expressions evaluating to string', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add classes specified in a string literal', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = `<div [ngClass]="'foo bar foo-bar fooBar'"></div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar'); | 
					
						
							|  |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should add and remove classes based on changes to the expression', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="strExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.strExpr = 'foo bar'; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo bar'); | 
					
						
							| 
									
										
										
										
											2015-08-07 17:21:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.strExpr = 'baz'; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'baz'); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-07-08 17:41:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should remove active classes when switching from string to null', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = `<div [ngClass]="strExpr"></div>`; | 
					
						
							| 
									
										
										
										
											2015-07-08 17:41:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-07-08 17:41:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.strExpr = null; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, ''); | 
					
						
							| 
									
										
										
										
											2015-07-08 17:41:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should take initial classes into account when switching from string to null', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = `<div class="foo" [ngClass]="strExpr"></div>`; | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.strExpr = null; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  |       it('should ignore empty and blank strings', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = `<div class="foo" [ngClass]="strExpr"></div>`; | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      fixture.debugElement.componentInstance.strExpr = ''; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'foo'); | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-09-14 14:11:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div [ngClass]="objExpr" class="init foo"></div>'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init foo bar'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'foo', false); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init bar'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init foo'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should co-operate with the interpolated class attribute', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = `<div [ngClass]="objExpr" class="{{'init foo'}}"></div>`; | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, `init foo bar`); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'foo', false); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, `init bar`); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, `init foo`); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should co-operate with the class attribute and binding to it', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = `<div [ngClass]="objExpr" class="init" [class]="'foo'"></div>`; | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, `init foo bar`); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'foo', false); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, `init bar`); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, `init foo`); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      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', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = | 
					
						
							|  |  |  |                    '<div class="init foo" [ngClass]="objExpr" [class.baz]="condition"></div>'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init foo baz'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init foo baz bar'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'foo', false); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init baz bar'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.condition = false; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init bar'); | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07: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', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                var template = '<div class="init" [ngClass]="objExpr" [class]="strExpr"></div>'; | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                tcb.overrideTemplate(TestComponent, template) | 
					
						
							|  |  |  |                    .createAsync(TestComponent) | 
					
						
							|  |  |  |                    .then((fixture) => { | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init foo'); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      StringMapWrapper.set( | 
					
						
							|  |  |  |                          fixture.debugElement.componentInstance.objExpr, 'bar', true); | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init foo bar'); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.strExpr = 'baz'; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init bar baz foo'); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      fixture.debugElement.componentInstance.objExpr = null; | 
					
						
							|  |  |  |                      detectChangesAndCheck(fixture, 'init baz'); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2015-08-10 12:25:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({selector: 'test-cmp', directives: [NgClass, NgFor], template: ''}) | 
					
						
							| 
									
										
										
										
											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-08-28 11:29:19 -07:00
										 |  |  |   arrExpr: string[] = ['foo']; | 
					
						
							| 
									
										
										
										
											2015-10-26 09:50:51 -07:00
										 |  |  |   setExpr: Set<string> = new Set<string>(); | 
					
						
							| 
									
										
										
										
											2015-06-21 11:54:21 +02:00
										 |  |  |   objExpr = {'foo': true, 'bar': false}; | 
					
						
							|  |  |  |   strExpr = 'foo'; | 
					
						
							| 
									
										
										
										
											2015-10-26 09:50:51 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   constructor() { this.setExpr.add('foo'); } | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | } |