import { AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachBindings, ddescribe, xdescribe, describe, el, expect, iit, inject, it, xit, } from 'angular2/test_lib'; import {List, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection'; import {Component, View, NgFor, bind} from 'angular2/angular2'; import {NgClass} from 'angular2/src/directives/ng_class'; import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool'; function detectChangesAndCheck(rootTC, classes: string, elIndex: number = 0) { rootTC.detectChanges(); expect(rootTC.componentViewChildren[elIndex].nativeElement.className).toEqual(classes); } export function main() { describe('binding to CSS class list', () => { 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) => { var template = '
'; tcb.overrideTemplate(TestComponent, template) .createAsync(TestComponent) .then((rootTC) => { rootTC.componentInstance.items = [['0']]; rootTC.detectChanges(); rootTC.componentInstance.items = [['1']]; detectChangesAndCheck(rootTC, 'ng-binding 1', 1); async.done(); }); })); }); describe('expressions evaluating to objects', () => { it('should add classes specified in an object literal', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { var template = ''; tcb.overrideTemplate(TestComponent, template) .createAsync(TestComponent) .then((rootTC) => { detectChangesAndCheck(rootTC, 'ng-binding foo'); async.done(); }); })); it('should add classes specified in an object literal without change in class names', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { var template = ``; tcb.overrideTemplate(TestComponent, template) .createAsync(TestComponent) .then((rootTC) => { detectChangesAndCheck(rootTC, 'ng-binding foo-bar fooBar'); async.done(); }); })); it('should add and remove classes based on changes in object literal values', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { var template = ''; tcb.overrideTemplate(TestComponent, template) .createAsync(TestComponent) .then((rootTC) => { detectChangesAndCheck(rootTC, 'ng-binding foo'); rootTC.componentInstance.condition = false; detectChangesAndCheck(rootTC, 'ng-binding bar'); async.done(); }); })); it('should add and remove classes based on changes to the expression object', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { var template = ''; tcb.overrideTemplate(TestComponent, template) .createAsync(TestComponent) .then((rootTC) => { detectChangesAndCheck(rootTC, 'ng-binding foo'); StringMapWrapper.set(rootTC.componentInstance.objExpr, 'bar', true); detectChangesAndCheck(rootTC, 'ng-binding foo bar'); StringMapWrapper.set(rootTC.componentInstance.objExpr, 'baz', true); detectChangesAndCheck(rootTC, 'ng-binding foo bar baz'); StringMapWrapper.delete(rootTC.componentInstance.objExpr, 'bar'); detectChangesAndCheck(rootTC, 'ng-binding foo baz'); async.done(); }); })); it('should add and remove classes based on reference changes to the expression object', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { var template = ''; tcb.overrideTemplate(TestComponent, template) .createAsync(TestComponent) .then((rootTC) => { detectChangesAndCheck(rootTC, 'ng-binding foo'); rootTC.componentInstance.objExpr = {foo: true, bar: true}; detectChangesAndCheck(rootTC, 'ng-binding foo bar'); rootTC.componentInstance.objExpr = {baz: true}; detectChangesAndCheck(rootTC, 'ng-binding baz'); async.done(); }); })); }); describe('expressions evaluating to lists', () => { it('should add classes specified in a list literal', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { var template = ``; tcb.overrideTemplate(TestComponent, template) .createAsync(TestComponent) .then((rootTC) => { detectChangesAndCheck(rootTC, 'ng-binding foo bar foo-bar fooBar'); async.done(); }); })); it('should add and remove classes based on changes to the expression', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { var template = ''; tcb.overrideTemplate(TestComponent, template) .createAsync(TestComponent) .then((rootTC) => { var arrExpr: List