-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Gallery block: Fix crash when adding images and selecting …
…a gallery item (#38238) * Add the native variant of MediaReplaceFlow Since the MediaReplaceFlow component is not implemented yet in the native version of the editor, we return an empty component instead. * Set MediaPlaceholder props by platform in gallery * Update react-native-editor changelog * Remove autoOpenMediaUpload from web props `autoOpenMediaUpload` prop is only used in the native version of the `MediaPlaceholder` component hence, we don't need to define it in the props set for the web version. * Add gallery block integration tests * Unify shared props between web and native
- Loading branch information
Showing
7 changed files
with
167 additions
and
5 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
3 changes: 3 additions & 0 deletions
3
packages/block-editor/src/components/media-replace-flow/index.native.js
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,3 @@ | ||
// MediaReplaceFlow component is not yet implemented in the native version, | ||
// so we return an empty component instead. | ||
export default () => null; |
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
7 changes: 7 additions & 0 deletions
7
packages/block-library/src/gallery/test/__snapshots__/index.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,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Gallery block inserts block 1`] = ` | ||
"<!-- wp:gallery {\\"linkTo\\":\\"none\\"} --> | ||
<figure class=\\"wp-block-gallery has-nested-images columns-default is-cropped\\"></figure> | ||
<!-- /wp:gallery -->" | ||
`; |
128 changes: 128 additions & 0 deletions
128
packages/block-library/src/gallery/test/index.native.js
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,128 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
getEditorHtml, | ||
initializeEditor, | ||
fireEvent, | ||
waitFor, | ||
within, | ||
} from 'test/helpers'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks'; | ||
import { registerCoreBlocks } from '@wordpress/block-library'; | ||
|
||
beforeAll( () => { | ||
// Register all core blocks | ||
registerCoreBlocks(); | ||
} ); | ||
|
||
afterAll( () => { | ||
// Clean up registered blocks | ||
getBlockTypes().forEach( ( block ) => { | ||
unregisterBlockType( block.name ); | ||
} ); | ||
} ); | ||
|
||
const GALLERY_WITH_ONE_IMAGE = `<!-- wp:gallery {"linkTo":"none"} --> | ||
<figure class="wp-block-gallery has-nested-images columns-default is-cropped"><!-- wp:image {"id":1} --> | ||
<figure class="wp-block-image"><img src="https://cldup.com/cXyG__fTLN.jpg" alt="" class="wp-image-1"/></figure> | ||
<!-- /wp:image --></figure> | ||
<!-- /wp:gallery -->`; | ||
|
||
const addGalleryBlock = async () => { | ||
const screen = initializeEditor(); | ||
const { getByA11yLabel, getByTestId, getByText } = screen; | ||
|
||
fireEvent.press( getByA11yLabel( 'Add block' ) ); | ||
|
||
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 }, | ||
}, | ||
} ); | ||
|
||
fireEvent.press( await waitFor( () => getByText( 'Gallery' ) ) ); | ||
|
||
return screen; | ||
}; | ||
|
||
describe( 'Gallery block', () => { | ||
it( 'inserts block', async () => { | ||
const { getByA11yLabel } = await addGalleryBlock(); | ||
|
||
const galleryBlock = await waitFor( () => | ||
getByA11yLabel( /Gallery Block\. Row 1/ ) | ||
); | ||
|
||
expect( galleryBlock ).toHaveProperty( 'type', 'View' ); | ||
expect( getEditorHtml() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'selects a gallery item', async () => { | ||
const { getByA11yLabel } = initializeEditor( { | ||
initialHtml: GALLERY_WITH_ONE_IMAGE, | ||
} ); | ||
|
||
const galleryBlock = await waitFor( () => | ||
getByA11yLabel( /Gallery Block\. Row 1/ ) | ||
); | ||
fireEvent.press( galleryBlock ); | ||
|
||
const innerBlockListWrapper = await waitFor( () => | ||
within( galleryBlock ).getByTestId( 'block-list-wrapper' ) | ||
); | ||
fireEvent( innerBlockListWrapper, 'layout', { | ||
nativeEvent: { | ||
layout: { | ||
width: 100, | ||
}, | ||
}, | ||
} ); | ||
|
||
const galleryItem = await waitFor( () => | ||
getByA11yLabel( /Image Block\. Row 1/ ) | ||
); | ||
fireEvent.press( galleryItem ); | ||
|
||
expect( galleryItem ).toHaveProperty( 'type', 'View' ); | ||
} ); | ||
|
||
it( 'shows appender button when gallery has images', async () => { | ||
const { getByA11yLabel, getByText } = initializeEditor( { | ||
initialHtml: GALLERY_WITH_ONE_IMAGE, | ||
} ); | ||
|
||
const galleryBlock = await waitFor( () => | ||
getByA11yLabel( /Gallery Block\. Row 1/ ) | ||
); | ||
fireEvent.press( galleryBlock ); | ||
|
||
const innerBlockListWrapper = await waitFor( () => | ||
within( galleryBlock ).getByTestId( 'block-list-wrapper' ) | ||
); | ||
fireEvent( innerBlockListWrapper, 'layout', { | ||
nativeEvent: { | ||
layout: { | ||
width: 100, | ||
}, | ||
}, | ||
} ); | ||
|
||
const appenderButton = await waitFor( () => | ||
within( galleryBlock ).getByA11yLabel( /Gallery block\. Empty/ ) | ||
); | ||
fireEvent.press( appenderButton ); | ||
|
||
expect( getByText( 'Choose from device' ) ).toBeDefined(); | ||
expect( getByText( 'Take a Photo' ) ).toBeDefined(); | ||
expect( getByText( 'WordPress Media Library' ) ).toBeDefined(); | ||
} ); | ||
} ); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,4 +153,7 @@ module.exports = { | |
'components-autocomplete': { | ||
height: 100, | ||
}, | ||
addMediaButton: { | ||
color: 'white', | ||
}, | ||
}; |