diff --git a/src/app/article/cms/article-editor/article-editor.component.spec.ts b/src/app/article/cms/article-editor/article-editor.component.spec.ts
new file mode 100644
index 0000000..1b3beb4
--- /dev/null
+++ b/src/app/article/cms/article-editor/article-editor.component.spec.ts
@@ -0,0 +1,28 @@
+import {ArticleEditorComponent} from './article-editor.component';
+import {BasicEditorComponent} from "../basic-editor/basic-editor.component";
+import {ComponentTestHelper, createClass} from '../../../../spec/component-test-helper';
+import * as helpers from "../../../../spec/helpers";
+
+const htmlTemplate: string = '';
+
+describe("Components", () => {
+ describe("Article Editor Component", () => {
+
+ let helper: ComponentTestHelper;
+ beforeEach(angular.mock.module("templates"));
+
+ beforeEach((done) => {
+ let properties = { article: { type: "TextArticle" } };
+ let cls = createClass({
+ template: htmlTemplate,
+ directives: [ArticleEditorComponent, BasicEditorComponent],
+ properties: properties
+ });
+ helper = new ComponentTestHelper(cls, done);
+ });
+
+ it("replace element with article basic editor when type is TextArticle", () => {
+ expect(helper.find("article-basic-editor").length).toEqual(1);
+ });
+ });
+});
diff --git a/src/app/article/cms/article-editor/article-editor.component.ts b/src/app/article/cms/article-editor/article-editor.component.ts
index 4cb4592..37373df 100644
--- a/src/app/article/cms/article-editor/article-editor.component.ts
+++ b/src/app/article/cms/article-editor/article-editor.component.ts
@@ -16,10 +16,10 @@ export class ArticleEditorComponent {
private $compile: ng.ICompileService) { }
ngOnInit() {
- let articleType = this.article.type.replace(/::/, '');
+ let articleType = this.article && this.article.type ? this.article.type.replace(/::/, '') : "TextArticle";
let specificDirective = `${articleType.charAt(0).toLowerCase()}${articleType.substring(1)}Editor`;
let directiveName = "article-basic-editor";
- if (this.$injector.has(specificDirective + 'Directive')) {
+ if (specificDirective !== "articleEditor" && this.$injector.has(specificDirective + 'Directive')) {
directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
this.$element.replaceWith(this.$compile('<' + directiveName + ' [article]="ctrl.article">' + directiveName + '>')(this.$scope));
diff --git a/src/spec/component-test-helper.ts b/src/spec/component-test-helper.ts
index 590769f..651940f 100644
--- a/src/spec/component-test-helper.ts
+++ b/src/spec/component-test-helper.ts
@@ -88,10 +88,11 @@ export class ComponentTestHelper {
this.debugElement = fixture.debugElement;
this.component = this.debugElement.componentViewChildren[0].componentInstance;
let mockObj = new this.mockComponent();
- Object.keys(mockObj).forEach((key: any) => {
- (this.component)[key] = mockObj[key];
- });
-
+ if (this.component) {
+ Object.keys(mockObj).forEach((key: any) => {
+ (this.component)[key] = mockObj[key];
+ });
+ }
}).then(() => {
// Force the resolution of components and sync
done();
@@ -99,9 +100,9 @@ export class ComponentTestHelper {
}
changeProperties(properties: any) {
- Object.keys(properties).forEach((key: any) => {
- this.component[key] = properties[key];
- });
+ Object.keys(properties).forEach((key: any) => {
+ this.component[key] = properties[key];
+ });
}
/**
--
libgit2 0.21.2