Skip to content

Commit

Permalink
#10719: enable upload images within Text widgets (#10735)
Browse files Browse the repository at this point in the history
* #10719: enable upload images within Text widgets
Description:
- add 'prop' called 'enableUploadImg' passing it to 'CompactRichTextEditor' component to enable upload image
- add unit test

* #10719: revert naming enableUploadImg to be uploadEnabled
  • Loading branch information
mahmoudadel54 authored Jan 14, 2025
1 parent ad51ceb commit 779416d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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 [uploadEnabled]', () => {
ReactDOM.render(<CompactRichTextEditor uploadEnabled />, 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
uploadEnabled
editorState={editorState}
onEditorStateChange={(newEditorState) => {
const previousHTML = draftJSEditorStateToHtml(editorState);
Expand Down

0 comments on commit 779416d

Please sign in to comment.