Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Aug 23, 2024
2 parents ea8deb1 + b9c3058 commit 317d8f7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3674,7 +3674,7 @@ export class SurveyCreatorModel extends Base
needSeparator: needSeparator
});
action.action = () => {
onSelectQuestionType(item.typeName);
onSelectQuestionType(item.typeName, item.json);
};

if (!!item.items && item.items.length > 0 && this.toolbox.showSubitems) {
Expand Down
36 changes: 36 additions & 0 deletions packages/survey-creator-core/tests/creator-base.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { PropertyGridEditorMatrixItemValues } from "../src/property-grid/matrice
import { ObjectSelector } from "../src/property-grid/object-selector";
import { TabDesignerViewModel } from "../src/components/tabs/designer";
import { ConfigureTablePropertyEditorEvent } from "../src/creator-events-api";
import { IQuestionToolboxItem } from "../src/toolbox";

surveySettings.supportCreatorV2 = true;

Expand Down Expand Up @@ -1329,6 +1330,41 @@ test("Question type selector popup displayMode", (): any => {
expect(selectorModel.popupModel.displayMode).toBe("overlay");
});

test("Question type selector with custom toolbox item", (): any => {
const creator = new CreatorTester();
const customToolboxItem = <IQuestionToolboxItem>{
"id": "panel1",
"name": "panel1",
"iconName": "icon-panel",
"className": "",
"title": "",
"json": {
"type": "panel",
"name": "panel1",
"elements": [{ "type": "text", "name": "question1" }],
},
"isCopied": false,
"isUsed": true,
"isStandard": false,
"category": "Custom Questions"
};
creator.toolbox.addItem(customToolboxItem);

const survey: SurveyModel = creator.survey;
expect(survey.getAllQuestions().length).toEqual(0);

const selectorModel = creator.getQuestionTypeSelectorModel(() => { });
const listModel: ListModel = selectorModel.popupModel.contentComponentData.model;
selectorModel.popupModel.toggleVisibility();
const customItem = listModel.actions.filter((item) => item.id == "panel1")[0];
listModel.onItemClick(customItem);
expect(survey.getAllPanels().length).toEqual(1);
expect(survey.getAllPanels()[0].getType()).toEqual("panel");

const newQ = survey.getAllPanels()[0];
expect(newQ.elements.length).toEqual(1);
});

test("Add question with default choices", (): any => {
const creator = new CreatorTester();
const survey: SurveyModel = creator.survey;
Expand Down

0 comments on commit 317d8f7

Please sign in to comment.