From e8b8870ba06622563093ecc920738cdc27168936 Mon Sep 17 00:00:00 2001 From: OlgaLarina Date: Wed, 10 Jul 2024 15:56:16 +0300 Subject: [PATCH] work for #8530 --- src/survey.ts | 8 +++++--- tests/surveytests.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/survey.ts b/src/survey.ts index 5931895545..2927225dfb 100644 --- a/src/survey.ts +++ b/src/survey.ts @@ -3330,7 +3330,9 @@ export class SurveyModel extends SurveyElementCore } private updateActivePage(): void { const newPage = this.isShowStartingPage ? this.startedPage : this.currentPage; - this.setPropertyValue("activePage", newPage); + if (newPage !== this.activePage) { + this.setPropertyValue("activePage", newPage); + } } private onStateAndCurrentPageChanged(): void { this.updateActivePage(); @@ -6073,11 +6075,11 @@ export class SurveyModel extends SurveyElementCore isCompleted: string, response: any ) { - self.isLoading = false; if (success) { self.isCompletedBefore = isCompleted == "completed"; self.loadSurveyFromServiceJson(json); } + self.isLoading = false; } ); } else { @@ -6086,10 +6088,10 @@ export class SurveyModel extends SurveyElementCore result: string, response: any ) { - self.isLoading = false; if (success) { self.loadSurveyFromServiceJson(result); } + self.isLoading = false; }); } } diff --git a/tests/surveytests.ts b/tests/surveytests.ts index 2a646f8dec..c32f7854bf 100644 --- a/tests/surveytests.ts +++ b/tests/surveytests.ts @@ -6587,6 +6587,49 @@ QUnit.test("surveyId + clientId", function (assert) { assert.equal(q1.name, "q1", "The survey created from the string"); }); +QUnit.test("surveyId + clientId several page render", function (assert) { + let log = ""; + let curState = ""; + const json = { questions: [{ type: "text", name: "q1" }] }; + class dxSurveyServiceTester extends dxSurveyService { + public getSurveyJsonAndIsCompleted(surveyId: string, clientId: string, onLoad: (success: boolean, surveyJson: any, result: string, response: any) => void) { + if (onLoad) { + onLoad(true, json, clientId, ""); + } + } + } + class SurveyTester extends SurveyModel { + protected createSurveyService(): dxSurveyService { + return new dxSurveyServiceTester(); + } + protected propertyValueChanged(name: string, oldValue: any, newValue: any, arrayChanges?: ArrayChanges, target?: Base): void { + super.propertyValueChanged(name, oldValue, newValue, arrayChanges); + if (name === "isLoading" || name === "state" || name === "activePage") { + log += ("-> " + name + ":" + newValue); + } + } + protected onLoadSurveyFromService(): void { + super.onLoadSurveyFromService(); + curState = this.state; + assert.equal(curState, "loading"); + } + protected setPropertyValueDirectly(name: string, val: any): void { + if (name === "activePage" && !!val) { + assert.ok(this.activePage === undefined, "this.activePage undefined"); + assert.ok(!!val, "new activePage"); + } + super.setPropertyValueDirectly(name, val); + } + } + + let survey = new SurveyTester({ surveyId: "surveyDummyId", clientId: "completed" }); + assert.equal(survey.state, "completedbefore", "The survey is running"); + assert.equal(log, "-> state:empty-> state:loading-> isLoading:true-> activePage:page1-> state:completedbefore-> isLoading:false"); + + let q1 = survey.getQuestionByName("q1"); + assert.equal(q1.name, "q1", "The survey created from the string"); +}); + QUnit.test( "Question description and text processing, variable, Bug #632", function (assert) {