2015-04-16 18:38:28 -04:00
|
|
|
import {
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
xdescribe,
|
|
|
|
describe,
|
|
|
|
el,
|
|
|
|
dispatchEvent,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
beforeEachBindings,
|
|
|
|
it,
|
|
|
|
xit,
|
2015-05-26 12:25:39 -04:00
|
|
|
SpyObject,
|
|
|
|
proxy
|
2015-04-16 18:38:28 -04:00
|
|
|
} from 'angular2/test_lib';
|
2015-06-02 13:15:16 -04:00
|
|
|
import {isBlank} from 'angular2/src/facade/lang';
|
2015-04-16 18:38:28 -04:00
|
|
|
import {ListWrapper} from 'angular2/src/facade/collection';
|
|
|
|
|
2015-05-06 14:22:28 -04:00
|
|
|
import {DomProtoView} from 'angular2/src/render/dom/view/proto_view';
|
2015-04-16 18:38:28 -04:00
|
|
|
import {ElementBinder} from 'angular2/src/render/dom/view/element_binder';
|
2015-05-06 14:22:28 -04:00
|
|
|
import {DomView} from 'angular2/src/render/dom/view/view';
|
2015-06-02 13:15:16 -04:00
|
|
|
import {DomElement} from 'angular2/src/render/dom/view/element';
|
2015-04-16 18:38:28 -04:00
|
|
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
|
|
|
|
|
|
|
export function main() {
|
2015-05-06 14:22:28 -04:00
|
|
|
describe('DomView', () => {
|
2015-04-16 18:38:28 -04:00
|
|
|
function createProtoView(binders = null) {
|
|
|
|
if (isBlank(binders)) {
|
|
|
|
binders = [];
|
|
|
|
}
|
|
|
|
var rootEl = el('<div></div>');
|
2015-06-02 17:14:10 -04:00
|
|
|
return new DomProtoView(
|
|
|
|
{element: rootEl, elementBinders: binders, transitiveContentTagCount: 0});
|
2015-04-16 18:38:28 -04:00
|
|
|
}
|
|
|
|
|
2015-05-26 12:25:39 -04:00
|
|
|
function createView(pv = null, boundElementCount = 0) {
|
2015-04-16 18:38:28 -04:00
|
|
|
if (isBlank(pv)) {
|
|
|
|
pv = createProtoView();
|
|
|
|
}
|
|
|
|
var root = el('<div><div></div></div>');
|
|
|
|
var boundElements = [];
|
2015-05-26 12:25:39 -04:00
|
|
|
for (var i = 0; i < boundElementCount; i++) {
|
2015-06-02 13:15:16 -04:00
|
|
|
ListWrapper.push(boundElements,
|
|
|
|
new DomElement(pv.elementBinders[i], el('<span></span'), null));
|
2015-04-16 18:38:28 -04:00
|
|
|
}
|
2015-06-02 13:15:16 -04:00
|
|
|
return new DomView(pv, [DOM.childNodes(root)[0]], [], boundElements);
|
2015-04-16 18:38:28 -04:00
|
|
|
}
|
|
|
|
|
2015-06-02 13:15:16 -04:00
|
|
|
describe('getDirectParentElement', () => {
|
2015-04-16 18:38:28 -04:00
|
|
|
|
2015-06-02 13:15:16 -04:00
|
|
|
it('should return the DomElement of the direct parent', () => {
|
2015-04-16 18:38:28 -04:00
|
|
|
var pv = createProtoView(
|
2015-05-26 12:25:39 -04:00
|
|
|
[new ElementBinder(), new ElementBinder({parentIndex: 0, distanceToParent: 1})]);
|
2015-04-16 18:38:28 -04:00
|
|
|
var view = createView(pv, 2);
|
2015-06-02 13:15:16 -04:00
|
|
|
expect(view.getDirectParentElement(1)).toBe(view.boundElements[0]);
|
2015-04-16 18:38:28 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return null if the direct parent is not bound', () => {
|
2015-05-26 12:25:39 -04:00
|
|
|
var pv = createProtoView([
|
|
|
|
new ElementBinder(),
|
|
|
|
new ElementBinder(),
|
|
|
|
new ElementBinder({parentIndex: 0, distanceToParent: 2})
|
|
|
|
]);
|
2015-04-16 18:38:28 -04:00
|
|
|
var view = createView(pv, 3);
|
2015-06-02 13:15:16 -04:00
|
|
|
expect(view.getDirectParentElement(2)).toBe(null);
|
2015-04-16 18:38:28 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|