Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 committed Jul 26, 2024
1 parent bd5b503 commit eb07fc3
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions packages/survey-creator-core/tests/tabs/theme-tab-plugin.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,28 +1073,30 @@ test("Check onOpenFileChooser is called and context is passed", (): any => {
themePlugin.activate();
const propertyGridSurvey = themePlugin.propertyGrid.survey;
const themeModel = themePlugin.themeModel;
const origGetElementById = document.getElementById;
document.getElementById = () => ({} as any);
try {
const backgroundImageEditor = propertyGridSurvey.getQuestionByName("backgroundImage") as QuestionFileModel;
backgroundImageEditor.chooseFile(new MouseEvent("click"));
expect(log).toBe("->onOpenFileChooser->uploadFile");
expect(lastContext).toStrictEqual({ element: themePlugin.themeModel, elementType: "theme", propertyName: "backgroundImage" });
expect(lastUploadContext).toStrictEqual({ element: themePlugin.themeModel, item: undefined, elementType: "theme", propertyName: "backgroundImage" });
expect(lastUploadOptions.elementType).toBe("theme");
expect(lastUploadOptions.propertyName).toBe("backgroundImage");

const groupHeader = themePlugin.propertyGrid.survey.pages[0].getElementByName("header");
const headerBackgroundImageEditor = groupHeader.elements[0].contentPanel.getElementByName("backgroundImage");
headerBackgroundImageEditor.chooseFile(new MouseEvent("click"));
expect(log).toBe("->onOpenFileChooser->uploadFile->onOpenFileChooser->uploadFile");
expect(lastContext).toStrictEqual({ element: themeModel.header, elementType: "header", propertyName: "backgroundImage" });
expect(lastUploadContext).toStrictEqual({ element: themeModel.header, elementType: "header", propertyName: "backgroundImage", item: undefined });
expect(lastUploadOptions.elementType).toBe("header");
expect(lastUploadOptions.propertyName).toBe("backgroundImage");
} finally {
document.getElementById = origGetElementById;
}
const backgroundImageEditor = propertyGridSurvey.getQuestionByName("backgroundImage") as QuestionFileModel;
const testContainer = document.createElement("div");
const testInput = document.createElement("input");
testContainer.appendChild(testInput);
testInput.id = backgroundImageEditor.inputId;
backgroundImageEditor["rootElement"] = testContainer;
backgroundImageEditor.chooseFile(new MouseEvent("click"));
expect(log).toBe("->onOpenFileChooser->uploadFile");
expect(lastContext).toStrictEqual({ element: themePlugin.themeModel, elementType: "theme", propertyName: "backgroundImage" });
expect(lastUploadContext).toStrictEqual({ element: themePlugin.themeModel, item: undefined, elementType: "theme", propertyName: "backgroundImage" });
expect(lastUploadOptions.elementType).toBe("theme");
expect(lastUploadOptions.propertyName).toBe("backgroundImage");

const groupHeader = themePlugin.propertyGrid.survey.pages[0].getElementByName("header");
const headerBackgroundImageEditor = groupHeader.elements[0].contentPanel.getElementByName("backgroundImage");
testInput.id = headerBackgroundImageEditor.inputId;
headerBackgroundImageEditor["rootElement"] = testContainer;
headerBackgroundImageEditor.chooseFile(new MouseEvent("click"));
expect(log).toBe("->onOpenFileChooser->uploadFile->onOpenFileChooser->uploadFile");
expect(lastContext).toStrictEqual({ element: themeModel.header, elementType: "header", propertyName: "backgroundImage" });
expect(lastUploadContext).toStrictEqual({ element: themeModel.header, elementType: "header", propertyName: "backgroundImage", item: undefined });
expect(lastUploadOptions.elementType).toBe("header");
expect(lastUploadOptions.propertyName).toBe("backgroundImage");

});

test("Modify property grid: add/hide properties", (): any => {
Expand Down

0 comments on commit eb07fc3

Please sign in to comment.