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

File question in composite component doesn't show files in preview mo… #7844

Merged
merged 1 commit into from
Feb 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
5 changes: 2 additions & 3 deletions src/question_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/questionFileTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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" },
Expand Down
52 changes: 52 additions & 0 deletions tests/question_customtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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 = <QuestionCompositeModel>survey.getQuestionByName("q1");
const file_q1 = <QuestionFileModel>compQuestion.contentPanel.getQuestionByName("file_q");
const file_q2 = <QuestionFileModel>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 = <QuestionCompositeModel>survey.getQuestionByName("q1");
const file_q1_preview = <QuestionFileModel>compQuestion_preview.contentPanel.getQuestionByName("file_q");
const file_q2_preview = <QuestionFileModel>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();
});
Loading