Skip to content

Commit

Permalink
Add tests on matrices #6869
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Sep 21, 2023
1 parent 168a93e commit 11887e8
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,7 @@ Serializer.addClass("question", [
{ name: "valueName", onSettingValue: (obj: any, val: any): any => { return makeNameValid(val); } },
"enableIf:condition",
{
name: "clearValueIf:expression",
name: "clearValueIf:condition",
category: "logic", visible: false
},
"defaultValue:value",
Expand Down
12 changes: 12 additions & 0 deletions src/question_matrixdropdowncolumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ export class MatrixDropdownColumn extends Base
public set requiredIf(val: string) {
this.templateQuestion.requiredIf = val;
}
public get clearValueIf(): string {
return this.templateQuestion.clearValueIf;
}
public set clearValueIf(val: string) {
this.templateQuestion.clearValueIf = val;
}
public get defaultValueExpression(): string {
return this.templateQuestion.defaultValueExpression;
}
public set defaultValueExpression(val: string) {
this.templateQuestion.defaultValueExpression = val;
}
public get isUnique(): boolean {
return this.getPropertyValue("isUnique");
}
Expand Down
69 changes: 68 additions & 1 deletion tests/question_matrixdropdownbasetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,71 @@ QUnit.test("column.visible property and design time", function (assert) {
assert.equal(table.headerRow.cells.length, 1 + 3, "Header: Two columns are invisible, but it is visible in design-time, #2");
assert.equal(table.rows[1].cells.length, 1 + 3, "Row: Two columns are invisible, but it is visible in design-time, #2");
assert.equal(table.headerRow.cells[3].headers, "col3", "The last column is col3, #2");
});
});
QUnit.test("question.clearValueIf, basic functionality", function (assert) {
const survey = new SurveyModel({
elements: [
{
type: "matrixdynamic",
name: "matrix",
rowCount: 1,
columns: [{
name: "q1",
typeType: "text"
},
{
name: "q2",
typeType: "text",
clearValueIf: "{row.q1} = 1"
}
]
}
]
});
const matrix = survey.getQuestionByName("matrix");
const row = matrix.visibleRows[0];
const q1 = row.getQuestionByName("q1");
const q2 = row.getQuestionByName("q2");
const col2 = matrix.getColumnByName("q2");
assert.equal(col2.clearValueIf, "{row.q1} = 1", "Load from JSON, column");
assert.equal(q2.clearValueIf, "{row.q1} = 1", "Load from JSON, question");
q2.value = "abc";
q1.value = 2;
assert.equal(q2.value, "abc", "value is set");
q1.value = 1;
assert.equal(q2.isEmpty(), true, "value is cleared");
});
QUnit.test("question.clearValueIf & quesiton.defaultValueExpression", function (assert) {
const survey = new SurveyModel({
elements: [
{
type: "matrixdynamic",
name: "matrix",
rowCount: 1,
columns: [{
name: "q1",
cellType: "text"
},
{
name: "q2",
cellType: "text",
clearValueIf: "{row.q1} = 1",
defaultValueExpression: "iif({row.q3} > 2, {row.q3}, '')"
},
{
name: "q3", cellType: "text"
}]
}
]
});
const matrix = survey.getQuestionByName("matrix");
const row = matrix.visibleRows[0];
const q1 = row.getQuestionByName("q1");
const q2 = row.getQuestionByName("q2");
const q3 = row.getQuestionByName("q3");
q2.value = "abc";
q3.value = 3;
assert.equal(q2.value, "abc", "value is set directly");
q1.value = 1;
assert.equal(q2.value, 3, "value is set from defaultValueExpression");
});

0 comments on commit 11887e8

Please sign in to comment.