2015-05-26 17:22:35 -04:00
|
|
|
import {
|
2015-10-31 12:50:19 -04:00
|
|
|
ComponentFixture,
|
2015-05-26 17:22:35 -04:00
|
|
|
AsyncTestCompleter,
|
2015-06-24 16:07:15 -04:00
|
|
|
TestComponentBuilder,
|
2015-05-26 17:22:35 -04:00
|
|
|
beforeEach,
|
|
|
|
beforeEachBindings,
|
|
|
|
ddescribe,
|
|
|
|
xdescribe,
|
|
|
|
describe,
|
|
|
|
el,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
xit,
|
2015-10-13 03:29:13 -04:00
|
|
|
} from 'angular2/testing_internal';
|
2015-10-26 12:50:51 -04:00
|
|
|
import {ListWrapper, StringMapWrapper, SetWrapper} from 'angular2/src/core/facade/collection';
|
2015-10-11 01:11:13 -04:00
|
|
|
import {Component, View, NgFor, provide} from 'angular2/angular2';
|
2015-11-05 17:58:24 -05:00
|
|
|
import {NgClass} from 'angular2/src/common/directives/ng_class';
|
2015-10-02 10:37:23 -04:00
|
|
|
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
function detectChangesAndCheck(fixture: ComponentFixture, classes: string, elIndex: number = 0) {
|
|
|
|
fixture.detectChanges();
|
|
|
|
expect(fixture.debugElement.componentViewChildren[elIndex].nativeElement.className)
|
2015-09-11 16:45:31 -04:00
|
|
|
.toEqual(classes);
|
2015-08-07 11:21:57 -04:00
|
|
|
}
|
|
|
|
|
2015-05-26 17:22:35 -04:00
|
|
|
export function main() {
|
|
|
|
describe('binding to CSS class list', () => {
|
|
|
|
|
2015-07-23 19:22:14 -04:00
|
|
|
describe('viewpool support', () => {
|
2015-10-12 14:30:34 -04:00
|
|
|
beforeEachBindings(() => { return [provide(APP_VIEW_POOL_CAPACITY, {useValue: 100})]; });
|
2015-07-23 19:22:14 -04:00
|
|
|
|
|
|
|
it('should clean up when the directive is destroyed',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = '<div *ng-for="var item of items" [ng-class]="item"></div>';
|
2015-07-23 19:22:14 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
fixture.debugElement.componentInstance.items = [['0']];
|
|
|
|
fixture.detectChanges();
|
|
|
|
fixture.debugElement.componentInstance.items = [['1']];
|
2015-08-07 11:21:57 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
detectChangesAndCheck(fixture, '1', 1);
|
2015-07-23 19:22:14 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-06-21 05:54:21 -04:00
|
|
|
describe('expressions evaluating to objects', () => {
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-06-21 05:54:21 -04:00
|
|
|
it('should add classes specified in an object literal',
|
2015-06-24 16:07:15 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = '<div [ng-class]="{foo: true, bar: false}"></div>';
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-06-24 16:07:15 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-06-21 05:54:21 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-07-24 04:49:47 -04:00
|
|
|
|
|
|
|
it('should add classes specified in an object literal without change in class names',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = `<div [ng-class]="{'foo-bar': true, 'fooBar': true}"></div>`;
|
2015-07-24 04:49:47 -04:00
|
|
|
|
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo-bar fooBar');
|
2015-07-24 04:49:47 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-06-21 05:54:21 -04:00
|
|
|
it('should add and remove classes based on changes in object literal values',
|
2015-06-24 16:07:15 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = '<div [ng-class]="{foo: condition, bar: !condition}"></div>';
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-06-24 16:07:15 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.condition = false;
|
|
|
|
detectChangesAndCheck(fixture, 'bar');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should add and remove classes based on changes to the expression object',
|
2015-06-24 16:07:15 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = '<div [ng-class]="objExpr"></div>';
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-06-24 16:07:15 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
|
|
|
|
detectChangesAndCheck(fixture, 'foo bar');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'baz', true);
|
|
|
|
detectChangesAndCheck(fixture, 'foo bar baz');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.delete(fixture.debugElement.componentInstance.objExpr, 'bar');
|
|
|
|
detectChangesAndCheck(fixture, 'foo baz');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should add and remove classes based on reference changes to the expression object',
|
2015-06-24 16:07:15 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = '<div [ng-class]="objExpr"></div>';
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-06-24 16:07:15 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.objExpr = {foo: true, bar: true};
|
|
|
|
detectChangesAndCheck(fixture, 'foo bar');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.objExpr = {baz: true};
|
|
|
|
detectChangesAndCheck(fixture, 'baz');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-08-10 06:25:46 -04: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)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.objExpr = null;
|
|
|
|
detectChangesAndCheck(fixture, '');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.objExpr = {'foo': false, 'bar': true};
|
|
|
|
detectChangesAndCheck(fixture, 'bar');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-06-21 05:54:21 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-06-21 05:54:21 -04:00
|
|
|
describe('expressions evaluating to lists', () => {
|
|
|
|
|
|
|
|
it('should add classes specified in a list literal',
|
2015-06-24 16:07:15 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = `<div [ng-class]="['foo', 'bar', 'foo-bar', 'fooBar']"></div>`;
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-06-24 16:07:15 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar');
|
2015-06-21 05:54:21 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should add and remove classes based on changes to the expression',
|
2015-06-24 16:07:15 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = '<div [ng-class]="arrExpr"></div>';
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-06-24 16:07:15 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
var arrExpr: string[] = fixture.debugElement.componentInstance.arrExpr;
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
|
|
|
arrExpr.push('bar');
|
2015-10-31 12:50:19 -04:00
|
|
|
detectChangesAndCheck(fixture, 'foo bar');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
|
|
|
arrExpr[1] = 'baz';
|
2015-10-31 12:50:19 -04:00
|
|
|
detectChangesAndCheck(fixture, 'foo baz');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
ListWrapper.remove(fixture.debugElement.componentInstance.arrExpr, 'baz');
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should add and remove classes when a reference changes',
|
2015-06-24 16:07:15 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = '<div [ng-class]="arrExpr"></div>';
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-06-24 16:07:15 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.arrExpr = ['bar'];
|
|
|
|
detectChangesAndCheck(fixture, 'bar');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-08-10 06:25:46 -04: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)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.arrExpr = ['bar'];
|
|
|
|
detectChangesAndCheck(fixture, 'foo bar');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-09-14 08:11:28 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should ignore empty or blank class names',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
|
|
|
var template = '<div class="foo" [ng-class]="arrExpr"></div>';
|
|
|
|
|
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
2015-09-14 08:11:28 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.arrExpr = ['', ' '];
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-09-14 08:11:28 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should trim blanks from class names',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
|
|
|
var template = '<div class="foo" [ng-class]="arrExpr"></div>';
|
|
|
|
|
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
2015-09-14 08:11:28 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.arrExpr = [' bar '];
|
|
|
|
detectChangesAndCheck(fixture, 'foo bar');
|
2015-09-14 08:11:28 -04:00
|
|
|
|
2015-06-21 05:54:21 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2015-10-26 12:50:51 -04:00
|
|
|
describe('expressions evaluating to sets', () => {
|
|
|
|
|
|
|
|
it('should add and remove classes if the set instance changed',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
|
|
|
var template = '<div [ng-class]="setExpr"></div>';
|
|
|
|
|
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
2015-10-26 12:50:51 -04:00
|
|
|
var setExpr = new Set<string>();
|
|
|
|
setExpr.add('bar');
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.setExpr = setExpr;
|
|
|
|
detectChangesAndCheck(fixture, 'bar');
|
2015-10-26 12:50:51 -04:00
|
|
|
|
|
|
|
setExpr = new Set<string>();
|
|
|
|
setExpr.add('baz');
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.setExpr = setExpr;
|
|
|
|
detectChangesAndCheck(fixture, 'baz');
|
2015-10-26 12:50:51 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
2015-06-21 05:54:21 -04:00
|
|
|
describe('expressions evaluating to string', () => {
|
|
|
|
|
|
|
|
it('should add classes specified in a string literal',
|
2015-06-24 16:07:15 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = `<div [ng-class]="'foo bar foo-bar fooBar'"></div>`;
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-06-24 16:07:15 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo bar foo-bar fooBar');
|
2015-06-21 05:54:21 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should add and remove classes based on changes to the expression',
|
2015-06-24 16:07:15 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = '<div [ng-class]="strExpr"></div>';
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-06-24 16:07:15 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.strExpr = 'foo bar';
|
|
|
|
detectChangesAndCheck(fixture, 'foo bar');
|
2015-08-07 11:21:57 -04:00
|
|
|
|
2015-06-21 05:54:21 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.strExpr = 'baz';
|
|
|
|
detectChangesAndCheck(fixture, 'baz');
|
2015-06-21 05:54:21 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-07-08 11:41:18 -04:00
|
|
|
|
|
|
|
it('should remove active classes when switching from string to null',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-08-06 04:38:40 -04:00
|
|
|
var template = `<div [ng-class]="strExpr"></div>`;
|
2015-07-08 11:41:18 -04:00
|
|
|
|
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-07-08 11:41:18 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.strExpr = null;
|
|
|
|
detectChangesAndCheck(fixture, '');
|
2015-07-08 11:41:18 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-08-10 06:25:46 -04: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)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.strExpr = null;
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-09-14 08:11:28 -04:00
|
|
|
it('should ignore empty and blank strings',
|
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
|
|
|
var template = `<div class="foo" [ng-class]="strExpr"></div>`;
|
|
|
|
|
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
fixture.debugElement.componentInstance.strExpr = '';
|
|
|
|
detectChangesAndCheck(fixture, 'foo');
|
2015-09-14 08:11:28 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-06-21 05:54:21 -04:00
|
|
|
});
|
|
|
|
|
2015-08-10 06:25:46 -04:00
|
|
|
describe('cooperation with other class-changing constructs', () => {
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-08-10 06:25:46 -04: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 17:22:35 -04:00
|
|
|
|
2015-08-10 06:25:46 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
|
|
|
|
detectChangesAndCheck(fixture, 'init foo bar');
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false);
|
|
|
|
detectChangesAndCheck(fixture, 'init bar');
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.objExpr = null;
|
|
|
|
detectChangesAndCheck(fixture, 'init foo');
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-08-10 06:25:46 -04: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)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
|
|
|
|
detectChangesAndCheck(fixture, `init foo bar`);
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false);
|
|
|
|
detectChangesAndCheck(fixture, `init bar`);
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.objExpr = null;
|
|
|
|
detectChangesAndCheck(fixture, `init foo`);
|
2015-08-10 06:25:46 -04:00
|
|
|
|
|
|
|
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)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
|
|
|
|
detectChangesAndCheck(fixture, `init foo bar`);
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false);
|
|
|
|
detectChangesAndCheck(fixture, `init bar`);
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.objExpr = null;
|
|
|
|
detectChangesAndCheck(fixture, `init foo`);
|
2015-08-10 06:25:46 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-08-10 06:25:46 -04: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 17:22:35 -04:00
|
|
|
|
2015-08-10 06:25:46 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'init foo baz');
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
|
|
|
|
detectChangesAndCheck(fixture, 'init foo baz bar');
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'foo', false);
|
|
|
|
detectChangesAndCheck(fixture, 'init baz bar');
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.condition = false;
|
|
|
|
detectChangesAndCheck(fixture, 'init bar');
|
2015-06-24 16:07:15 -04:00
|
|
|
|
2015-08-10 06:25:46 -04:00
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-06-24 16:07:15 -04:00
|
|
|
|
2015-08-10 06:25:46 -04: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 16:07:15 -04:00
|
|
|
|
2015-08-10 06:25:46 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
detectChangesAndCheck(fixture, 'init foo');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.set(fixture.debugElement.componentInstance.objExpr, 'bar', true);
|
|
|
|
detectChangesAndCheck(fixture, 'init foo bar');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.strExpr = 'baz';
|
|
|
|
detectChangesAndCheck(fixture, 'init bar baz foo');
|
2015-05-26 17:22:35 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.objExpr = null;
|
|
|
|
detectChangesAndCheck(fixture, 'init baz');
|
2015-08-10 06:25:46 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
2015-05-26 17:22:35 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'test-cmp'})
|
2015-08-06 04:38:40 -04:00
|
|
|
@View({directives: [NgClass, NgFor]})
|
2015-05-26 17:22:35 -04:00
|
|
|
class TestComponent {
|
2015-06-21 05:54:21 -04:00
|
|
|
condition: boolean = true;
|
2015-07-23 19:22:14 -04:00
|
|
|
items: any[];
|
2015-08-28 14:29:19 -04:00
|
|
|
arrExpr: string[] = ['foo'];
|
2015-10-26 12:50:51 -04:00
|
|
|
setExpr: Set<string> = new Set<string>();
|
2015-06-21 05:54:21 -04:00
|
|
|
objExpr = {'foo': true, 'bar': false};
|
|
|
|
strExpr = 'foo';
|
2015-10-26 12:50:51 -04:00
|
|
|
|
|
|
|
constructor() { this.setExpr.add('foo'); }
|
2015-05-26 17:22:35 -04:00
|
|
|
}
|