Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 committed Feb 21, 2023
1 parent 4da3d04 commit 5a9fcda
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/itemvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export class ItemValue extends BaseAction implements ILocalizableOwner, IShortcu
}
public ownerPropertyName: string = "";
//private itemValue: any;
@property({ defaultValue: true}) private _visible: boolean;
private locTextValue: LocalizableString;
private visibleConditionRunner: ConditionRunner;
private enableConditionRunner: ConditionRunner;
Expand Down Expand Up @@ -425,10 +426,12 @@ export class ItemValue extends BaseAction implements ILocalizableOwner, IShortcu
this.setIsEnabled(val);
}
protected getVisible(): boolean {
return this.isVisible;
const isVisible = this.isVisible === undefined ? true : this.isVisible;
const visible = this._visible === undefined ? true : this._visible;
return isVisible && visible;
}
protected setVisible(val: boolean): void {
this.setIsVisible(val);
this._visible = val;
}
protected getLocTitle(): LocalizableString {
return this.locText;
Expand Down
28 changes: 28 additions & 0 deletions tests/questionDropdownTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,4 +941,32 @@ QUnit.test("show comment and show other together", assert => {
assert.equal(question.getStoreOthersAsComment(), true, "show comment is hidden");
question.showCommentArea = true;
assert.equal(question.getStoreOthersAsComment(), false, "show comment again");
});

QUnit.test("ItemValue: check action fields", assert => {
const json = {
questions: [{
"type": "dropdown",
itemComponent: "custom-component",
defaultValue: "Item1",
"choices": [{ text: "Item 1", value: "Item1" }, { text: "Item 2", value: "Item2" }]
}]
};
const survey = new SurveyModel(json);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
assert.equal(question.visibleChoices[0].component, "custom-component");
assert.equal(question.visibleChoices[0].locTitle.text, "Item 1");
assert.equal(question.visibleChoices[0].title, "Item 1");
assert.equal(question.visibleChoices[0].id, "Item1");
assert.equal(question.visibleChoices[0].visible, true);
question.visibleChoices[0].setIsVisible(false);
assert.equal(question.visibleChoices[0].visible, false);
assert.equal(question.visibleChoices[0].enabled, true);
question.visibleChoices[0].setIsEnabled(false);
assert.equal(question.visibleChoices[0].enabled, false);
assert.equal(question.visibleChoices[0].selected, true);
assert.equal(question.visibleChoices[1].selected, false);
question.value = "Item2";
assert.equal(question.visibleChoices[0].selected, false);
assert.equal(question.visibleChoices[1].selected, true);
});

0 comments on commit 5a9fcda

Please sign in to comment.