From 3154a8fa008b43e2655faf4c2b0dd3c2c5c24a27 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Sun, 31 Dec 2023 19:36:40 +0200 Subject: [PATCH] Matrices doesn't work correctly if a column visibleIf returns false for all rows fix #7613 --- src/question_matrixdropdownbase.ts | 2 +- testCafe/questions/matrixdynamic.js | 43 +++++++++++++++++++++++ tests/question_matrixdropdownbasetests.ts | 28 +++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/question_matrixdropdownbase.ts b/src/question_matrixdropdownbase.ts index 16c52136a5..35f04751ec 100644 --- a/src/question_matrixdropdownbase.ts +++ b/src/question_matrixdropdownbase.ts @@ -1458,7 +1458,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel): void { const choices = q.visibleChoices; diff --git a/testCafe/questions/matrixdynamic.js b/testCafe/questions/matrixdynamic.js index 5d76867686..64925fb1fd 100644 --- a/testCafe/questions/matrixdynamic.js +++ b/testCafe/questions/matrixdynamic.js @@ -323,4 +323,47 @@ frameworks.forEach((framework) => { const surveyResult = await getSurveyResult(); await t.expect(surveyResult.matrix.length).eql(1); }); +}); +const json4 = { + "textUpdateMode": "onTyping", + "focusFirstQuestionAutomatic": true, + "elements": [ + { + "type": "matrixdynamic", + "name": "matrix", + "rowCount": 1, + "columns": [ + { + "name": "col1", + "cellType": "text" + }, + { + "name": "col2", + "cellType": "text" + }, + { + "name": "col3", + "cellType": "text", + "visibleIf": "false" + } + ] + } + ] +}; + +frameworks.forEach((framework) => { + fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach( + async (t) => { + await initSurvey(framework, json4); + } + ); + test("column.visibleIf returns always false and rebuilding table", async (t) => { + await t.resizeWindow(1920, 1080); + await t.pressKey("a b c") + .pressKey("tab") + .pressKey("e d f") + .click(completeButton); + const surveyResult = await getSurveyResult(); + await t.expect(surveyResult.matrix).eql([{ col1: "abc", col2: "edf" }]); + }); }); \ No newline at end of file diff --git a/tests/question_matrixdropdownbasetests.ts b/tests/question_matrixdropdownbasetests.ts index 1808c67fe6..9ed4c04b5c 100644 --- a/tests/question_matrixdropdownbasetests.ts +++ b/tests/question_matrixdropdownbasetests.ts @@ -1073,4 +1073,32 @@ QUnit.test("checkIfValueInRowDuplicated has only one duplicated error", function assert.equal(cellQuestion2.getType(), "tagbox", "type #2"); assert.equal(cellQuestion1.choices.length, 3, "choices #1"); assert.equal(cellQuestion2.choices.length, 4, "choices #2"); +}); +QUnit.test("Do not resetTable for always invisible column", function (assert) { + const survey = new SurveyModel({ + "elements": [ + { + "type": "matrixdynamic", + "name": "matrix", + "rowCount": 1, + "columns": [ + { + "name": "col1", + "cellType": "text" + }, + { + "name": "col2", + "cellType": "text", + "visibleIf": "false" + } + ] + } + ] + }); + const matrix = survey.getQuestionByName("matrix"); + const cellQuestion = matrix.visibleRows[0].cells[0].question; + const table = matrix.renderedTable; + table["$ref"] = "ref1"; + cellQuestion.value = "test"; + assert.equal(matrix.renderedTable["$ref"], "ref1", "Do not recreate the rendered table"); }); \ No newline at end of file