Skip to content

Commit

Permalink
Fixed #4940 - Change question menu incorrect for custom question type (
Browse files Browse the repository at this point in the history
…#5341)

Co-authored-by: tsv2013 <tsv2013@noreply.github.com>
  • Loading branch information
tsv2013 and tsv2013 committed Mar 21, 2024
1 parent b9be320 commit ad70284
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/survey-creator-core/src/components/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
messageText: "",
onClick: () => { }
};
if(this.creator) {
if (this.creator) {
this.creator.onCreateCustomMessagePanel.fire(this.creator, res);
}
res.text = res.messageText;
Expand Down Expand Up @@ -302,15 +302,19 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
public getConvertToTypesActions(): Array<IAction> {
const availableItems = this.creator.getAvailableToolboxItems(this.element, false);
const itemNames = [];
availableItems.forEach(item => itemNames.push(item.typeName));
availableItems.forEach(item => {
if (itemNames.indexOf(item.typeName) == -1) {
itemNames.push(item.typeName);
}
});
const convertClasses: string[] = QuestionConverter.getConvertToClasses(
this.currentType, itemNames, true
);
const res = [];
let lastItem = null;
convertClasses.forEach((className: string) => {
const items = this.creator.toolbox.items.filter(item => item.name == className);
if(Array.isArray(items) && items.length > 0) {
if (Array.isArray(items) && items.length > 0) {
const item = items[0];
const needSeparator = lastItem && item.category != lastItem.category;
const action = this.creator.createIActionBarItemByClass(item.name, item.title, item.iconName, needSeparator);
Expand Down
47 changes: 45 additions & 2 deletions packages/survey-creator-core/tests/creator-toolbox.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ test("Add-remove toolbox items, #5271", (): any => {
}
});
creator.currentAddQuestionType = "dropdown";
creator.addNewQuestionInPage(() => {}, undefined, "dropdown");
creator.addNewQuestionInPage(() => { }, undefined, "dropdown");
expect(creator.getAddNewQuestionText()).toEqual("Add Question");
});
test("Add-remove toolbox items, #5067", (): any => {
Expand All @@ -204,4 +204,47 @@ test("Add-remove toolbox items, #5067", (): any => {
expect(creator.selectedElement.getType()).toEqual("text");
const adorner = new QuestionAdornerViewModel(creator, <SurveyElement>creator.selectedElement, undefined);
expect(adorner.getConvertToTypesActions()).toHaveLength(0);
});
});
test("Doesn't duplicate custom toolbox items with built-in ones in convertTo", (): any => {
const creator = new CreatorTester();
creator.toolbox.addItem({
name: "country",
title: "Country",
json: {
type: "dropdown",
placeholder: "Select a country...",
choicesByUrl: {
url: "https://surveyjs.io/api/CountriesExample",
},
},
} as any);
creator.JSON = {
elements: [
{ type: "radiogroup", name: "q1" }
]
};
const question = creator.survey.getQuestionByName("q1");
creator.selectElement(question);
const questionModel = new QuestionAdornerViewModel(
creator,
question,
undefined as any
);

const items = questionModel.getConvertToTypesActions();
let counter = 0;
items.forEach(item => {
if (item.id === "dropdown") counter++;
});
expect(counter).toEqual(1);

const popup = questionModel.getActionById("convertTo").popupModel;
expect(popup).toBeTruthy();
const list = popup.contentComponentData.model;
expect(list).toBeTruthy();
counter = 0;
list.actions.forEach(item => {
if (item.id === "dropdown") counter++;
});
expect(counter).toEqual(1);
});

0 comments on commit ad70284

Please sign in to comment.