From 0f3f5c6ea258a5b13db4e4a4439bd3776dadd2bd Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Fri, 10 Nov 2023 16:26:52 +0200 Subject: [PATCH] Fix functional tests in Creator --- src/question_baseselect.ts | 22 ++++++++++++---------- src/question_imagepicker.ts | 4 +++- tests/entries/test.ts | 1 + tests/question_imagepickertests.ts | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 tests/question_imagepickertests.ts diff --git a/src/question_baseselect.ts b/src/question_baseselect.ts index ab52505ff6..7147e6c512 100644 --- a/src/question_baseselect.ts +++ b/src/question_baseselect.ts @@ -901,16 +901,7 @@ export class QuestionSelectBase extends Question { protected addToVisibleChoices(items: Array, isAddAll: boolean): void { this.headItemsCount = 0; this.footItemsCount = 0; - if (isAddAll) { - if (!this.newItemValue) { - this.newItemValue = this.createItemValue("newitem"); //TODO - this.newItemValue.isGhost = true; - } - if (!this.isUsingCarryForward && this.canShowOptionItem(this.newItemValue, isAddAll, false)) { - this.footItemsCount ++; - items.push(this.newItemValue); - } - } + this.addNewItemToVisibleChoices(items, isAddAll); const dict = new Array<{ index: number, item: ItemValue }>(); this.addNonChoicesItems(dict, isAddAll); dict.sort((a: { index: number, item: ItemValue }, b: { index: number, item: ItemValue }): number => { @@ -929,6 +920,17 @@ export class QuestionSelectBase extends Question { } } } + protected addNewItemToVisibleChoices(items: Array, isAddAll: boolean): void { + if (!isAddAll) return; + if (!this.newItemValue) { + this.newItemValue = this.createItemValue("newitem"); //TODO + this.newItemValue.isGhost = true; + } + if (!this.isUsingCarryForward && this.canShowOptionItem(this.newItemValue, isAddAll, false)) { + this.footItemsCount = 1; + items.push(this.newItemValue); + } + } protected addNonChoicesItems(dict: Array<{ index: number, item: ItemValue }>, isAddAll: boolean): void { if ( this.supportNone() && this.canShowOptionItem(this.noneItem, isAddAll, this.hasNone) diff --git a/src/question_imagepicker.ts b/src/question_imagepicker.ts index 96f00a057a..84ab6c1d96 100644 --- a/src/question_imagepicker.ts +++ b/src/question_imagepicker.ts @@ -296,7 +296,9 @@ export class QuestionImagePickerModel extends QuestionCheckboxBase { protected isBuiltInChoice(item: ItemValue, question: QuestionSelectBase): boolean { return false; } - protected addToVisibleChoices(items: Array, isAddAll: boolean): void { } + protected addToVisibleChoices(items: Array, isAddAll: boolean): void { + this.addNewItemToVisibleChoices(items, isAddAll); + } public getSelectBaseRootCss(): string { return new CssClassBuilder().append(super.getSelectBaseRootCss()).append(this.cssClasses.rootColumn, this.getCurrentColCount() == 1).toString(); } diff --git a/tests/entries/test.ts b/tests/entries/test.ts index cde37f1a83..ac3ea7def4 100644 --- a/tests/entries/test.ts +++ b/tests/entries/test.ts @@ -39,6 +39,7 @@ export * from "../questionImagepicker"; export * from "../questionBooleanTests"; export * from "../question_baseselecttests"; export * from "../question_imagetests"; +export * from "../question_imagepickertests"; export * from "../question_ratingtests"; export * from "../question_texttests"; export * from "../question_customtests"; diff --git a/tests/question_imagepickertests.ts b/tests/question_imagepickertests.ts new file mode 100644 index 0000000000..c518d842c2 --- /dev/null +++ b/tests/question_imagepickertests.ts @@ -0,0 +1,21 @@ +import { QuestionImagePickerModel } from "../src/question_imagepicker"; +import { settings } from "../src/settings"; +import { SurveyModel } from "../src/survey"; + +QUnit.test("Items number in run-time and design-time", function (assert) { + settings.supportCreatorV2 = true; + const json = { + elements: [ + { type: "imagepicker", name: "q", choices: ["a", "b", "c"] } + ] + }; + const survey1 = new SurveyModel(json); + const q1 = survey1.getQuestionByName("q"); + const survey2 = new SurveyModel(); + survey2.setDesignMode(true); + survey2.fromJSON(json); + const q2 = survey2.getQuestionByName("q"); + assert.equal(q1.visibleChoices.length, 3, "There are 3 items in run-time"); + assert.equal(q2.visibleChoices.length, 4, "There are 4 items in design-time"); + settings.supportCreatorV2 = false; +}); \ No newline at end of file