-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Fix drag mode not being enabled when long-pressing over Sh…
…ortcode block (#41155) * Add prop for disabling suggestions button * Use allowed formats in format types calculation * Add RichText version to PlainText component * Use experimental version of PlainText in Shortcode block * Add disableAutocorrection prop to RichText * Disable autocorrection in Shortcode block * Update PlainText props in Shortcode block * Use pre as tagName in PlainText * Rename replaceLineBreaks function * Update shortcode block unit tests * Prevent text input focus when selecting Shortcode block * Force text color in Shortcode block * Remove tagName prop from PlainText component
- Loading branch information
Showing
12 changed files
with
217 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/block-library/src/shortcode/test/__snapshots__/edit.native.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Shortcode block edits content 1`] = ` | ||
"<!-- wp:shortcode --> | ||
[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg] | ||
<!-- /wp:shortcode -->" | ||
`; | ||
|
||
exports[`Shortcode block inserts block 1`] = `"<!-- wp:shortcode /-->"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,76 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import renderer from 'react-test-renderer'; | ||
import { TextInput } from 'react-native'; | ||
import { | ||
getEditorHtml, | ||
initializeEditor, | ||
fireEvent, | ||
waitFor, | ||
} from 'test/helpers'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BlockEdit } from '@wordpress/block-editor'; | ||
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks'; | ||
import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks'; | ||
import { registerCoreBlocks } from '@wordpress/block-library'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { metadata, settings, name } from '../index'; | ||
beforeAll( () => { | ||
// Register all core blocks | ||
registerCoreBlocks(); | ||
} ); | ||
|
||
afterAll( () => { | ||
// Clean up registered blocks | ||
getBlockTypes().forEach( ( block ) => { | ||
unregisterBlockType( block.name ); | ||
} ); | ||
} ); | ||
|
||
describe( 'Shortcode block', () => { | ||
it( 'inserts block', async () => { | ||
const { | ||
getByA11yLabel, | ||
getByTestId, | ||
getByText, | ||
} = await initializeEditor(); | ||
|
||
const Shortcode = ( { clientId, ...props } ) => ( | ||
<BlockEdit name={ name } clientId={ clientId || 0 } { ...props } /> | ||
); | ||
fireEvent.press( getByA11yLabel( 'Add block' ) ); | ||
|
||
describe( 'Shortcode', () => { | ||
beforeAll( () => { | ||
registerBlockType( name, { | ||
...metadata, | ||
...settings, | ||
const blockList = getByTestId( 'InserterUI-Blocks' ); | ||
// onScroll event used to force the FlatList to render all items | ||
fireEvent.scroll( blockList, { | ||
nativeEvent: { | ||
contentOffset: { y: 0, x: 0 }, | ||
contentSize: { width: 100, height: 100 }, | ||
layoutMeasurement: { width: 100, height: 100 }, | ||
}, | ||
} ); | ||
} ); | ||
|
||
afterAll( () => { | ||
unregisterBlockType( name ); | ||
} ); | ||
fireEvent.press( await waitFor( () => getByText( 'Shortcode' ) ) ); | ||
|
||
it( 'renders without crashing', () => { | ||
const component = renderer.create( | ||
<Shortcode attributes={ { text: '' } } /> | ||
); | ||
const rendered = component.toJSON(); | ||
expect( rendered ).toBeTruthy(); | ||
expect( getByA11yLabel( /Shortcode Block\. Row 1/ ) ).toBeVisible(); | ||
expect( getEditorHtml() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'renders given text without crashing', () => { | ||
const component = renderer.create( | ||
<Shortcode | ||
attributes={ { | ||
text: | ||
'[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]', | ||
} } | ||
/> | ||
); | ||
const testInstance = component.root; | ||
const textInput = testInstance.findByType( TextInput ); | ||
expect( textInput ).toBeTruthy(); | ||
expect( textInput.props.value ).toBe( | ||
'[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]' | ||
it( 'edits content', async () => { | ||
const { getByA11yLabel, getByPlaceholderText } = await initializeEditor( | ||
{ | ||
initialHtml: '<!-- wp:shortcode /-->', | ||
} | ||
); | ||
const shortcodeBlock = getByA11yLabel( /Shortcode Block\. Row 1/ ); | ||
fireEvent.press( shortcodeBlock ); | ||
|
||
const textField = getByPlaceholderText( 'Add a shortcode…' ); | ||
fireEvent( textField, 'focus' ); | ||
fireEvent( textField, 'onChange', { | ||
nativeEvent: { | ||
eventCount: 1, | ||
target: undefined, | ||
text: '[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]', | ||
}, | ||
} ); | ||
|
||
expect( getEditorHtml() ).toMatchSnapshot(); | ||
} ); | ||
} ); |
Oops, something went wrong.