diff --git a/functionalTests/dxService/loadSurvey.js b/functionalTests/dxService/loadSurvey.js index bce655d61a..3268f346be 100644 --- a/functionalTests/dxService/loadSurvey.js +++ b/functionalTests/dxService/loadSurvey.js @@ -13,7 +13,7 @@ frameworks.forEach(framework => { } ); - test("correct loading", async t => { + test.skip("correct loading", async t => { let surveyResult; await setRowItemFlowDirection(); diff --git a/packages/survey-core/entries/chunks/model.ts b/packages/survey-core/entries/chunks/model.ts index d85628fb02..29186e12f8 100644 --- a/packages/survey-core/entries/chunks/model.ts +++ b/packages/survey-core/entries/chunks/model.ts @@ -243,7 +243,6 @@ export { TextPreProcessor } from "../../src/textPreProcessor"; export { Notifier } from "../../src/notifier"; export { Cover, CoverCell } from "../../src/header"; -export { dxSurveyService } from "../../src/dxSurveyService"; export { englishStrings } from "../../src/localization/english"; export { surveyLocalization, surveyStrings, getLocaleString, getLocaleStrings, setupLocale } from "../../src/surveyStrings"; // export { cultureInfo } from "../../src/cultureInfo"; diff --git a/packages/survey-core/src/dxSurveyService.ts b/packages/survey-core/src/dxSurveyService.ts deleted file mode 100644 index 44fec08a13..0000000000 --- a/packages/survey-core/src/dxSurveyService.ts +++ /dev/null @@ -1,138 +0,0 @@ -import { settings } from "./settings"; -import { getLocaleString } from "./surveyStrings"; - -const surveyIOSite = "surveyjs.io"; -const surveyIOMaxPostSize = 65536; -/** - * The class contains methods to work with api.surveyjs.io service. - */ -export class dxSurveyService { - public locale: string; - public static get serviceUrl(): string { - return settings.web.surveyServiceUrl; - } - public static set serviceUrl(val: string) { - settings.web.surveyServiceUrl = val; - } - public loadSurvey(surveyId: string, - onLoad: (success: boolean, result: string, response: any) => void): void { - var xhr = new XMLHttpRequest(); - xhr.open( - "GET", - this.serviceUrl + "/getSurvey?surveyId=" + surveyId - ); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.onload = function () { - var result = JSON.parse(xhr.response); - onLoad(xhr.status == 200, result, xhr.response); - }; - xhr.send(); - } - public getSurveyJsonAndIsCompleted(surveyId: string, clientId: string, - onLoad: (success: boolean, surveyJson: any, result: string, response: any) => void): void { - var xhr = new XMLHttpRequest(); - xhr.open( - "GET", - this.serviceUrl + - "/getSurveyAndIsCompleted?surveyId=" + - surveyId + - "&clientId=" + - clientId - ); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.onload = function () { - var result = JSON.parse(xhr.response); - var surveyJson = result ? result.survey : null; - var isCompleted = result ? result.isCompleted : null; - onLoad(xhr.status == 200, surveyJson, isCompleted, xhr.response); - }; - xhr.send(); - } - public canSendResult(result: JSON): boolean { - if (!this.isSurveJSIOService) return true; - const str = JSON.stringify(result); - return str.length < surveyIOMaxPostSize; - } - public get isSurveJSIOService(): boolean { - return this.serviceUrl.indexOf(surveyIOSite) >= 0; - } - public sendResult(postId: string, result: JSON, - onSendResult: (success: boolean, response: any, request?: any) => void, - clientId: string = null, isPartialCompleted: boolean = false): void { - if (!this.canSendResult(result)) { - onSendResult(false, getLocaleString("savingExceedSize", this.locale), undefined); - } else { - this.sendResultCore(postId, result, onSendResult, clientId, isPartialCompleted); - } - } - protected sendResultCore(postId: string, result: JSON, - onSendResult: (success: boolean, response: any, request?: any) => void, - clientId: string = null, isPartialCompleted: boolean = false): void { - var xhr = new XMLHttpRequest(); - xhr.open("POST", this.serviceUrl + "/post/"); - xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8"); - var data = { postId: postId, surveyResult: JSON.stringify(result) }; - if (clientId) (data)["clientId"] = clientId; - if (isPartialCompleted) (data)["isPartialCompleted"] = true; - var dataStringify: string = JSON.stringify(data); - xhr.onload = xhr.onerror = function () { - if (!onSendResult) return; - onSendResult(xhr.status === 200, xhr.response, xhr); - }; - xhr.send(dataStringify); - } - public sendFile(postId: string, file: File, - onSendFile: (success: boolean, response: any) => void): void { - var xhr = new XMLHttpRequest(); - xhr.onload = xhr.onerror = function () { - if (!onSendFile) return; - onSendFile(xhr.status == 200, JSON.parse(xhr.response)); - }; - xhr.open("POST", this.serviceUrl + "/upload/", true); - var formData = new FormData(); - formData.append("file", file); - formData.append("postId", postId); - xhr.send(formData); - } - public getResult(resultId: string, name: string, - onGetResult: (success: boolean, data: any, dataList: Array, response: any) => void): void { - var xhr = new XMLHttpRequest(); - var data = "resultId=" + resultId + "&name=" + name; - xhr.open("GET", this.serviceUrl + "/getResult?" + data); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - var self = this; - xhr.onload = function () { - var result = null; - var list = null; - if (xhr.status == 200) { - result = JSON.parse(xhr.response); - list = []; - for (var key in result.QuestionResult) { - var el = { name: key, value: result.QuestionResult[key] }; - list.push(el); - } - } - onGetResult(xhr.status == 200, result, list, xhr.response); - }; - xhr.send(); - } - public isCompleted(resultId: string, clientId: string, - onIsCompleted: (success: boolean, result: string, response: any) => void): void { - var xhr = new XMLHttpRequest(); - var data = "resultId=" + resultId + "&clientId=" + clientId; - xhr.open("GET", this.serviceUrl + "/isCompleted?" + data); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - var self = this; - xhr.onload = function () { - var result = null; - if (xhr.status == 200) { - result = JSON.parse(xhr.response); - } - onIsCompleted(xhr.status == 200, result, xhr.response); - }; - xhr.send(); - } - private get serviceUrl(): string { - return dxSurveyService.serviceUrl || ""; - } -} diff --git a/packages/survey-core/src/settings.ts b/packages/survey-core/src/settings.ts index c82e51edc0..a2e38ef51e 100644 --- a/packages/survey-core/src/settings.ts +++ b/packages/survey-core/src/settings.ts @@ -117,7 +117,7 @@ export var settings = { * Disables a question while its choices are being loaded from a web service. Default value: `false`. * * - `surveyServiceUrl`: `string`\ - * The URL of the SurveyJS Service API endpoint. + * Obsolete. Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). * * - `onBeforeRequestChoices`: `(sender: ChoicesRestful, options: { request: XMLHttpRequest })`\ * An event that is raised before a request for choices is send. Applies to questions with a specified [`choiceByUrl`](https://surveyjs.io/form-library/documentation/api-reference/questionselectbase#choicesByUrl) property. Use the `options.request` parameter to access and modify the `XMLHttpRequest` object. For instance, you can add authentication headers to it: @@ -125,7 +125,7 @@ export var settings = { * ```js * import { settings } from "survey-core"; * - * settings.web.onBeforeSendRequest = (sender, options) => { + * settings.web.onBeforeRequestChoices = (sender, options) => { * options.request.setRequestHeader('RequestVerificationToken', requestVerificationToken); * }; * ``` @@ -134,8 +134,7 @@ export var settings = { onBeforeRequestChoices: (sender: any, options: { request: XMLHttpRequest }): void => { }, encodeUrlParams: true, cacheLoadedChoices: true, - disableQuestionWhileLoadingChoices: false, - surveyServiceUrl: "https://api.surveyjs.io/public/v1/Survey" + disableQuestionWhileLoadingChoices: false }, //#region web section, obsolete properties @@ -147,8 +146,6 @@ export var settings = { set useCachingForChoicesRestfull(val: boolean) { this.web.cacheLoadedChoices = val; }, get disableOnGettingChoicesFromWeb(): boolean { return this.web.disableQuestionWhileLoadingChoices; }, set disableOnGettingChoicesFromWeb(val: boolean) { this.web.disableQuestionWhileLoadingChoices = val; }, - get surveyServiceUrl(): string { return this.web.surveyServiceUrl; }, - set surveyServiceUrl(val: string) { this.web.surveyServiceUrl = val; }, //#endregion /** diff --git a/packages/survey-core/src/survey.ts b/packages/survey-core/src/survey.ts index 9255342ebe..7f1698b72e 100644 --- a/packages/survey-core/src/survey.ts +++ b/packages/survey-core/src/survey.ts @@ -30,7 +30,6 @@ import { CalculatedValue } from "./calculatedValue"; import { PageModel } from "./page"; import { TextPreProcessor, TextPreProcessorValue } from "./textPreProcessor"; import { ProcessValue } from "./conditionProcessValue"; -import { dxSurveyService } from "./dxSurveyService"; import { surveyLocalization } from "./surveyStrings"; import { CustomError } from "./error"; import { LocalizableString } from "./localizablestring"; @@ -474,12 +473,11 @@ export class SurveyModel extends SurveyElementCore public onTextRenderAs: EventBase = this.addEvent(); /** - * An event that is raised after a request to save survey results on [SurveyJS Service](https://api.surveyjs.io/) has been completed. Use this event to find out if the results have been saved successfully. + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ public onSendResult: EventBase = this.addEvent(); /** - * An event that is raised when the [`getResult(resultId, questionName)`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#getResult) method is called. Use this event to obtain answers to an individual question from [SurveyJS Service](https://api.surveyjs.io/). - * @see getResult + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ public onGetResult: EventBase = this.addEvent(); /** @@ -530,10 +528,7 @@ export class SurveyModel extends SurveyElementCore public onLoadChoicesFromServer: EventBase = this.onChoicesLoaded; /** - * An event that is raised after a survey JSON schema is loaded from the [SurveyJS Service](https://api.surveyjs.io). Use this event to modify the loaded schema. - * @see surveyId - * @see clientId - * @see loadSurveyFromService + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ public onLoadedSurveyFromService: EventBase = this.addEvent(); @@ -1443,11 +1438,7 @@ export class SurveyModel extends SurveyElementCore this.setPropertyValue("calculatedValues", val); } /** - * The identifier of a survey JSON schema to load from [SurveyJS Service](https://api.surveyjs.io). - * - * Refer to the following help topic for more information: [Store Survey Results in the SurveyJS Service](https://surveyjs.io/form-library/documentation/handle-survey-results-store#store-survey-results-in-the-surveyjs-service). - * @see loadSurveyFromService - * @see onLoadedSurveyFromService + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ public get surveyId(): string { return this.getPropertyValue("surveyId", ""); @@ -1456,11 +1447,7 @@ export class SurveyModel extends SurveyElementCore this.setPropertyValue("surveyId", val); } /** - * An identifier used to save survey results to [SurveyJS Service](https://api.surveyjs.io). - * - * Refer to the following help topic for more information: [Store Survey Results in the SurveyJS Service](https://surveyjs.io/form-library/documentation/handle-survey-results-store#store-survey-results-in-the-surveyjs-service). - * @see onComplete - * @see surveyShowDataSaving + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ public get surveyPostId(): string { return this.getPropertyValue("surveyPostId", ""); @@ -1469,10 +1456,7 @@ export class SurveyModel extends SurveyElementCore this.setPropertyValue("surveyPostId", val); } /** - * A user identifier (e-mail or other unique ID). - * - * If your application works with [SurveyJS Service](https://api.surveyjs.io), the ID ensures that users do not pass the same survey twice. On the second run, they will see the [Completed Before page](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#completedBeforeHtml). - * @see cookieName + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ public get clientId(): string { return this.getPropertyValue("clientId", ""); @@ -1513,10 +1497,7 @@ export class SurveyModel extends SurveyElementCore this.partialSendEnabled = val; } /** - * Specifies whether to show progress when the survey sends data to [SurveyJS Service](https://api.surveyjs.io). - * - * [View Demo](https://surveyjs.io/form-library/examples/save-survey-results-and-load-surveys-from-surveyjs-service/ (linkStyle)) - * @see surveyPostId + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ public get surveyShowDataSaving(): boolean { return this.getPropertyValue("surveyShowDataSaving"); @@ -2585,8 +2566,7 @@ export class SurveyModel extends SurveyElementCore return this.getLocalizableString("completedBeforeHtml"); } /** - * HTML content displayed while a survey JSON schema is being loaded from [SurveyJS Service](https://api.surveyjs.io). - * @see surveyId + * HTML content displayed while a survey JSON schema is [being loaded](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#beginLoading). * @see processedLoadingHtml */ public get loadingHtml(): string { @@ -3791,7 +3771,20 @@ export class SurveyModel extends SurveyElementCore private set isLoading(val: boolean) { this.setPropertyValue("isLoading", val); } - + /** + * Displays the [Loading page](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#loadingHtml). + * @see endLoading + */ + public beginLoading(): void { + this.isLoading = true; + } + /** + * Stops displaying the [Loading page](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#loadingHtml). + * @see beginLoading + */ + public endLoading(): void { + this.isLoading = false; + } public get completedState(): string { return this.getPropertyValue("completedState", ""); } @@ -4876,14 +4869,12 @@ export class SurveyModel extends SurveyElementCore * 1. Switches the survey [`state`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#state) to `"completed"`. * 1. Raises the [`onComplete`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onComplete) event. * 1. Navigates the user to a URL specified by the [`navigateToUrl`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#navigateToUrl) or [`navigateToUrlOnCondition`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#navigateToUrlOnCondition) property. - * 1. Calls the [`sendResult()`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#sendResult) method if Form Library works with [SurveyJS Service](https://api.surveyjs.io/). * * The `doComplete()` method completes the survey regardless of validation errors and the current page. If you need to ensure that survey results are valid and full, call the [`completeLastPage()`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#completeLastPage) method instead. * * @param isCompleteOnTrigger For internal use. * @param completeTrigger For internal use. * @returns `false` if survey completion is cancelled within the [`onCompleting`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onCompleting) event handler; otherwise, `true`. - * @see surveyPostId */ public doComplete(isCompleteOnTrigger: boolean = false, completeTrigger?: Trigger): boolean { if (this.isCompleted) return; @@ -5129,7 +5120,7 @@ export class SurveyModel extends SurveyElementCore return this.locCompletedBeforeHtml.textOrHtml; } /** - * Returns HTML content displayed while a survey JSON schema is being loaded from [SurveyJS Service](https://api.surveyjs.io). + * Returns HTML content displayed while a survey JSON schema is [being loaded](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#beginLoading). * * To specify HTML content, use the [`loadingHtml`](#loadingHtml) property. */ @@ -5736,12 +5727,8 @@ export class SurveyModel extends SurveyElementCore * @see onUploadFiles * @see downloadFile */ - public uploadFiles( - question: QuestionFileModel | QuestionSignaturePadModel, - name: string, - files: File[], - callback: (data: any | Array, errors?: any | Array) => any - ) { + public uploadFiles(question: QuestionFileModel | QuestionSignaturePadModel, name: string, files: File[], + callback: (data: any | Array, errors?: any | Array) => any): void { if (this.onUploadFiles.isEmpty) { callback("error", this.getLocString("noUploadFilesHandler")); } else { @@ -5812,33 +5799,9 @@ export class SurveyModel extends SurveyElementCore loadedChoicesFromServer(question: IQuestion): void { this.locStrsChanged(); } - protected createSurveyService(): dxSurveyService { - return new dxSurveyService(); - } protected uploadFilesCore(name: string, files: File[], uploadingCallback: (data: any | Array, errors?: any | Array,) => any): void { - var responses: Array = []; - files.forEach((file) => { - if (uploadingCallback) uploadingCallback("uploading", file); - this.createSurveyService().sendFile( - this.surveyPostId, - file, - (success: boolean, response: any) => { - if (success) { - responses.push({ content: response, file: file }); - if (responses.length === files.length) { - if (uploadingCallback) uploadingCallback("success", responses); - } - } else { - if (uploadingCallback) - uploadingCallback("error", { - response: response, - file: file, - }); - } - } - ); - }); + this.reportWarningOnUsingService(); } getPage(index: number): PageModel { return this.pages[index]; @@ -6435,10 +6398,7 @@ export class SurveyModel extends SurveyElementCore } } /** - * Posts a survey result to [SurveyJS Service](https://api.surveyjs.io/). - * @param postId An identifier used to save survey results. You can find it on the [My Surveys](https://surveyjs.io/service/mysurveys) page. If you do not specify this parameter, the survey uses the [`surveyPostId`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#surveyPostId) property value. - * @param clientId A respondent identifier (e-mail or other unique ID). This ID ensures that the respondent does not pass the same survey twice. - * @param isPartial Pass `true` to save partial survey results (see [Continue an Incomplete Survey](https://surveyjs.io/form-library/documentation/handle-survey-results-continue-incomplete)). + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ public sendResult(postId: string = null, clientId: string = null, isPartial: boolean = false): void { if (!this.isEditMode) return; @@ -6454,96 +6414,28 @@ export class SurveyModel extends SurveyElementCore this.clientId = clientId; } if (isPartial && !this.clientId) return; - const service = this.createSurveyService(); - service.locale = this.getLocale(); - const showSaving = this.surveyShowDataSaving || (!isPartial && service.isSurveJSIOService); - if (showSaving) { - this.setCompletedState("saving", ""); - } - service.sendResult(postId, this.data, - (success: boolean, response: any, request: any) => { - if (showSaving || service.isSurveJSIOService) { - if (success) { - this.setCompletedState("success", ""); - } else { - this.setCompletedState("error", response); - } - } - const options = { success: success, response: response, request: request }; - this.onSendResult.fire(this, options); - }, - this.clientId, - isPartial - ); + this.reportWarningOnUsingService(); } /** - * Requests [SurveyJS Service](https://api.surveyjs.io/) to retrieve all answers to a specified question. Handle the [`onGetResult`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onGetResult) event to access the answers. - * @param resultId A result ID that identifies the required survey. You can find it on the [My Surveys](https://surveyjs.io/service/mysurveys) page. - * @param questionName A question name. + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ - public getResult(resultId: string, questionName: string) { - var self = this; - this.createSurveyService().getResult(resultId, questionName, function ( - success: boolean, - data: any, - dataList: any[], - response: any - ) { - self.onGetResult.fire(self, { - success: success, - data: data, - dataList: dataList, - response: response, - }); - }); + public getResult(resultId: string, questionName: string): void { + this.reportWarningOnUsingService(); } /** - * Loads a survey JSON schema from the [SurveyJS Service](https://api.surveyjs.io). You can handle the [`onLoadedSurveyFromService`](#onLoadedSurveyFromService) event to modify the schema after loading if required. - * @param surveyId The identifier of a survey JSON schema to load. Refer to the following help topic for more information: [Store Survey Results in the SurveyJS Service](https://surveyjs.io/form-library/documentation/handle-survey-results-store#store-survey-results-in-the-surveyjs-service). - * @param clientId A user identifier (e-mail or other unique ID) used to determine whether the user has already taken the survey. + * @deprecated Self-hosted Form Library [no longer supports integration with SurveyJS Demo Service](https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service). */ - public loadSurveyFromService( - surveyId: string = null, - clientId: string = null - ) { + public loadSurveyFromService(surveyId: string = null, clientId: string = null): void { if (surveyId) { this.surveyId = surveyId; } if (clientId) { this.clientId = clientId; } - var self = this; - this.isLoading = true; - this.onLoadingSurveyFromService(); - if (clientId) { - this.createSurveyService().getSurveyJsonAndIsCompleted( - this.surveyId, - this.clientId, - function ( - success: boolean, - json: string, - isCompleted: string, - response: any - ) { - if (success) { - self.isCompletedBefore = isCompleted == "completed"; - self.loadSurveyFromServiceJson(json); - } - self.isLoading = false; - } - ); - } else { - this.createSurveyService().loadSurvey(this.surveyId, function ( - success: boolean, - result: string, - response: any - ) { - if (success) { - self.loadSurveyFromServiceJson(result); - } - self.isLoading = false; - }); - } + this.reportWarningOnUsingService(); + } + private reportWarningOnUsingService(): void { + ConsoleWarnings.warn("Self-hosted Form Library no longer supports integration with SurveyJS Demo Service. Learn more: https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service"); } private loadSurveyFromServiceJson(json: any) { if (!json) return; @@ -6617,6 +6509,7 @@ export class SurveyModel extends SurveyElementCore this.jsonErrors = jsonConverter.errors; } this.onStateAndCurrentPageChanged(); + this.endLoading(); this.updateState(); if(!!this.sjsVersion && !!settings.version) { if(Helpers.compareVerions(this.sjsVersion, settings.version) > 0) { diff --git a/packages/survey-core/tests/entries/test.ts b/packages/survey-core/tests/entries/test.ts index 36068b3e4e..60fd734340 100644 --- a/packages/survey-core/tests/entries/test.ts +++ b/packages/survey-core/tests/entries/test.ts @@ -17,7 +17,6 @@ export * from "../question_matrixdropdownbasetests"; export * from "../question_paneldynamic_tests"; export * from "../surveyserializationtests"; // export * from "../surveytests"; // -export * from "../surveyServiceTests"; // export * from "../surveyWindowTests"; // export * from "../surveywidthmodetests"; // export * from "../surveytriggertests"; // @@ -79,6 +78,7 @@ export * from "../mask/mask_settings_tests"; export * from "../mask/multipletext_mask_settings_tests"; export * from "../headerTests"; export * from "../layout_tests"; +export * from "../surveyServiceRemovingTests"; // localization import "../../src/localization/russian"; diff --git a/packages/survey-core/tests/surveyServiceRemovingTests.ts b/packages/survey-core/tests/surveyServiceRemovingTests.ts new file mode 100644 index 0000000000..c663c64061 --- /dev/null +++ b/packages/survey-core/tests/surveyServiceRemovingTests.ts @@ -0,0 +1,64 @@ +import { ConsoleWarnings } from "../src/console-warnings"; +import { SurveyModel } from "../src/survey"; + +export default QUnit.module("SurveySerialization"); + +const errorText = "Self-hosted Form Library no longer supports integration with SurveyJS Demo Service. Learn more: https://surveyjs.io/stay-updated/release-notes/v2.0.0#form-library-removes-apis-for-integration-with-surveyjs-demo-service"; + +QUnit.test("survey.beginLoading()/survey.endLoading()", function (assert) { + const survey = new SurveyModel(); + assert.equal(survey.state, "empty", "state #1"); + survey.beginLoading(); + assert.equal(survey.state, "loading", "state #2"); + survey.endLoading(); + assert.equal(survey.state, "empty", "state #3"); + survey.beginLoading(); + assert.equal(survey.state, "loading", "state #4"); + survey.fromJSON({ elements: [{ type: "text", name: "q1" }] }); + assert.equal(survey.state, "running", "state #5"); +}); +QUnit.test("Show warning in console on loading survey", function(assert) { + const prev = ConsoleWarnings.warn; + let reportText: string = ""; + ConsoleWarnings.warn = (text: string) => { + reportText = text; + }; + let survey = new SurveyModel({ surveyId: "abcde" }); + + assert.equal(survey.state, "empty", "state #1"); + assert.equal(reportText, errorText, "Error on loading, #1"); + reportText = ""; + survey.loadSurveyFromService("abcde"); + assert.equal(reportText, errorText, "Error on loading, #2"); + + ConsoleWarnings.warn = prev; +}); +QUnit.test("Show warning in console on loading survey", function(assert) { + const prev = ConsoleWarnings.warn; + let reportText: string = ""; + ConsoleWarnings.warn = (text: string) => { + reportText = text; + }; + let survey = new SurveyModel({ surveyPostId: "abcde", elements: [{ type: "text", name: "q1", defaultValue: 1 }] }); + + assert.equal(survey.state, "running", "state #1"); + survey.doComplete(); + assert.equal(survey.state, "completed", "state #2"); + assert.equal(reportText, errorText, "Error on loading, #1"); + + ConsoleWarnings.warn = prev; +}); +QUnit.test("Show warning in console on sendResult/getResult", function(assert) { + const prev = ConsoleWarnings.warn; + let reportText: string = ""; + ConsoleWarnings.warn = (text: string) => { + reportText = text; + }; + let survey = new SurveyModel(); + survey.sendResult("abcde"); + assert.equal(reportText, errorText, "Error on sendResult, #1"); + reportText = ""; + survey.getResult("abcde", "q1"); + assert.equal(reportText, errorText, "Error on getResult, #2"); + ConsoleWarnings.warn = prev; +}); diff --git a/packages/survey-core/tests/surveyServiceTests.ts b/packages/survey-core/tests/surveyServiceTests.ts deleted file mode 100644 index eb55673e5f..0000000000 --- a/packages/survey-core/tests/surveyServiceTests.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { SurveyModel } from "../src/survey"; -import { dxSurveyService } from "../src/dxSurveyService"; - -export default QUnit.module("SurveyServiceTests"); - -class SurveyServiceTester extends dxSurveyService { - private onSendResult: any; - public doSendResult(success: boolean, response: any, request?: any): void { - if(!!this.onSendResult) { - this.onSendResult(success, response, request); - this.onSendResult = undefined; - } - } - public get isSavingData(): boolean { - return !!this.onSendResult; - } - protected sendResultCore(postId: string, result: JSON, - onSendResult: (success: boolean, response: any, request?: any) => void, - clientId: string = null, isPartialCompleted: boolean = false): void { - this.onSendResult = onSendResult; - } -} - -class SurveyModelTester extends SurveyModel { - public serviceTester: SurveyServiceTester; - public notiferList: Array = []; - constructor(jsonObj: any = null) { - super(jsonObj); - } - protected createSurveyService(): dxSurveyService { - this.serviceTester = new SurveyServiceTester(); - return this.serviceTester; - } - public notify(message: string, type: string, showActions: boolean = false): void { - this.notiferList.push({ message: message, type: type, showActions: showActions }); - } -} - -QUnit.test("Always show data saving for surveyjs io service, no errors", function(assert) { - const json = { - surveyPostId: "abc", - elements: [{ type: "comment", name: "q1", defaultValue: 1 }] - }; - const survey = new SurveyModelTester(json); - survey.getQuestionByName("q1").value = "0123456789"; - survey.doComplete(); - assert.equal(survey.serviceTester.isSavingData, true, "The data is saving"); - assert.equal(survey.serviceTester.isSurveJSIOService, true, "We are saving data into the surveyjs service"); - assert.equal(survey.completedStateText, "The results are being saved on the server...", "do saving #1"); - assert.equal(survey.notiferList.length, 1, "notiferList.length #1"); - assert.equal(survey.notiferList[0].type, "saving", "notiferList[0].type #1"); - survey.serviceTester.doSendResult(true, "", ""); - assert.equal(survey.completedStateText, "The results were saved successfully!", "do saving #2"); - assert.equal(survey.notiferList.length, 2, "notiferList.length #2"); - assert.equal(survey.notiferList[1].type, "success", "notiferList[1].type #2"); -}); -QUnit.test("Always show data saving for surveyjs io service, with errors", function(assert) { - const json = { - surveyPostId: "abc", - elements: [{ type: "comment", name: "q1" }] - }; - const survey = new SurveyModelTester(json); - survey.getQuestionByName("q1").value = "0123456789"; - survey.doComplete(); - assert.equal(survey.serviceTester.isSavingData, true, "The data is saving"); - assert.equal(survey.serviceTester.isSurveJSIOService, true, "We are saving data into the surveyjs service"); - assert.equal(survey.completedStateText, "The results are being saved on the server...", "do saving #1"); - assert.equal(survey.notiferList.length, 1, "notiferList.length #1"); - assert.equal(survey.notiferList[0].type, "saving", "notiferList[0].type #1"); - survey.serviceTester.doSendResult(false, "We have an error on the server", ""); - assert.equal(survey.completedStateText, "We have an error on the server", "do saving #2"); - assert.equal(survey.notiferList.length, 2, "notiferList.length #2"); - assert.equal(survey.notiferList[1].type, "error", "notiferList[1].type #2"); -}); -QUnit.test("Try to save a lot of data into the service", function(assert) { - const json = { - surveyPostId: "abc", - elements: [{ type: "comment", name: "q1" }] - }; - const survey = new SurveyModelTester(json); - let largeVal = ""; - for(let i = 0; i < 6556; i ++) { - largeVal += "0123456789"; - } - survey.getQuestionByName("q1").value = largeVal; - survey.doComplete(); - const errorText = "Your response exceeds 64KB. Please reduce the size of your file(s) and try again or contact the survey owner."; - assert.equal(survey.serviceTester.isSurveJSIOService, true, "We are saving data into the surveyjs service"); - assert.equal(survey.serviceTester.isSavingData, false, "The data is not saving. We got an error stright away"); - assert.equal(survey.completedStateText, errorText, "try to save"); - assert.equal(survey.notiferList.length, 2, "notiferList.length"); - assert.equal(survey.notiferList[0].type, "saving", "notiferList[0].type"); - assert.equal(survey.notiferList[1].type, "error", "notiferList[1].type"); - assert.equal(survey.notiferList[1].message, errorText, "notiferList[1].type"); -}); diff --git a/packages/survey-core/tests/surveytests.ts b/packages/survey-core/tests/surveytests.ts index ae02f69c36..ec98678194 100644 --- a/packages/survey-core/tests/surveytests.ts +++ b/packages/survey-core/tests/surveytests.ts @@ -41,7 +41,6 @@ import { QuestionMatrixDynamicModel } from "../src/question_matrixdynamic"; import { QuestionRatingModel } from "../src/question_rating"; import { CustomWidgetCollection } from "../src/questionCustomWidgets"; import { surveyCss } from "../src/defaultCss/defaultCss"; -import { dxSurveyService } from "../src/dxSurveyService"; import { FunctionFactory } from "../src/functionsfactory"; import { QuestionExpressionModel } from "../src/question_expression"; import { QuestionPanelDynamicModel } from "../src/question_paneldynamic"; @@ -6661,90 +6660,6 @@ QUnit.test("Clear value if empty array is set, Bug #608", function (assert) { assert.deepEqual(survey.data, {}, "The value with empty array is removed"); }); -QUnit.test("surveyId + clientId", function (assert) { - var 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(); - } - } - var survey = new SurveyTester({ surveyId: "surveyDummyId", clientId: "no" }); - assert.equal(survey.state, "running", "The survey is running"); - var q1 = survey.getQuestionByName("q1"); - assert.equal(q1.name, "q1", "The survey created from the string"); - - survey = new SurveyTester({ - surveyId: "surveyDummyId", - clientId: "completed", - }); - assert.equal( - survey.state, - "completedbefore", - "The survey was completed before" - ); - var q1 = survey.getQuestionByName("q1"); - 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) { @@ -21511,4 +21426,4 @@ QUnit.test("Show warning on loadig JSON created in higher version of Creator", f checkFunc("2.0.3", "2.0.2", true); ConsoleWarnings.warn = prevWarn; settings.version = oldVersion; -}); +}); \ No newline at end of file