2015-06-21 08:18:28 -04:00
|
|
|
import {
|
|
|
|
AsyncTestCompleter,
|
2015-06-26 19:16:19 -04:00
|
|
|
TestComponentBuilder,
|
2015-06-21 08:18:28 -04:00
|
|
|
beforeEach,
|
|
|
|
beforeEachBindings,
|
|
|
|
ddescribe,
|
|
|
|
xdescribe,
|
|
|
|
describe,
|
|
|
|
el,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
xit,
|
|
|
|
} from 'angular2/test_lib';
|
|
|
|
|
|
|
|
import {StringMapWrapper} from 'angular2/src/facade/collection';
|
|
|
|
|
|
|
|
import {Component, View} from 'angular2/angular2';
|
|
|
|
|
|
|
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
|
|
|
import {NgStyle} from 'angular2/src/directives/ng_style';
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('binding to CSS styles', () => {
|
|
|
|
|
|
|
|
it('should add styles specified in an object literal',
|
2015-06-26 19:16:19 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-06-21 08:18:28 -04:00
|
|
|
var template = `<div [ng-style]="{'text-align': 'right'}"></div>`;
|
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
|
|
|
.then((rootTC) => {
|
|
|
|
rootTC.detectChanges();
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'text-align'))
|
|
|
|
.toEqual('right');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should add and change styles specified in an object expression',
|
2015-06-26 19:16:19 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-06-21 08:18:28 -04:00
|
|
|
var template = `<div [ng-style]="expr"></div>`;
|
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
|
|
|
.then((rootTC) => {
|
2015-06-21 08:18:28 -04:00
|
|
|
var expr: Map<string, any>;
|
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
rootTC.componentInstance.expr = {'text-align': 'right'};
|
|
|
|
rootTC.detectChanges();
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'text-align'))
|
|
|
|
.toEqual('right');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
expr = rootTC.componentInstance.expr;
|
2015-06-21 08:18:28 -04:00
|
|
|
expr['text-align'] = 'left';
|
2015-06-26 19:16:19 -04:00
|
|
|
rootTC.detectChanges();
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'text-align'))
|
|
|
|
.toEqual('left');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should remove styles when deleting a key in an object expression',
|
2015-06-26 19:16:19 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-06-21 08:18:28 -04:00
|
|
|
var template = `<div [ng-style]="expr"></div>`;
|
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
|
|
|
.then((rootTC) => {
|
|
|
|
rootTC.componentInstance.expr = {'text-align': 'right'};
|
|
|
|
rootTC.detectChanges();
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'text-align'))
|
|
|
|
.toEqual('right');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
StringMapWrapper.delete(rootTC.componentInstance.expr, 'text-align');
|
|
|
|
rootTC.detectChanges();
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'text-align'))
|
|
|
|
.toEqual('');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should co-operate with the style attribute',
|
2015-06-26 19:16:19 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-06-21 08:18:28 -04:00
|
|
|
var template = `<div style="font-size: 12px" [ng-style]="expr"></div>`;
|
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
|
|
|
.then((rootTC) => {
|
|
|
|
rootTC.componentInstance.expr = {'text-align': 'right'};
|
|
|
|
rootTC.detectChanges();
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'text-align'))
|
|
|
|
.toEqual('right');
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size'))
|
|
|
|
.toEqual('12px');
|
|
|
|
|
|
|
|
StringMapWrapper.delete(rootTC.componentInstance.expr, 'text-align');
|
|
|
|
rootTC.detectChanges();
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'text-align'))
|
|
|
|
.toEqual('');
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size'))
|
|
|
|
.toEqual('12px');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should co-operate with the style.[styleName]="expr" special-case in the compiler',
|
2015-06-26 19:16:19 -04:00
|
|
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
2015-06-21 08:18:28 -04:00
|
|
|
var template = `<div [style.font-size.px]="12" [ng-style]="expr"></div>`;
|
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
|
|
|
.then((rootTC) => {
|
|
|
|
rootTC.componentInstance.expr = {'text-align': 'right'};
|
|
|
|
rootTC.detectChanges();
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'text-align'))
|
|
|
|
.toEqual('right');
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size'))
|
|
|
|
.toEqual('12px');
|
|
|
|
|
|
|
|
StringMapWrapper.delete(rootTC.componentInstance.expr, 'text-align');
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size'))
|
|
|
|
.toEqual('12px');
|
|
|
|
|
|
|
|
rootTC.detectChanges();
|
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'text-align'))
|
|
|
|
.toEqual('');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'test-cmp'})
|
|
|
|
@View({directives: [NgStyle]})
|
|
|
|
class TestComponent {
|
|
|
|
expr;
|
|
|
|
}
|