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-07-29 12:34:02 -04:00
|
|
|
var template = `<div [ng-style]="{'max-width': '40px'}"></div>`;
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
|
|
|
.then((rootTC) => {
|
|
|
|
rootTC.detectChanges();
|
2015-07-29 12:34:02 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width'))
|
|
|
|
.toEqual('40px');
|
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-07-29 12:34:02 -04:00
|
|
|
rootTC.componentInstance.expr = {'max-width': '40px'};
|
2015-06-26 19:16:19 -04:00
|
|
|
rootTC.detectChanges();
|
2015-07-29 12:34:02 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width'))
|
|
|
|
.toEqual('40px');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
expr = rootTC.componentInstance.expr;
|
2015-07-29 12:34:02 -04:00
|
|
|
expr['max-width'] = '30%';
|
2015-06-26 19:16:19 -04:00
|
|
|
rootTC.detectChanges();
|
2015-07-29 12:34:02 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width'))
|
|
|
|
.toEqual('30%');
|
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) => {
|
2015-07-29 12:34:02 -04:00
|
|
|
rootTC.componentInstance.expr = {'max-width': '40px'};
|
2015-06-26 19:16:19 -04:00
|
|
|
rootTC.detectChanges();
|
2015-07-29 12:34:02 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width'))
|
|
|
|
.toEqual('40px');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-07-29 12:34:02 -04:00
|
|
|
StringMapWrapper.delete(rootTC.componentInstance.expr, 'max-width');
|
2015-06-26 19:16:19 -04:00
|
|
|
rootTC.detectChanges();
|
2015-07-29 12:34:02 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width'))
|
2015-06-26 19:16:19 -04:00
|
|
|
.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) => {
|
2015-07-29 12:34:02 -04:00
|
|
|
rootTC.componentInstance.expr = {'max-width': '40px'};
|
2015-06-26 19:16:19 -04:00
|
|
|
rootTC.detectChanges();
|
2015-07-29 12:34:02 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width'))
|
|
|
|
.toEqual('40px');
|
2015-06-26 19:16:19 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size'))
|
|
|
|
.toEqual('12px');
|
|
|
|
|
2015-07-29 12:34:02 -04:00
|
|
|
StringMapWrapper.delete(rootTC.componentInstance.expr, 'max-width');
|
2015-06-26 19:16:19 -04:00
|
|
|
rootTC.detectChanges();
|
2015-07-29 12:34:02 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width'))
|
2015-06-26 19:16:19 -04:00
|
|
|
.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) => {
|
2015-07-29 12:34:02 -04:00
|
|
|
rootTC.componentInstance.expr = {'max-width': '40px'};
|
2015-06-26 19:16:19 -04:00
|
|
|
rootTC.detectChanges();
|
2015-07-29 12:34:02 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width'))
|
|
|
|
.toEqual('40px');
|
2015-06-26 19:16:19 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size'))
|
|
|
|
.toEqual('12px');
|
|
|
|
|
2015-07-29 12:34:02 -04:00
|
|
|
StringMapWrapper.delete(rootTC.componentInstance.expr, 'max-width');
|
2015-06-26 19:16:19 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'font-size'))
|
|
|
|
.toEqual('12px');
|
|
|
|
|
|
|
|
rootTC.detectChanges();
|
2015-07-29 12:34:02 -04:00
|
|
|
expect(DOM.getStyle(rootTC.componentViewChildren[0].nativeElement, 'max-width'))
|
2015-06-26 19:16:19 -04:00
|
|
|
.toEqual('');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'test-cmp'})
|
|
|
|
@View({directives: [NgStyle]})
|
|
|
|
class TestComponent {
|
|
|
|
expr;
|
|
|
|
}
|