diff --git a/src/question_file.ts b/src/question_file.ts index aa33f08a47..35e7edec00 100644 --- a/src/question_file.ts +++ b/src/question_file.ts @@ -921,9 +921,8 @@ export class QuestionFileModel extends QuestionFileModelBase { super.updateElementCss(reNew); this.updateCurrentMode(); } - - endLoadingFromJson(): void { - super.endLoadingFromJson(); + public onSurveyLoad(): void { + super.onSurveyLoad(); this.updateCurrentMode(); this.updateActionsVisibility(); this.loadPreview(this.value); diff --git a/tests/questionFileTests.ts b/tests/questionFileTests.ts index 311ecd878c..e999a5e8cc 100644 --- a/tests/questionFileTests.ts +++ b/tests/questionFileTests.ts @@ -1129,7 +1129,7 @@ QUnit.test("QuestionFile remove file by preview value", function (assert) { }); }); -QUnit.test("QuestionFile download file content on preview", function (assert) { +QUnit.test("QuestionFile download file content on preview, #1", function (assert) { var json = { showPreviewBeforeComplete: "showAnsweredQuestions", elements: [ @@ -1386,7 +1386,7 @@ QUnit.test("Check file question processResponsiveness method", (assert) => { assert.equal(question.pageSize, 4); }); -QUnit.test("QuestionFile download file content on preview", function (assert) { +QUnit.test("QuestionFile download file content on preview, #2", function (assert) { const survey = new SurveyModel({ elements: [ { type: "file", name: "q1" }, diff --git a/tests/question_customtests.ts b/tests/question_customtests.ts index 499e639b03..285bf1e653 100644 --- a/tests/question_customtests.ts +++ b/tests/question_customtests.ts @@ -16,6 +16,7 @@ import { LocalizableString } from "../src/localizablestring"; import { PanelModel } from "../src/panel"; import { StylesManager } from "../src/stylesmanager"; import { ArrayChanges, Base } from "../src/base"; +import { QuestionFileModel } from "../src/question_file"; export default QUnit.module("custom questions"); @@ -2891,3 +2892,54 @@ QUnit.test("Bug with visibleIf with composite.question and panel dynamic. Bug#77 assert.equal(q2.isVisible, true, "isVisible #3"); ComponentCollection.Instance.clear(); }); +QUnit.test("file question in composite component doesn't show preview in preview mode. Bug#7826", function (assert) { + ComponentCollection.Instance.add({ + name: "test", + elementsJSON: [ + { + type: "file", + name: "file_q", + allowMultiple: true, + storeDataAsText: false + }, + ] + }); + + const survey = new SurveyModel({ + elements: [ + { type: "test", name: "q1" }, + { type: "file", name: "q2", storeDataAsText: false } + ] + }); + survey.onUploadFiles.add((survey, options) => { + options.callback( + "success", + options.files.map((file) => { + return { file: file, content: file.name + "_url" }; + }) + ); + }); + + const compQuestion = survey.getQuestionByName("q1"); + const file_q1 = compQuestion.contentPanel.getQuestionByName("file_q"); + const file_q2 = survey.getQuestionByName("q2"); + file_q1.loadFiles([{ name: "f1", type: "t1" } as any]); + file_q2.loadFiles([{ name: "f1", type: "t1" } as any]); + assert.equal(file_q1.showPreviewContainer, true, "file_q1 #1"); + assert.equal(file_q2.showPreviewContainer, true, "file_q2 #1"); + + survey.showPreview(); + assert.equal(survey.state, "preview", "state #1"); + const compQuestion_preview = survey.getQuestionByName("q1"); + const file_q1_preview = compQuestion_preview.contentPanel.getQuestionByName("file_q"); + const file_q2_preview = survey.getQuestionByName("q2"); + assert.equal(file_q1_preview.showPreviewContainer, true, "file_q1_preview #1"); + assert.equal(file_q2_preview.showPreviewContainer, true, "file_q2_preview #1"); + + survey.cancelPreview(); + assert.equal(survey.state, "running", "state #2"); + assert.equal(file_q1.showPreviewContainer, true, "file_q1 #1"); + assert.equal(file_q2.showPreviewContainer, true, "file_q2 #1"); + + ComponentCollection.Instance.clear(); +}); \ No newline at end of file