Browse Source

Some more tests.

pull/130/head
Sebastian Stehle 9 years ago
parent
commit
c2049793fd
  1. 6
      src/Squidex/app/framework/angular/modal-view.directive.ts
  2. 25
      src/Squidex/app/framework/angular/root-view.directive.spec.ts
  3. 2
      src/Squidex/app/framework/angular/root-view.directive.ts
  4. 43
      src/Squidex/app/framework/services/root-view.service.spec.ts
  5. 16
      src/Squidex/app/framework/services/root-view.service.ts

6
src/Squidex/app/framework/angular/modal-view.directive.ts

@ -31,7 +31,7 @@ export class ModalViewDirective implements OnChanges, OnInit, OnDestroy {
private readonly templateRef: TemplateRef<any>, private readonly templateRef: TemplateRef<any>,
private readonly renderer: Renderer, private readonly renderer: Renderer,
private readonly viewContainer: ViewContainerRef, private readonly viewContainer: ViewContainerRef,
private readonly rootViewService: RootViewService private readonly rootContainer: RootViewService
) { ) {
} }
@ -82,7 +82,7 @@ export class ModalViewDirective implements OnChanges, OnInit, OnDestroy {
if (isOpen) { if (isOpen) {
if (this.placeOnRoot) { if (this.placeOnRoot) {
this.renderedView = this.rootViewService.rootView.createEmbeddedView(this.templateRef); this.renderedView = this.rootContainer.createEmbeddedView(this.templateRef);
} else { } else {
this.renderedView = this.viewContainer.createEmbeddedView(this.templateRef); this.renderedView = this.viewContainer.createEmbeddedView(this.templateRef);
} }
@ -91,7 +91,7 @@ export class ModalViewDirective implements OnChanges, OnInit, OnDestroy {
this.renderedView = null; this.renderedView = null;
if (this.placeOnRoot) { if (this.placeOnRoot) {
this.rootViewService.rootView.clear(); this.rootContainer.clear();
} else { } else {
this.viewContainer.clear(); this.viewContainer.clear();
} }

25
src/Squidex/app/framework/angular/root-view.directive.spec.ts

@ -0,0 +1,25 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { RootViewDirective } from './../';
describe('RootViewDirective', () => {
it('should call init of service in ctor', () => {
let viewRef = {};
let viewRefPassed = null;
const service = {
init: (ref: any) => {
viewRefPassed = ref;
}
};
new RootViewDirective(<any>viewRef, <any>service);
expect(viewRef).toBe(viewRefPassed);
});
});

2
src/Squidex/app/framework/angular/root-view.directive.ts

@ -14,6 +14,6 @@ import { RootViewService } from './../services/root-view.service';
}) })
export class RootViewDirective { export class RootViewDirective {
constructor(viewContainer: ViewContainerRef, rootViewService: RootViewService) { constructor(viewContainer: ViewContainerRef, rootViewService: RootViewService) {
rootViewService.rootView = viewContainer; rootViewService.init(viewContainer);
} }
} }

43
src/Squidex/app/framework/services/root-view.service.spec.ts

@ -0,0 +1,43 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { RootViewService } from './../';
describe('RootViewService', () => {
const rootViewService = new RootViewService();
it('should call view when clearing element', () => {
let isClearCalled = false;
const viewRef = {
clear: () => {
isClearCalled = true;
}
};
rootViewService.init(<any>viewRef);
rootViewService.clear();
expect(isClearCalled).toBeTruthy();
});
it('should call view when creating element', () => {
let view = {};
const viewRef = {
createEmbeddedView: () => {
return view;
}
};
rootViewService.init(<any>viewRef);
const result = rootViewService.createEmbeddedView(<any>{});
expect(result).toBe(view);
});
});

16
src/Squidex/app/framework/services/root-view.service.ts

@ -5,9 +5,21 @@
* Copyright (c) Sebastian Stehle. All rights reserved * Copyright (c) Sebastian Stehle. All rights reserved
*/ */
import { Injectable, ViewContainerRef } from '@angular/core'; import { EmbeddedViewRef, Injectable, TemplateRef, ViewContainerRef } from '@angular/core';
@Injectable() @Injectable()
export class RootViewService { export class RootViewService {
public rootView: ViewContainerRef; private rootView: ViewContainerRef;
public init(view: ViewContainerRef) {
this.rootView = view;
}
public createEmbeddedView<C>(templateRef: TemplateRef<C>, context?: C, index?: number): EmbeddedViewRef<C> {
return this.rootView.createEmbeddedView(templateRef, context, index);
}
public clear() {
this.rootView.clear();
}
} }
Loading…
Cancel
Save