export default class LifeCycleService {
protected animator: EventEmitter;
protected entitySystemMediator: EntitySystemMediatorService;
protected destroyAll: EntityVO[] = [];
public domElementToEntityVOMap: Map<HTMLElement, EntityVO> = new Map();
constructor(animator: EventEmitter, entitySystemMediator: EntitySystemMediatorService) {
this.animator = animator;
this.entitySystemMediator = entitySystemMediator;
}
protected animator_exitFrameHandler = ()=> {
};
public create(entityVO: EntityVO): void {
}
public destroy(entityVO: EntityVO): void {
}
public installLayer(entityVO: EntityVO, layer: Layer): LifeCycleService {
return this;
}
public uninstallLayer(entityVO: EntityVO, layer: Layer): LifeCycleService {
return this;
}
public reinstallLayer(entityVO: EntityVO, layer: Layer): LifeCycleService {
return this;
}
}
describe('[test Layer] >', function(){
const NUM_CHILDREN: number = 5;
const RANDOM_CHILD: number = 2;
const DEPTH: number = 5;
let layer: Layer;
let layerFromMiddle: Layer;
let elementHashContainer: ElementHashContainer;
let element: Element;
let children: Layer[];
let composition: Layer;
beforeAll(function(){
element = createElementForElementHashContainer();
elementHashContainer = createElementHashContainer(element);
});
describe('create instance and props >', function(){
it('create instance', function(){
expect(()=>layer = new Layer(elementHashContainer)).not.toThrow();
});
});
describe('operations with children layers >', function(){
beforeAll(function(){
children = createLayerWithNullInConstructor(NUM_CHILDREN);
});
afterAll(function(){
children = null;
});
it('insertLayer', function(){
expect(()=> children.map((item:Layer)=>layer.insertLayer(item))).not.toThrow();
});
it('comparison length', function(){
expect(layer.numChildren).toEqual(children.length);
});
it('getChildrenAt', function(){
expect(layer.getChildAt(RANDOM_CHILD)).toEqual(children[RANDOM_CHILD]);
});
it('removeLayer', function(){
expect(()=>children.map(item => layer.removeLayer(item))).not.toThrow();
});
it('comparison length', function(){
expect(layer.numChildren).toEqual(0);
});
});
describe('change child composition layer >', function(){
beforeAll(function(){
children = createLayerWithNullInConstructor(NUM_CHILDREN);
composition = createCompositionLayer(children);
layerFromMiddle = children[RANDOM_CHILD];
layer.isRoot = true;
spyOn(Layer, 'informRootAboutChangeTree').and.callThrough();
spyOn(layer, 'rebuildLayer').and.callThrough();
});
afterAll(function(){
children = null;
composition = null;
layerFromMiddle = null;
layer.isRoot = true;
spyOn(Layer, 'informRootAboutChangeTree').and.callThrough();
spyOn(layer, 'rebuildLayer').and.callThrough();
});
it('check depth', function(){
expect(getDepthComposition(composition)).toEqual(DEPTH);
});
it('check count', function(){
expect(getCountComposition(composition)).toEqual(NUM_CHILDREN);
});
it('layerFromMiddle child', function(){
expect(layerFromMiddle.numChildren).toEqual(1);
});
});
});