From f45c3679b5c2d9390395477a0fd700820ba1399d Mon Sep 17 00:00:00 2001 From: Dmitry Kuzin Date: Tue, 9 Apr 2024 00:22:40 +0400 Subject: [PATCH] Fix file question does not show preview inside paneldynamic --- src/survey.ts | 1 + tests/flat_file.test.ts | 56 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/survey.ts b/src/survey.ts index 82f63a5..3b3db2b 100644 --- a/src/survey.ts +++ b/src/survey.ts @@ -205,6 +205,7 @@ export class SurveyPDF extends SurveyModel { } } protected async renderSurvey(controller: DocController): Promise { + this.visiblePages.forEach(page => page.onFirstRendering()); await this.waitForCoreIsReady(); const flats: IPdfBrick[][] = await FlatSurvey.generateFlats(this, controller); this.correctBricksPosition(controller, flats); diff --git a/tests/flat_file.test.ts b/tests/flat_file.test.ts index d0efa12..c0a5af5 100644 --- a/tests/flat_file.test.ts +++ b/tests/flat_file.test.ts @@ -13,6 +13,7 @@ import { SurveyHelper } from '../src/helper_survey'; import { TestHelper } from '../src/helper_test'; import { ImageBrick } from '../src/pdf_render/pdf_image'; import { CompositeBrick } from '../src/pdf_render/pdf_composite'; +import { LinkBrick } from '../src/pdf_render/pdf_link'; let __dummy_fl = new FlatFile(null, null, null); test('Check no files', async () => { @@ -461,3 +462,58 @@ test('Test file question getImagePreviewContentWidth always return correct image }); }); }); + +test('Test file question inside paneldynamic waits preview loading', async () => { + const json: any = { + 'logoPosition': 'right', + 'pages': [ + { + 'name': 'page1', + 'elements': [ + { + 'type': 'text', + 'name': 'question1' + } + ] + }, + { + 'name': 'page2', + 'elements': [ + { + 'type': 'paneldynamic', + 'name': 'pd', + 'templateElements': [ + { + 'type': 'file', + 'storeDataAsText': false, + 'name': 'file' + } + ] + } + ] + } + ] + }; + SurveyHelper.inBrowser = false; + const survey: SurveyPDF = new SurveyPDF(json, TestHelper.defaultOptions); + survey.onDownloadFile.add((_, options) => { + setTimeout(() => { + options.callback('success', 'data:image/jpeg;base64,FILECONTENT1'); + }); + }); + let fileBricks: IPdfBrick[]; + survey.onRenderQuestion.add((_, options) => { + fileBricks = options.bricks; + }); + survey.data = { 'pd': [{ 'file': { + 'name': 'name.jpeg', + 'type': 'image/jpeg', + 'content': 'url' + } }] }; + await survey.raw(); + const unFoldedBricks = fileBricks[0].unfold(); + expect(unFoldedBricks.length).toBe(8); + expect(unFoldedBricks[5]).toBeInstanceOf(LinkBrick); + expect((unFoldedBricks[5])['link']).toBe('data:image/jpeg;base64,FILECONTENT1'); + +});