Skip to content

Commit dbb3fe0

Browse files
author
Gerardo
committed
Mobile - HTML Editor - Fix an issue where the editor would crash if it was focused on a block since it was calling clearSelectedBlock twice.
1 parent 0529628 commit dbb3fe0

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

packages/edit-post/src/test/editor.native.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
/**
22
* External dependencies
33
*/
4-
import { act, render } from 'test/helpers';
4+
import {
5+
act,
6+
addBlock,
7+
fireEvent,
8+
getBlock,
9+
initializeEditor,
10+
render,
11+
setupCoreBlocks,
12+
} from 'test/helpers';
513

614
/**
715
* WordPress dependencies
816
*/
9-
import { registerCoreBlocks } from '@wordpress/block-library';
10-
import RNReactNativeGutenbergBridge from '@wordpress/react-native-bridge';
17+
import RNReactNativeGutenbergBridge, {
18+
subscribeParentToggleHTMLMode,
19+
} from '@wordpress/react-native-bridge';
1120
// Force register 'core/editor' store.
1221
import { store } from '@wordpress/editor'; // eslint-disable-line no-unused-vars
1322

14-
jest.mock( '../components/layout', () => () => 'Layout' );
15-
1623
/**
1724
* Internal dependencies
1825
*/
@@ -34,11 +41,9 @@ afterAll( () => {
3441
jest.useRealTimers();
3542
} );
3643

37-
describe( 'Editor', () => {
38-
beforeAll( () => {
39-
registerCoreBlocks();
40-
} );
44+
setupCoreBlocks();
4145

46+
describe( 'Editor', () => {
4247
it( 'detects unsupported block and sends hasUnsupportedBlocks true to native', () => {
4348
RNReactNativeGutenbergBridge.editorDidMount = jest.fn();
4449

@@ -56,6 +61,26 @@ describe( 'Editor', () => {
5661
RNReactNativeGutenbergBridge.editorDidMount
5762
).toHaveBeenCalledWith( [ 'core/notablock' ] );
5863
} );
64+
65+
it( 'toggles the editor from Visual to HTML mode', async () => {
66+
// Arrange
67+
let toggleMode;
68+
subscribeParentToggleHTMLMode.mockImplementation( ( callback ) => {
69+
toggleMode = callback;
70+
} );
71+
const screen = await initializeEditor();
72+
await addBlock( screen, 'Paragraph' );
73+
74+
// Act
75+
const paragraphBlock = getBlock( screen, 'Paragraph' );
76+
fireEvent.press( paragraphBlock );
77+
78+
toggleMode();
79+
80+
// Assert
81+
const htmlEditor = await screen.findByLabelText( 'html-view-content' );
82+
expect( htmlEditor ).toBeDefined();
83+
} );
5984
} );
6085

6186
// Utilities.

packages/editor/src/components/provider/index.native.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ class NativeEditorProvider extends Component {
319319
const { mode, switchMode } = this.props;
320320
// Refresh html content first.
321321
this.serializeToNativeAction();
322-
// Make sure to blur the selected block and dismiss the keyboard.
323-
this.props.clearSelectedBlock();
324322
switchMode( mode === 'visual' ? 'text' : 'visual' );
325323
}
326324

@@ -387,12 +385,8 @@ const ComposedNativeProvider = compose( [
387385
withDispatch( ( dispatch ) => {
388386
const { editPost, resetEditorBlocks, updateEditorSettings } =
389387
dispatch( editorStore );
390-
const {
391-
updateSettings,
392-
clearSelectedBlock,
393-
insertBlock,
394-
replaceBlock,
395-
} = dispatch( blockEditorStore );
388+
const { updateSettings, insertBlock, replaceBlock } =
389+
dispatch( blockEditorStore );
396390
const { switchEditorMode } = dispatch( editPostStore );
397391
const { addEntities, receiveEntityRecords } = dispatch( coreStore );
398392
const { createSuccessNotice } = dispatch( noticesStore );
@@ -401,7 +395,6 @@ const ComposedNativeProvider = compose( [
401395
updateBlockEditorSettings: updateSettings,
402396
updateEditorSettings,
403397
addEntities,
404-
clearSelectedBlock,
405398
insertBlock,
406399
createSuccessNotice,
407400
editTitle( title ) {

0 commit comments

Comments
 (0)