Skip to content

Commit

Permalink
Fix Creator unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Nov 10, 2023
1 parent 6bbc7d5 commit 888136c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/questionfactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Question } from "./question";
import { IElement } from "./base-interfaces";
import { surveyLocalization } from "./surveyStrings";
import { Serializer } from "./jsonobject";
import { ComponentCollection } from "./question_custom";

export class QuestionFactory {
public static Instance: QuestionFactory = new QuestionFactory();
Expand Down Expand Up @@ -79,6 +80,8 @@ export class ElementFactory {
public createElement(elementType: string, name: string): IElement {
var creator = this.creatorHash[elementType];
if (!!creator) return creator(name);
return Serializer.createClass(elementType, { name: name });
const compJSON = ComponentCollection.Instance.getCustomQuestionByName(elementType);
if(!!compJSON) return ComponentCollection.Instance.createQuestion(name, compJSON);
return null;
}
}
17 changes: 17 additions & 0 deletions tests/question_customtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2527,4 +2527,21 @@ QUnit.test("Set title from single component into question", function (assert) {
assert.equal(q3.name, "q3", "q3 name");
assert.equal(q3.locTitle.renderedHtml, "Title from Component", "q3 title");
assert.deepEqual(q1.toJSON(), { name: "q1" }, "Do not serialize title");
ComponentCollection.Instance.clear();
});
QUnit.test("Allow to add question via addNewQuestion for component, but not for abstract classes", function (assert) {
ComponentCollection.Instance.add({
name: "newquestion",
questionJSON: { type: "text", title: "Title from Component" },
});
const survey = new SurveyModel({
elements: [
{ type: "text", name: "q1" }
]
});
const q2 = survey.pages[0].addNewQuestion("newquestion", "q2");
const q3 = survey.pages[0].addNewQuestion("matrixdropdownbase", "q3");
assert.ok(q2, "component created");
assert.notOk(q3, "matrixdropdownbase is not created");
ComponentCollection.Instance.clear();
});

0 comments on commit 888136c

Please sign in to comment.