From b4bcd557fed71cde860a4a67ab71e9b35bf387f6 Mon Sep 17 00:00:00 2001 From: tsv2013 Date: Fri, 27 Dec 2024 17:05:21 +0300 Subject: [PATCH] SurveyModel: Rename `completeLastPage()` to `tryComplete()` (#9218) * SurveyModel: renamings Fixes #9209 * Add fixes for the docs --------- Co-authored-by: tsv2013 Co-authored-by: RomanTsukanov --- ...esign-survey-create-a-multi-page-survey.md | 2 +- packages/survey-core/src/survey.ts | 35 ++++++--- packages/survey-core/tests/paneltests.ts | 4 +- .../tests/question_baseselecttests.ts | 2 +- .../survey-core/tests/question_customtests.ts | 4 +- .../tests/question_matrix_tests.ts | 2 +- .../tests/question_matrixdynamictests.ts | 6 +- .../tests/question_multipletexttests.ts | 2 +- .../tests/question_paneldynamic_tests.ts | 8 +- .../survey-core/tests/question_texttests.ts | 2 +- .../tests/surveyShowPreviewTests.ts | 14 ++-- .../survey-core/tests/surveyquestiontests.ts | 2 +- packages/survey-core/tests/surveytests.ts | 78 +++++++++---------- .../survey-core/tests/surveytriggertests.ts | 2 +- testCafe/survey/customNavigation.js | 4 +- tests/markup/etalon_matrixdropdown.ts | 4 +- tests/markup/etalon_multipletext.ts | 4 +- 17 files changed, 94 insertions(+), 81 deletions(-) diff --git a/docs/design-survey-create-a-multi-page-survey.md b/docs/design-survey-create-a-multi-page-survey.md index 2ef9982c4b..6a024d2032 100644 --- a/docs/design-survey-create-a-multi-page-survey.md +++ b/docs/design-survey-create-a-multi-page-survey.md @@ -238,7 +238,7 @@ if (!navigatedBack) { alert("Navigation failed!") } -const completedSuccessfully = survey.completeLastPage(); +const completedSuccessfully = survey.tryComplete(); if (!completedSuccessfully) { alert("Check the answers for validation errors") } diff --git a/packages/survey-core/src/survey.ts b/packages/survey-core/src/survey.ts index 1857be958b..873266540c 100644 --- a/packages/survey-core/src/survey.ts +++ b/packages/survey-core/src/survey.ts @@ -424,7 +424,8 @@ export class SurveyModel extends SurveyElementCore */ public onGetQuestionNumber: EventBase = this.addEvent(); /** - * This event is obsolete. Use the [`onGetQuestionNumber`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onGetQuestionNumber) event instead. + * Obsolete. Use the [`onGetQuestionNumber`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onGetQuestionNumber) event instead. + * @deprecated */ public onGetQuestionNo: EventBase = this.onGetQuestionNumber; /** @@ -664,7 +665,8 @@ export class SurveyModel extends SurveyElementCore */ public onMatrixRowAdding: EventBase = this.addEvent(); /** - * This event is obsolete. Use the [`onMatrixRowAdding`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onMatrixRowAdding) event instead. + * Obsolete. Use the [`onMatrixRowAdding`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onMatrixRowAdding) event instead. + * @deprecated */ public onMatrixBeforeRowAdded: EventBase = this.onMatrixRowAdding; @@ -687,7 +689,8 @@ export class SurveyModel extends SurveyElementCore */ public onMatrixRenderRemoveButton: EventBase = this.addEvent(); /** - * This event is obsolete. Use the [`onMatrixRenderRemoveButton`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onMatrixRenderRemoveButton) event instead. + * Obsolete. Use the [`onMatrixRenderRemoveButton`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onMatrixRenderRemoveButton) event instead. + * @deprecated */ public onMatrixAllowRemoveRow: EventBase = this.onMatrixRenderRemoveButton; /** @@ -712,7 +715,8 @@ export class SurveyModel extends SurveyElementCore */ public onAfterRenderMatrixCell: EventBase = this.addEvent(); /** - * This event is obsolete. Use the [`onAfterRenderMatrixCell`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onAfterRenderMatrixCell) event instead. + * Obsolete. Use the [`onAfterRenderMatrixCell`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onAfterRenderMatrixCell) event instead. + * @deprecated */ public onMatrixAfterCellRender: EventBase = this.onAfterRenderMatrixCell; @@ -1252,7 +1256,8 @@ export class SurveyModel extends SurveyElementCore @property() containerCss: string; @property({ onSet: (newValue, target: SurveyModel) => { target.updateCss(); } }) fitToContainer: boolean; /** - * This property is obsolete. Use the [`headerView`](https://surveyjs.io/form-library/documentation/api-reference/itheme#headerView) property within a theme instead. + * Obsolete. Use the [`headerView`](https://surveyjs.io/form-library/documentation/api-reference/itheme#headerView) property within a theme instead. + * @deprecated */ @property({ onSet: (newValue, target: SurveyModel) => { @@ -3854,7 +3859,8 @@ export class SurveyModel extends SurveyElementCore DomDocumentHelper.setCookie(this.cookieName + "=;"); } /** - * This property is obsolete. Use the [`validationEnabled`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#validationEnabled) property instead. + * Obsolete. Use the [`validationEnabled`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#validationEnabled) property instead. + * @deprecated */ public get ignoreValidation(): boolean { return !this.validationEnabled; } public set ignoreValidation(val: boolean) { this.validationEnabled = !val; } @@ -4231,7 +4237,7 @@ export class SurveyModel extends SurveyElementCore * @see isCurrentPageValid * @see nextPage */ - public completeLastPage(): boolean { + public tryComplete(): boolean { if (this.isValidateOnComplete) { this.cancelPreview(); } @@ -4241,6 +4247,13 @@ export class SurveyModel extends SurveyElementCore } return res; } + /** + * Obsolete. Use the [`tryComplete`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#tryComplete) method instead. + * @deprecated + */ + public completeLastPage(): boolean { + return this.tryComplete(); + } private isNavigationButtonPressed: boolean = false; public navigationMouseDown(): boolean { this.isNavigationButtonPressed = true; @@ -6445,7 +6458,7 @@ export class SurveyModel extends SurveyElementCore mouseDown: () => this.navigationMouseDown(), }, locTitle: this.locCompleteText, - action: () => this.taskManager.waitAndExecute(() => this.completeLastPage()), + action: () => this.taskManager.waitAndExecute(() => this.tryComplete()), component: defaultComponent }); this.updateNavigationItemCssCallback = () => { @@ -6810,7 +6823,7 @@ export class SurveyModel extends SurveyElementCore if (this.isShowPreviewBeforeComplete) { this.showPreview(); } else { - this.completeLastPage(); + this.tryComplete(); } } }; @@ -7615,13 +7628,13 @@ export class SurveyModel extends SurveyElementCore this.onTimerTick.fire(this, {}); if (this.timeLimit > 0 && this.timeLimit <= this.timeSpent) { this.timeSpent = this.timeLimit; - this.completeLastPage(); + this.tryComplete(); } if (page) { var pageLimit = page.getMaxTimeToFinish(); if (pageLimit > 0 && pageLimit == page.timeSpent) { if (this.isLastPage) { - this.completeLastPage(); + this.tryComplete(); } else { this.nextPage(); } diff --git a/packages/survey-core/tests/paneltests.ts b/packages/survey-core/tests/paneltests.ts index 323757214b..eb075b72ef 100644 --- a/packages/survey-core/tests/paneltests.ts +++ b/packages/survey-core/tests/paneltests.ts @@ -1827,7 +1827,7 @@ QUnit.test("Expand panel on error in multiple text question", function(assert) { }); const panel = survey.getPanelByName("panel"); assert.equal(panel.state, "collapsed", "the panel is collapsed by default"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(panel.state, "expanded", "the panel is expanded"); }); @@ -2836,7 +2836,7 @@ QUnit.test("Check if errors disappered in the closest questions on changing the q2.value = 6; assert.equal(q1.errors.length, 0, "q1.errors #1"); assert.equal(q2.errors.length, 0, "q2.errors #1"); - assert.equal(survey.completeLastPage(), false, "Could not complete"); + assert.equal(survey.tryComplete(), false, "Could not complete"); assert.equal(q1.errors.length, 1, "q1.errors #2"); assert.equal(q2.errors.length, 1, "q2.errors #2"); q1.value = 1; diff --git a/packages/survey-core/tests/question_baseselecttests.ts b/packages/survey-core/tests/question_baseselecttests.ts index 1070e4b767..35fbfd8c68 100644 --- a/packages/survey-core/tests/question_baseselecttests.ts +++ b/packages/survey-core/tests/question_baseselecttests.ts @@ -1206,7 +1206,7 @@ QUnit.test("selectbase, showOtherItem & checkErrorsMode: 'onValueChanged'", (ass const q1 = survey.getQuestionByName("q1"); q1.renderedValue = "other"; assert.equal(q1.errors.length, 0, "We do not have errors yet"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(q1.errors.length, 1, "There is an error"); assert.equal(survey.state, "running", "Still running"); }); diff --git a/packages/survey-core/tests/question_customtests.ts b/packages/survey-core/tests/question_customtests.ts index 1943f6c8f0..450fe3e80a 100644 --- a/packages/survey-core/tests/question_customtests.ts +++ b/packages/survey-core/tests/question_customtests.ts @@ -849,7 +849,7 @@ QUnit.test("Composite: remove invisible values", function (assert) { lastName.value = "last"; assert.equal(lastName.value, "last", "value set correctly"); firstName.value = "Jon"; - survey.completeLastPage(); + survey.tryComplete(); assert.deepEqual( survey.data, { q1: { firstName: "Jon" } }, @@ -3079,7 +3079,7 @@ QUnit.test("Single: showPreviewBeforeComplete Bug#8005", function (assert) { survey.getQuestionByName("question1").value = 1; survey.showPreview(); assert.deepEqual(survey.data, { question1: 1 }, "survey.data #2"); - survey.completeLastPage(); + survey.tryComplete(); assert.deepEqual(survey.data, { question1: 1 }, "survey.data #2"); ComponentCollection.Instance.clear(); }); diff --git a/packages/survey-core/tests/question_matrix_tests.ts b/packages/survey-core/tests/question_matrix_tests.ts index 82be317fea..6e050664bc 100644 --- a/packages/survey-core/tests/question_matrix_tests.ts +++ b/packages/survey-core/tests/question_matrix_tests.ts @@ -369,7 +369,7 @@ QUnit.test("matrix isAllRowRequired & getItemClass", function (assert) { let row = question.visibleRows[1]; assert.equal(question.getItemClass(row, column1).indexOf(itemError) > -1, false, "itemError doesn't exist in column 1, #1"); assert.equal(question.getItemClass(row, column2).indexOf(itemError) > -1, false, "itemError doesn't exist in column 2, #1"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "running", "There is an error"); row = question.visibleRows[1]; assert.equal(question.getItemClass(row, column1).indexOf(itemError) > -1, true, "itemError exists in column 1, #2"); diff --git a/packages/survey-core/tests/question_matrixdynamictests.ts b/packages/survey-core/tests/question_matrixdynamictests.ts index 8e91618ce4..85c8b0991a 100644 --- a/packages/survey-core/tests/question_matrixdynamictests.ts +++ b/packages/survey-core/tests/question_matrixdynamictests.ts @@ -5743,7 +5743,7 @@ QUnit.test( 0, "There is no errors yet in the cell, second row, first column" ); - survey.completeLastPage(); + survey.tryComplete(); assert.equal( rows[0].cells[1].question.errors.length, 1, @@ -9072,7 +9072,7 @@ QUnit.test("Errors: matrixdropdown", function (assert) { assert.equal(table.rows[0].cells[2].isErrorsCell, true); assert.strictEqual(table.rows[0].cells[2].question, table.rows[1].cells[2].question); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(table.rows[0].visible, true); assert.equal(table.rows[2].visible, true); table.rows[1].cells[1].question.value = "Item1"; @@ -10310,7 +10310,7 @@ QUnit.test("Validation doesn't work if a user doensn't visit the page, Bug#8937" checkErrorsMode: "onComplete" }); survey.currentPageNo = 2; - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "running", "Still running"); assert.equal(survey.currentPageNo, 1, "move to page with panel"); const matrix = survey.getQuestionByName("matrix"); diff --git a/packages/survey-core/tests/question_multipletexttests.ts b/packages/survey-core/tests/question_multipletexttests.ts index 2380aec508..caf013970e 100644 --- a/packages/survey-core/tests/question_multipletexttests.ts +++ b/packages/survey-core/tests/question_multipletexttests.ts @@ -166,7 +166,7 @@ QUnit.test("Check error row visibility", (assert) => { }); const question = survey.getAllQuestions()[0]; assert.notOk(question.getRows()[0].isVisible); - survey.completeLastPage(); + survey.tryComplete(); assert.ok(question.getRows()[0].isVisible); question.items[0].editor.value = "test"; assert.ok(question.getRows()[0].isVisible); diff --git a/packages/survey-core/tests/question_paneldynamic_tests.ts b/packages/survey-core/tests/question_paneldynamic_tests.ts index e3035085fb..beb2bcae76 100644 --- a/packages/survey-core/tests/question_paneldynamic_tests.ts +++ b/packages/survey-core/tests/question_paneldynamic_tests.ts @@ -3484,7 +3484,7 @@ QUnit.test( assert.equal(q2.errors.length, 0, "and there is no error in the second question"); q1.value = ""; assert.equal(q1.errors.length, 1, "We have the error in q1 now"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(q1.errors.length, 1, "There is error in the first question"); assert.equal(q2.errors.length, 1, "There is error in the second question"); } @@ -5421,7 +5421,7 @@ QUnit.test("Two nested invisible dynamic panels do not clear itself correctly, B }); const rootPanel = survey.getQuestionByName("rootPanel"); rootPanel.panels[0].getQuestionByName("q1").value = 2; - survey.completeLastPage(); + survey.tryComplete(); assert.deepEqual(survey.data, { "rootPanel": [{ "q1": 2 }] }, "There is no empty data for any nested panels"); }); @@ -5499,7 +5499,7 @@ QUnit.test("Error in nested dynamic collapsed panel", (assert) => { const rootPanel = survey.getQuestionByName("rootPanel"); const childPanel = rootPanel.panels[0].getQuestionByName("childPanel"); assert.equal(childPanel.state, "collapsed", "child panel State is collapsed by default"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(childPanel.state, "expanded", "child panel state is expanded now"); }); QUnit.test("Error in nested dynamic collapsed panel && renderMode - progressTop", (assert) => { @@ -7641,7 +7641,7 @@ QUnit.test("Validation doesn't work if a user doensn't visit the page, Bug#8937" checkErrorsMode: "onComplete" }); survey.currentPageNo = 2; - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "running", "Still running"); assert.equal(survey.currentPageNo, 1, "move to page with panel"); const panel = survey.getQuestionByName("panel"); diff --git a/packages/survey-core/tests/question_texttests.ts b/packages/survey-core/tests/question_texttests.ts index 76a0756694..eb21c11ac7 100644 --- a/packages/survey-core/tests/question_texttests.ts +++ b/packages/survey-core/tests/question_texttests.ts @@ -493,7 +493,7 @@ QUnit.test("inputType='date' invalid value, #8617", function(assert) { q1.onKeyUp(event); q1.value = undefined; assert.equal(q1.errors.length, 0, "errors #2"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(q1.errors.length, 1, "errors #3"); assert.equal(q1.errors[0].text, "Invalid date", "errors #4"); assert.equal(survey.state, "running", "survey.state #1"); diff --git a/packages/survey-core/tests/surveyShowPreviewTests.ts b/packages/survey-core/tests/surveyShowPreviewTests.ts index bc3b9002cf..37749e5916 100644 --- a/packages/survey-core/tests/surveyShowPreviewTests.ts +++ b/packages/survey-core/tests/surveyShowPreviewTests.ts @@ -173,7 +173,7 @@ QUnit.test( survey.showPreviewBeforeComplete = "showAllQuestions"; survey.currentPageNo = 1; survey.showPreview(); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.visiblePages.length, 2, "We have two pages again"); assert.equal(survey.currentPageNo, 1, "Current page is the last one"); } @@ -195,10 +195,10 @@ QUnit.test( survey.currentPageNo = 1; survey.showPreview(); assert.equal(survey.state, "preview"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "preview", "Keep showing preview"); allowComplete = true; - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed"); } ); @@ -756,10 +756,10 @@ QUnit.test("showPreviewBeforeComplete = 'showAnsweredQuestions' and all question assert.equal(survey.state, "preview", "We do not check for errors"); survey.cancelPreview(); assert.equal(survey.state, "running", "running again"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "running", "We have errors, we can't fix errors"); survey.setValue("q1", "a"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed", "No errors"); } ); @@ -775,10 +775,10 @@ QUnit.test("showPreviewBeforeComplete = 'showAnsweredQuestions' & checkErrorsMod }); survey.nextPage(); survey.showPreview(); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "running", "We have errors, we can't fix errors"); survey.setValue("q1", "a"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed", "No errors"); } ); diff --git a/packages/survey-core/tests/surveyquestiontests.ts b/packages/survey-core/tests/surveyquestiontests.ts index d002614778..72d4d79c30 100644 --- a/packages/survey-core/tests/surveyquestiontests.ts +++ b/packages/survey-core/tests/surveyquestiontests.ts @@ -7000,7 +7000,7 @@ QUnit.test("survey.onMultipleTextItemAdded", function (assert) { const q2 = survey.getQuestionByName("q2"); q1.value = "yes"; assert.equal(q2.isRequired, true, "q2 is required"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(q2.errors.length, 1, "One error is shown"); q1.value = "no"; assert.equal(q2.isRequired, false, "q2 is not required"); diff --git a/packages/survey-core/tests/surveytests.ts b/packages/survey-core/tests/surveytests.ts index a9ec147c5f..d3700de7fb 100644 --- a/packages/survey-core/tests/surveytests.ts +++ b/packages/survey-core/tests/surveytests.ts @@ -489,7 +489,7 @@ QUnit.test("Do not show errors if ignoreValidation = true", function ( survey.nextPage(); assert.equal(q1.errors.length, 0, "There is a required error"); assert.equal(survey.currentPageNo, 1, "Can move into another page"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed", "Can complete survey with erros"); }); QUnit.test("Show error, but allow to navigate if validationAllowSwitchPages = true and validationAllowComplete=true", function (assert) { @@ -507,7 +507,7 @@ QUnit.test("Show error, but allow to navigate if validationAllowSwitchPages = tr assert.equal(q1.errors.length, 1, "There is an error"); survey.nextPage(); assert.equal(survey.currentPageNo, 1, "Can move into another page"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed", "Can complete survey with erros"); }); QUnit.test("Show error, but allow to navigate if survey.validationAllowSwitchPages = true", function (assert) { @@ -524,7 +524,7 @@ QUnit.test("Show error, but allow to navigate if survey.validationAllowSwitchPag assert.equal(q1.errors.length, 1, "There is an error"); survey.nextPage(); assert.equal(survey.currentPageNo, 1, "Can move into another page"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.currentPageNo, 0, "Move to the first page"); }); QUnit.test("Check pages state on onValueChanged event", function (assert) { @@ -1116,7 +1116,7 @@ QUnit.test("Survey state", function (assert) { assert.equal(survey.state, "running", "Survey is in run mode"); survey.nextPage(); assert.equal(survey.state, "running", "Survey is in run mode"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed", "Survey is completed"); }); QUnit.test("Question Creator", function (assert) { @@ -1603,13 +1603,13 @@ QUnit.test("survey.checkErrorsMode = 'onComplete'", function (assert) { var survey = new SurveyModel(json); survey.nextPage(); assert.equal(survey.currentPageNo, 1, "Ignore error on the first page"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.currentPageNo, 0, "Move to first page with the error"); survey.afterRenderPage({}); survey.nextPage(); assert.equal(survey.currentPageNo, 1, "Ignore error on the first page, #2"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal( survey.currentPageNo, 0, @@ -1619,11 +1619,11 @@ QUnit.test("survey.checkErrorsMode = 'onComplete'", function (assert) { survey.setValue("q1", "john.snow@nightwatch.org"); survey.nextPage(); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.currentPageNo, 1, "Stay on second page"); assert.equal(survey.state, "running", "There is an error on the second page"); survey.setValue("q2", "a"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed", "No errors, completed"); }); @@ -2040,7 +2040,7 @@ QUnit.test("onComplete event", function (assert) { }); survey.nextPage(); survey.nextPage(); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed", "The survey is completed"); assert.equal(counter, 1, "onComplete calls one time"); }); @@ -2493,8 +2493,8 @@ QUnit.test( 1, "Validation on next page is completed" ); - survey.completeLastPage(); - survey.completeLastPage(); + survey.tryComplete(); + survey.tryComplete(); assert.equal( survey.currentPage.visibleIndex, 1, @@ -2742,7 +2742,7 @@ QUnit.test( assert.equal(survey.state, "running"); assert.equal(survey.isCompleteButtonVisible, true, "complete button is visible"); assert.equal(survey.isShowNextButton, false, "next button is invisible"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed"); assert.equal( isCompleteOnTrigger_Completing, @@ -2756,7 +2756,7 @@ QUnit.test( ); survey.clear(); survey.nextPage(); - survey.completeLastPage(); + survey.tryComplete(); assert.equal( isCompleteOnTrigger_Completing, false, @@ -7646,7 +7646,7 @@ QUnit.test( ); survey.data = {}; q1.isRequired = true; - assert.equal(survey.completeLastPage(), false, "You can't complete the last page"); + assert.equal(survey.tryComplete(), false, "You can't complete the last page"); } ); @@ -11321,7 +11321,7 @@ QUnit.test("Test onValidatedErrorsOnCurrentPage event", function (assert) { survey.clearValue("q3"); assert.equal(counter, 5, "Do not call errors validation on clearing value"); assert.equal(errors.length, 0, "there is no errors on clearing value"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(counter, 6, "called six times"); assert.equal(errors.length, 2, "there are two errors onComplete, #5"); assert.equal(questions.length, 2, "there are two question onComplete, #6"); @@ -11333,12 +11333,12 @@ QUnit.test("Server validation - do no fire onValidatedErrorsOnCurrentPage on ch survey.onValidatedErrorsOnCurrentPage.add(function (sender, options) { counter++; }); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "running"); assert.equal(counter, 1, "On complete"); survey.setValue("name", "Jon"); assert.equal(counter, 1, "We do not make complete"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(counter, 2, "Do complete again"); } ); @@ -12329,7 +12329,7 @@ QUnit.test( panelDynamic.value = [{}]; assert.equal(question.isEmpty(), true, "Question is empty"); assert.equal(panelDynamic.containsErrors, false, "We do not show error on value change in panel itself"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(panelDynamic.containsErrors, true, "The panel has errors after value changed to empty. Show it on next page event" ); @@ -13039,7 +13039,7 @@ QUnit.test( var question1 = survey.getQuestionByName("question1"); question1.value = { "Row 1": "Column 2" }; assert.equal(question1.errors.length, 0, "There is no errors yet"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal( question1.errors.length, 1, @@ -13082,7 +13082,7 @@ QUnit.test( 0, "There is no errors in item2" ); - survey.completeLastPage(); + survey.tryComplete(); assert.equal( question1.items[1].editor.errors.length, 1, @@ -13125,7 +13125,7 @@ QUnit.test("Remove errors on settings correct values, multipletext", function ( var question1 = ( survey.getQuestionByName("question1") ); - survey.completeLastPage(); + survey.tryComplete(); assert.equal( question1.items[0].editor.errors.length, 1, @@ -13174,7 +13174,7 @@ QUnit.test("Remove errors on settings correct values, paneldynamic", function ( ], }); var panel = survey.getQuestionByName("panel1"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal( panel.panels[0].questions[0].errors.length, 1, @@ -13202,7 +13202,7 @@ QUnit.test("Remove errors on settings correct values, matrtixdynamic", function }); var matrix = survey.getQuestionByName("matrix"); var question = matrix.visibleRows[0].cells[0].question; - survey.completeLastPage(); + survey.tryComplete(); assert.equal( question.errors.length, 1, @@ -13256,7 +13256,7 @@ QUnit.test( }); var q1 = survey.getQuestionByName("q1"); var q2 = survey.getQuestionByName("q2"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(q1.errors.length, 1, "q1 is required"); assert.equal(q2.errors.length, 1, "q2 is required"); assert.equal( @@ -13325,7 +13325,7 @@ QUnit.test( }); var q1 = survey.getQuestionByName("q1"); q1.value = q1.otherItem.value; - survey.completeLastPage(); + survey.tryComplete(); assert.equal(q1.errors.length, 1, "There is an error right now"); q1.comment = "some value"; assert.equal(q1.errors.length, 0, "There is no error now"); @@ -14061,7 +14061,7 @@ QUnit.test( options.errors["q2"] = "error"; options.complete(); }); - survey.completeLastPage(); + survey.tryComplete(); assert.equal( survey.getQuestionByName("q1").inputId, focusedQuestionId, @@ -14069,7 +14069,7 @@ QUnit.test( ); survey.setValue("q1", "val1"); focusedQuestionId = ""; - survey.completeLastPage(); + survey.tryComplete(); assert.equal( survey.getQuestionByName("q2").inputId, focusedQuestionId, @@ -14108,7 +14108,7 @@ QUnit.test( }, ], }); - survey.completeLastPage(); + survey.tryComplete(); returnResult(0); assert.equal( survey.getQuestionByName("q1").inputId, @@ -14117,7 +14117,7 @@ QUnit.test( ); survey.setValue("q1", "val1"); focusedQuestionId = ""; - survey.completeLastPage(); + survey.tryComplete(); returnResult(0); assert.equal( survey.getQuestionByName("q2").inputId, @@ -14185,7 +14185,7 @@ QUnit.test( }); survey.nextPage(); survey.nextPage(); - survey.completeLastPage(); + survey.tryComplete(); survey.afterRenderPage({}); assert.equal(survey.currentPageNo, 0, "The first page is active"); assert.equal( @@ -14235,7 +14235,7 @@ QUnit.test( assert.equal(survey.currentPageNo, 1, "Allow to go the second page"); survey.nextPage(); assert.equal(survey.currentPageNo, 2, "Allow to go the third page"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.currentPageNo, 0, "The first page is active"); assert.equal(q1Value, "val1", "options.data set correctly"); assert.equal( @@ -14274,7 +14274,7 @@ QUnit.test("Focus errored question when checkErrorsMode: `onComplete` & panel re }); survey.nextPage(); survey.nextPage(); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.currentPageNo, 0, "comeback to the first page"); assert.equal(survey.getQuestionByName("q1").inputId, focusedQuestionId, "panel is required"); SurveyElement.FocusElement = oldFunc; @@ -14308,7 +14308,7 @@ QUnit.test("Do not focus errored question when checkErrorsMode: `onComplete` + f survey.nextPage(); survey.nextPage(); focusedQuestionId = ""; - survey.completeLastPage(); + survey.tryComplete(); survey.afterRenderPage({}); assert.equal(survey.currentPageNo, 0, "The first page is active"); assert.notOk(focusedQuestionId, "do not focus any question"); @@ -14387,7 +14387,7 @@ QUnit.test("Several onServerValidateQuestions event, bug#4531", options.errors["q2"] = "error"; options.complete(); }); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "running", "Survey is not completed"); assert.equal(survey.getQuestionByName("q2").errors.length, 1, "There is an error in the question"); } @@ -14406,7 +14406,7 @@ QUnit.test("Several onServerValidateQuestions event without errors, bug#4531 par survey.onServerValidateQuestions.add((sender, options) => { options.complete(); }); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed", "Survey is completed"); } ); @@ -16974,7 +16974,7 @@ QUnit.test("Survey Localization - check errors update after locale changed", fun q5.value = 9; q6.value = "other"; - survey.completeLastPage(); + survey.tryComplete(); assert.equal(q1.errors.length, 1); assert.equal(q1.errors[0].locText.renderedHtml, "Response required."); @@ -18681,7 +18681,7 @@ QUnit.test("check title classes when readOnly changed", function (assert) { question.readOnly = false; assert.notOk(question.cssTitle.includes(customDisabledClass)); }); -QUnit.test("Do not run onComplete twice if complete trigger and completeLastPage() is called", function (assert) { +QUnit.test("Do not run onComplete twice if complete trigger and tryComplete() is called", function (assert) { const survey = new SurveyModel({ "elements": [ { @@ -18705,7 +18705,7 @@ QUnit.test("Do not run onComplete twice if complete trigger and completeLastPage counter++; }); survey.setValue("question1", 1); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(counter, 1, "onComplete called one time"); }); QUnit.test("Expression with dates & defaultValueExpression & expression question", function (assert) { @@ -20393,7 +20393,7 @@ QUnit.test("PageModel passed property", function (assert) { assert.equal(survey.pages[2].passed, true, "4) Page 3 is passed"); survey.nextPage(); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.pages[0].passed, true, "5) Page 1 is passed"); assert.equal(survey.pages[1].passed, true, "5) Page 2 is passed"); assert.equal(survey.pages[2].passed, true, "5) Page 3 is passed"); diff --git a/packages/survey-core/tests/surveytriggertests.ts b/packages/survey-core/tests/surveytriggertests.ts index 746b4d61f1..d1ff012956 100644 --- a/packages/survey-core/tests/surveytriggertests.ts +++ b/packages/survey-core/tests/surveytriggertests.ts @@ -277,7 +277,7 @@ QUnit.test("On trigger executed && options.completeTrigger", function( }); survey.setValue("q1", 3); assert.equal(survey.state, "running"); - survey.completeLastPage(); + survey.tryComplete(); assert.equal(survey.state, "completed"); assert.equal(isCompleteEvent, true); assert.equal(completeTrigger.expression, "{q1} = 3"); diff --git a/testCafe/survey/customNavigation.js b/testCafe/survey/customNavigation.js index 39c2e63afe..2c7dfd9efc 100644 --- a/testCafe/survey/customNavigation.js +++ b/testCafe/survey/customNavigation.js @@ -28,8 +28,8 @@ const setCustomNavigation = ClientFunction(() => { window["survey"].nextPage(); event.preventDefault(); }; - document.getElementById("surveyComplete").onclick = function() { - window["survey"].completeLastPage(); + document.getElementById("surveyComplete").onclick = function () { + window["survey"].tryComplete(); event.preventDefault(); }; diff --git a/tests/markup/etalon_matrixdropdown.ts b/tests/markup/etalon_matrixdropdown.ts index 885b9a2164..f391067d20 100644 --- a/tests/markup/etalon_matrixdropdown.ts +++ b/tests/markup/etalon_matrixdropdown.ts @@ -193,7 +193,7 @@ registerMarkupTests( }, before: () => StylesManager.applyTheme("defaultV2"), initSurvey(survey) { - survey.completeLastPage(); + survey.tryComplete(); }, after: () => StylesManager.applyTheme("default"), snapshot: "matrixdropdown-cell-errors-top" @@ -220,7 +220,7 @@ registerMarkupTests( }, before: () => StylesManager.applyTheme("defaultV2"), initSurvey(survey) { - survey.completeLastPage(); + survey.tryComplete(); }, after: () => StylesManager.applyTheme("default"), snapshot: "matrixdropdown-cell-errors-bottom" diff --git a/tests/markup/etalon_multipletext.ts b/tests/markup/etalon_multipletext.ts index 6803a95bcd..96b30d2562 100644 --- a/tests/markup/etalon_multipletext.ts +++ b/tests/markup/etalon_multipletext.ts @@ -128,7 +128,7 @@ registerMarkupTests( }, before: () => StylesManager.applyTheme("defaultV2"), initSurvey(survey) { - survey.completeLastPage(); + survey.tryComplete(); }, after: () => StylesManager.applyTheme("default"), snapshot: "multipletext-error-top-v2", @@ -156,7 +156,7 @@ registerMarkupTests( }, before: () => StylesManager.applyTheme("defaultV2"), initSurvey(survey) { - survey.completeLastPage(); + survey.tryComplete(); }, after: () => StylesManager.applyTheme("default"), snapshot: "multipletext-error-bottom-v2",