Skip to content

Commit

Permalink
Fix functional tests in Creator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Nov 10, 2023
1 parent da6886f commit 0f3f5c6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,16 +901,7 @@ export class QuestionSelectBase extends Question {
protected addToVisibleChoices(items: Array<ItemValue>, 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 => {
Expand All @@ -929,6 +920,17 @@ export class QuestionSelectBase extends Question {
}
}
}
protected addNewItemToVisibleChoices(items: Array<ItemValue>, 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)
Expand Down
4 changes: 3 additions & 1 deletion src/question_imagepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ export class QuestionImagePickerModel extends QuestionCheckboxBase {
protected isBuiltInChoice(item: ItemValue, question: QuestionSelectBase): boolean {
return false;
}
protected addToVisibleChoices(items: Array<ItemValue>, isAddAll: boolean): void { }
protected addToVisibleChoices(items: Array<ItemValue>, isAddAll: boolean): void {
this.addNewItemToVisibleChoices(items, isAddAll);
}
public getSelectBaseRootCss(): string {
return new CssClassBuilder().append(super.getSelectBaseRootCss()).append(this.cssClasses.rootColumn, this.getCurrentColCount() == 1).toString();
}
Expand Down
1 change: 1 addition & 0 deletions tests/entries/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
21 changes: 21 additions & 0 deletions tests/question_imagepickertests.ts
Original file line number Diff line number Diff line change
@@ -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 = <QuestionImagePickerModel>survey1.getQuestionByName("q");
const survey2 = new SurveyModel();
survey2.setDesignMode(true);
survey2.fromJSON(json);
const q2 = <QuestionImagePickerModel>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;
});

0 comments on commit 0f3f5c6

Please sign in to comment.