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

#10719: enable upload images within Text widgets #10735

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function CompactRichTextEditor({
image: {
urlEnabled: true,
// upload controlled via props, disabled by default
uploadEnabled: props.uploadEnabled || false,
uploadEnabled: props.enableUploadImg || false,
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
alignmentEnabled: false,
uploadCallback: (file) => new Promise((resolve, reject) => {
const reader = new FileReader();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2025, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import ReactDOM from 'react-dom';
import CompactRichTextEditor from '../CompactRichTextEditor';
import expect from 'expect';
import TestUtils from 'react-dom/test-utils';

describe('CompactRichTextEditor component', () => {
beforeEach((done) => {
document.body.innerHTML = '<div id="container"></div>';
setTimeout(done);
});

afterEach((done) => {
ReactDOM.unmountComponentAtNode(document.getElementById("container"));
document.body.innerHTML = '';
setTimeout(done);
});

it('should render with default which does not include image upload', () => {
ReactDOM.render(<CompactRichTextEditor />, document.getElementById("container"));
const textEditorContainer = document.querySelector(".ms-compact-text-editor.rdw-editor-wrapper");
expect(textEditorContainer).toBeTruthy();
// check img upload btn
const imageWidget = document.querySelector(".rdw-image-wrapper .rdw-option-wrapper");
TestUtils.act(() => {
TestUtils.Simulate.click(imageWidget);
});
const uploadImgInput = document.querySelector(".rdw-image-modal-upload-option");
expect(uploadImgInput).toBeFalsy();
});
it('test rendering TextEditor with enabling image upload [enableUploadImg]', () => {
ReactDOM.render(<CompactRichTextEditor enableUploadImg />, document.getElementById("container"));
const textEditorContainer = document.querySelector(".ms-compact-text-editor.rdw-editor-wrapper");
expect(textEditorContainer).toBeTruthy();
const imageWidget = document.querySelector(".rdw-image-wrapper .rdw-option-wrapper");
TestUtils.act(() => {
TestUtils.Simulate.click(imageWidget);
});
const uploadImgInput = document.querySelector(".rdw-image-modal-upload-option");
expect(uploadImgInput).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function TextOptions({ data = {}, onChange = () => {} }) {
</Form>
</Col>
<DescriptorEditor
enableUploadImg
editorState={editorState}
onEditorStateChange={(newEditorState) => {
const previousHTML = draftJSEditorStateToHtml(editorState);
Expand Down
Loading