2016-04-07 20:17:50 -04:00
|
|
|
import {AsyncTestCompleter, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, xdescribe, describe, el, expect, iit, inject, it, xit,} from 'angular2/testing_internal';
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-11-06 20:34:07 -05:00
|
|
|
import {StringMapWrapper} from 'angular2/src/facade/collection';
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2016-03-08 16:36:48 -05:00
|
|
|
import {Component} from 'angular2/core';
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-11-19 18:09:34 -05:00
|
|
|
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
2015-11-05 17:58:24 -05:00
|
|
|
import {NgStyle} from 'angular2/src/common/directives/ng_style';
|
2015-06-21 08:18:28 -04:00
|
|
|
|
|
|
|
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-11-23 19:02:19 -05:00
|
|
|
var template = `<div [ngStyle]="{'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)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
fixture.detectChanges();
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
|
2015-07-29 12:34:02 -04:00
|
|
|
.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-11-23 19:02:19 -05:00
|
|
|
var template = `<div [ngStyle]="expr"></div>`;
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
2015-06-21 08:18:28 -04:00
|
|
|
var expr: Map<string, any>;
|
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
|
|
|
|
fixture.detectChanges();
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
|
2015-07-29 12:34:02 -04:00
|
|
|
.toEqual('40px');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
expr = fixture.debugElement.componentInstance.expr;
|
2015-07-29 12:34:02 -04:00
|
|
|
expr['max-width'] = '30%';
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
|
2015-07-29 12:34:02 -04:00
|
|
|
.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-11-23 19:02:19 -05:00
|
|
|
var template = `<div [ngStyle]="expr"></div>`;
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
|
|
|
|
fixture.detectChanges();
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
|
2015-07-29 12:34:02 -04:00
|
|
|
.toEqual('40px');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.delete(fixture.debugElement.componentInstance.expr, 'max-width');
|
|
|
|
fixture.detectChanges();
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[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-11-23 19:02:19 -05:00
|
|
|
var template = `<div style="font-size: 12px" [ngStyle]="expr"></div>`;
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
|
|
|
|
fixture.detectChanges();
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
|
2015-07-29 12:34:02 -04:00
|
|
|
.toEqual('40px');
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'font-size'))
|
2015-06-26 19:16:19 -04:00
|
|
|
.toEqual('12px');
|
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.delete(fixture.debugElement.componentInstance.expr, 'max-width');
|
|
|
|
fixture.detectChanges();
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
|
2015-06-26 19:16:19 -04:00
|
|
|
.toEqual('');
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'font-size'))
|
2015-06-26 19:16:19 -04:00
|
|
|
.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-11-23 19:02:19 -05:00
|
|
|
var template = `<div [style.font-size.px]="12" [ngStyle]="expr"></div>`;
|
2015-06-21 08:18:28 -04:00
|
|
|
|
2015-06-26 19:16:19 -04:00
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((fixture) => {
|
|
|
|
fixture.debugElement.componentInstance.expr = {'max-width': '40px'};
|
|
|
|
fixture.detectChanges();
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
|
2015-07-29 12:34:02 -04:00
|
|
|
.toEqual('40px');
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'font-size'))
|
2015-06-26 19:16:19 -04:00
|
|
|
.toEqual('12px');
|
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
StringMapWrapper.delete(fixture.debugElement.componentInstance.expr, 'max-width');
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'font-size'))
|
2015-06-26 19:16:19 -04:00
|
|
|
.toEqual('12px');
|
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
fixture.detectChanges();
|
2016-01-14 00:35:21 -05:00
|
|
|
expect(DOM.getStyle(fixture.debugElement.children[0].nativeElement, 'max-width'))
|
2015-06-26 19:16:19 -04:00
|
|
|
.toEqual('');
|
2015-06-21 08:18:28 -04:00
|
|
|
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:36:48 -05:00
|
|
|
@Component({selector: 'test-cmp', directives: [NgStyle], template: ''})
|
2015-06-21 08:18:28 -04:00
|
|
|
class TestComponent {
|
|
|
|
expr;
|
|
|
|
}
|