Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file question does not show preview inside paneldynamic #312

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export class SurveyPDF extends SurveyModel {
}
}
protected async renderSurvey(controller: DocController): Promise<void> {
this.visiblePages.forEach(page => page.onFirstRendering());
await this.waitForCoreIsReady();
const flats: IPdfBrick[][] = await FlatSurvey.generateFlats(this, controller);
this.correctBricksPosition(controller, flats);
Expand Down
56 changes: 56 additions & 0 deletions tests/flat_file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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((<LinkBrick>unFoldedBricks[5])['link']).toBe('data:image/jpeg;base64,FILECONTENT1');

});
Loading