
Closes #2529 BREAKING CHANGES: - shadow dom emulation no longer supports the `<content>` tag. Use the new `<ng-content>` instead (works with all shadow dom strategies). - removed `DomRenderer.setViewRootNodes` and `AppViewManager.getComponentView` -> use `DomRenderer.getNativeElementSync(elementRef)` and change shadow dom directly - the `Renderer` interface has changed: * `createView` now also has to support sub views * the notion of a container has been removed. Instead, the renderer has to implement methods to attach views next to elements or other views. * a RenderView now contains multiple RenderFragments. Fragments are used to move DOM nodes around. Internal changes / design changes: - Introduce notion of view fragments on render side - DomProtoViews and DomViews on render side are merged, AppProtoViews are not merged, AppViews are partially merged (they share arrays with the other merged AppViews but we keep individual AppView instances for now). - DomProtoViews always have a `<template>` element as root * needed for storing subviews * we have less chunks of DOM to clone now - remove fake ElementBinder / Bound element for root text bindings and model them explicitly. This removes a lot of special cases we had! - AppView shares data with nested component views - some methods in AppViewManager (create, hydrate, dehydrate) are iterative now * now possible as we have all child AppViews / ElementRefs already in an array!
138 lines
4.0 KiB
TypeScript
138 lines
4.0 KiB
TypeScript
import {
|
|
AsyncTestCompleter,
|
|
beforeEach,
|
|
ddescribe,
|
|
xdescribe,
|
|
describe,
|
|
el,
|
|
dispatchEvent,
|
|
expect,
|
|
iit,
|
|
inject,
|
|
beforeEachBindings,
|
|
it,
|
|
xit,
|
|
SpyObject,
|
|
proxy
|
|
} from 'angular2/test_lib';
|
|
import {isBlank} from 'angular2/src/facade/lang';
|
|
import {ListWrapper} from 'angular2/src/facade/collection';
|
|
|
|
import {DomProtoView} from 'angular2/src/render/dom/view/proto_view';
|
|
import {DomElementBinder} from 'angular2/src/render/dom/view/element_binder';
|
|
import {DomView} from 'angular2/src/render/dom/view/view';
|
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
|
|
|
export function main() {
|
|
describe('DomView', () => {
|
|
function createProtoView(binders = null) {
|
|
if (isBlank(binders)) {
|
|
binders = [];
|
|
}
|
|
var rootEl = DOM.createTemplate('<div></div>');
|
|
return DomProtoView.create(null, <Element>rootEl, [1], [], binders, null, null, null);
|
|
}
|
|
|
|
function createElementBinder() { return new DomElementBinder({textNodeIndices: []}); }
|
|
|
|
function createView(pv = null, boundElementCount = 0) {
|
|
if (isBlank(pv)) {
|
|
var elementBinders = ListWrapper.createFixedSize(boundElementCount);
|
|
for (var i = 0; i < boundElementCount; i++) {
|
|
elementBinders[i] = createElementBinder();
|
|
}
|
|
pv = createProtoView(elementBinders);
|
|
}
|
|
var root = el('<div><div></div></div>');
|
|
var boundElements = [];
|
|
for (var i = 0; i < boundElementCount; i++) {
|
|
boundElements.push(el('<span></span'));
|
|
}
|
|
return new DomView(pv, [DOM.childNodes(root)[0]], boundElements);
|
|
}
|
|
|
|
describe('setElementProperty', () => {
|
|
var el, view;
|
|
beforeEach(() => {
|
|
view = createView(null, 1);
|
|
el = view.boundElements[0];
|
|
});
|
|
|
|
it('should update the property value', () => {
|
|
view.setElementProperty(0, 'title', 'Hello');
|
|
expect(el.title).toEqual('Hello');
|
|
});
|
|
|
|
});
|
|
|
|
describe('setElementAttribute', () => {
|
|
var el, view;
|
|
beforeEach(() => {
|
|
view = createView(null, 1);
|
|
el = view.boundElements[0];
|
|
});
|
|
|
|
it('should update and remove an attribute', () => {
|
|
view.setElementAttribute(0, 'role', 'button');
|
|
expect(DOM.getAttribute(el, 'role')).toEqual('button');
|
|
view.setElementAttribute(0, 'role', null);
|
|
expect(DOM.getAttribute(el, 'role')).toEqual(null);
|
|
});
|
|
|
|
it('should de-normalize attribute names', () => {
|
|
view.setElementAttribute(0, 'ariaLabel', 'fancy button');
|
|
expect(DOM.getAttribute(el, 'aria-label')).toEqual('fancy button');
|
|
});
|
|
});
|
|
|
|
describe('setElementClass', () => {
|
|
var el, view;
|
|
beforeEach(() => {
|
|
view = createView(null, 1);
|
|
el = view.boundElements[0];
|
|
});
|
|
|
|
it('should set and remove a class', () => {
|
|
view.setElementClass(0, 'active', true);
|
|
expect(DOM.hasClass(el, 'active')).toEqual(true);
|
|
|
|
view.setElementClass(0, 'active', false);
|
|
expect(DOM.hasClass(el, 'active')).toEqual(false);
|
|
});
|
|
|
|
it('should de-normalize class names', () => {
|
|
view.setElementClass(0, 'veryActive', true);
|
|
expect(DOM.hasClass(el, 'very-active')).toEqual(true);
|
|
|
|
view.setElementClass(0, 'veryActive', false);
|
|
expect(DOM.hasClass(el, 'very-active')).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe('setElementStyle', () => {
|
|
var el, view;
|
|
beforeEach(() => {
|
|
view = createView(null, 1);
|
|
el = view.boundElements[0];
|
|
});
|
|
|
|
it('should set and remove styles', () => {
|
|
view.setElementStyle(0, 'width', '40px');
|
|
expect(DOM.getStyle(el, 'width')).toEqual('40px');
|
|
|
|
view.setElementStyle(0, 'width', null);
|
|
expect(DOM.getStyle(el, 'width')).toEqual('');
|
|
});
|
|
|
|
it('should de-normalize style names', () => {
|
|
view.setElementStyle(0, 'textAlign', 'right');
|
|
expect(DOM.getStyle(el, 'text-align')).toEqual('right');
|
|
view.setElementStyle(0, 'textAlign', null);
|
|
expect(DOM.getStyle(el, 'text-align')).toEqual('');
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
}
|