Skip to content

Commit

Permalink
Add unit test on add new panel with default values & survey.onValueCh…
Browse files Browse the repository at this point in the history
…anged
  • Loading branch information
andrewtelnov committed Sep 24, 2023
1 parent 29ca7ad commit 086b1df
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4367,6 +4367,34 @@ QUnit.test("templateTitle test + survey.onValueChanged", function(assert) {
"the first panel title set correctly again"
);
});
QUnit.test("defaultValue & survey.onValueChanged on adding new panel", function(assert) {
const survey = new SurveyModel({
questions: [
{
name: "panel",
type: "paneldynamic",
templateElements: [
{ type: "text", name: "q1", defaultValue: 1 },
{ type: "text", name: "q2", defaultValue: 2 },
{ type: "text", name: "q3", defaultValueExpression: "{panel.q1} + {panel.q2}" },
{ type: "text", name: "q4", defaultValueExpression: "{val1}" }
]
}
],
});
survey.setValue("val1", 4);
let counter = 0;
survey.onValueChanged.add((sender, options) => {
counter ++;
});
const panel = <QuestionPanelDynamicModel>survey.getQuestionByName("panel");
panel.addPanel();
assert.deepEqual(panel.value, [{ q1: 1, q2: 2, q3: 3, q4: 4 }], "panel.value #1");
assert.equal(counter, 1, "survey.onValueChanged call times #1");
panel.addPanel();
assert.deepEqual(panel.value, [{ q1: 1, q2: 2, q3: 3, q4: 4 }, { q1: 1, q2: 2, q3: 3, q4: 4 }], "panel.value #2");
assert.equal(counter, 2, "survey.onValueChanged call times #2");
});
QUnit.test(
"Dependend choices not working properly in PanelDynamic Bug #2851",
function(assert) {
Expand Down

0 comments on commit 086b1df

Please sign in to comment.